error LNK2001: unresolved external symbol "public: void __thiscall - visual-studio-2010

I'm using MFC for writing a windows program. I have used these settings when creating the project.
File -> New Project -> MFC applicatioin
and in the MFC application wizard I have choosed:
Application type: Dialog based
Resource language: English (United States)
Use Unicode libraries
Project style: MFC standard
Use of MFC: Use MFC in a static library
Main frame styles: Thick frame, System menu and About box are ticked
Advanced features: ActiveX controls, Common Control Manifest and Support Restart Manager are ticked
Dialog title: P2
Generated classes: Cp2App and Cp2Dlg
I haven't add any codes to the project yet. And I have just been adding the controls in the form:
but when I try to run the project, I get the errors:
1-error LNK2001: unresolved external symbol "public: void __thiscall CP2Dlg::OnBnClickedButton2(void)" (?OnBnClickedButton2#CP2Dlg##QAEXXZ)
2-error LNK1120: 1 unresolved externals
I know that I can start a new project to avoid the error. But I want to know what causes this problem and solve it?
Note: the first error occurs in the P2Dlg.obj and the second occurs in the P2.exe file.
Edited section: In fact I think this error is because I carelessly double-clicked Button2 and created the eventhandler BnClickedButton2 and deleted it. Now I try to create this eventhandler again but I can't, Because when I right-click button2 and choose add eventhandler in the event handler wizard the option BN_CLICKED is inactive.
I want to know how to generally fix this kind of problems.Please help me?
Edited section 2: I have added this function in the P2.cpp file using Add EventHandler but this did not solve the problem:
void CP2App::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
}
the function CP2Dlg::OnBnClickedButton2 should be added but I can't add it. It is inactive?????

There is a line in the dialog's message map that attempts to call the function you deleted. In the future if you delete a message handler function also delete the corresponding entry in the message map.
The message handler must be in the dialog class. (That's where the message is sent.) Clean out the message map and function and rebuild all. Then you can probably get the Add Event wizard working again.

Related

Send email with RAD Studio cpp11

I am trying to port an old Borland C++ application to the new RAD studio 11 format an I cannot get it to send emails using Outlook_2K_SRVR.h.
Would anyone have sample code to send emails with RAD studio 11? in C++?
This is the part of the code that does not work.
`
`#define Outlook_2k_olMailItem OlItemType::olMailItem`
`//---------------------------------------------------------------------------
#pragma package(smart_init)
//----------------------------------
// emailing ...
//----------------------------------
#pragma link "Outlook_2K_SRVR"
void __fastcall TLicMainForm::Button1Click(TObject *Sender)
{
MailItem = (MailItemPtr)(Outlook->CreateItem(Outlook_2k_olMailItem));
MailItem->set_To((MailAddressee.w_str() ));
MailItem->set_Subject((MailSubject.w_str()));
MailItem->set_Body((MailFullText.w_str()) );
MailItem->Attachments->Add( (TVariant)(FDispatch_path), TNoParam(), TNoParam(), TNoParam() );
MailItem->Send();
}`
`
this is the one of the many errors
[ilink32 Error] Error: Unresolved external '__fastcall Outlook_2k::TSyncObject::Disconnect()' referenced from C:\mypath\OUTLOOK_2K_SRVR.OBJ
[ilink32 Error] Error: Unable to perform link
Thanks in advance
I tried to re-compile "Outlook_2k_SRVR.obj" with the .h file that comes in the vcl folder but no luck.
It seems Outlook is disconnected right after the Send method is called. Most probably the new RAD studio release COM references quickly enough. You may try to get any Outlook window and keep it alive while Outlook is automated and the message is sent out. Try to use the Explorers.Add or Inspectors.Add methods to create an Outlook window, be aware that without calling the Display method the window will be kept not visible to the end user.

C++ Windows Forms application icon exception

I want to set an icon for my Windows Form application. My actions step by step:
I created an 'icon.ico' (256x256) and put it into my project folder
In my 'Form1.h [Design]' I chose this file using Properties
This code appeared in 'Form1.h'
void InitializeComponent(void)
{ ...
this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
... }
The object '$this.Icon' appeared in 'Form1.resx'
I rebuilt the whole project -> no errors
During execution the line 'this->Icon = ...' causes an exception: System.Resources.MissingManifestResourceException: 'Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "WinForm.Form1.resources" was correctly embedded or linked into assembly "MyProject" at compile time, or that all the satellite assemblies required are loadable and fully signed.'
Here I found numerous advices, such as remove/add icon or set some custom properties for 'Form1.resx', but none of them works for me
Just like above, change line to:
this->Icon = gcnew System::Drawing::Icon(L"ICON_NAME.ico");
You might get error/exception while opening form creator but you shouldn't lose any data.
Been there, done that :)
Place the Icon you want to connect to your Form in the project directory.
Then replace the line above with the following:
this->Icon = gcnew System::Drawing::Icon(L"app.ico");
This should neutralize the bug that Microsoft has not fixed.
If you are using visual studio 2019 , you need to change the name of namespace in Form1 the same as your project name, i did it and it works
and make sure you change it in main :
[STAThread]
int main() {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew your_namespace_name::Form1());
return 0;
}

::RegisterWIndowMessage() In Direct 2D application Compile Error

I'm working on a Direct2D (XAML) application (I picked this because I haven't done it before and I wanted to try it out, I thought it would be simple).
I created the project in Visual Studio 2012 using the default options.
I added a button to the GUI successfully.
I added a button press handler to the GUI successfully.
The problem is that I need the button press handler to send a registered windows message. I #include <Windows.h> as instructed by the MSDN docs for ::RegisterWindowMessage(), and finding the declaration and definition of the function with the F12 key works fine.
However, building the project fails, because the compiler can't find the function. Intellisense also flags the function as unrecognized.
I'm probably missing something in the project configuration, but I don't even know where to begin.
Can you please help me?
Edit: The exact error messages that I'm getting are:
error C2039: 'RegisterWindowMessage' : is not a member of '`global namespace''
error C3861: 'RegisterWindowMessage': identifier not found
RegisterWindowMessage is not available in a UWP application (which is likely what you are targeting in a XAML application). If you look into WinUser.h, you'll find the declarations are wrapped inside a
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
guard. This API is available to desktop applications only. There is nothing you can do to make it work in a UWP application.

Getting started with Watin

I am trying to do the quick start example, I bring in the ref's using NuGet in VS2010, I scrape the sample code on the webpage, I see my NUnit Session window, I click the green arrow, but the browser doesn't get invoked (doesn't start). What am I missing?
using System;
using NUnit.Framework;
using WatiN.Core;
namespace FirstWatinProject
{
[TestFixture]
public class Class1
{
[Test]
[STAThread]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.Button(Find.ByName("btnK")).Click();
Assert.IsTrue(browser.ContainsText("WatiN"));
}
}
}
}
I am getting the following error in NUnit Sessions window;
SearchForWaitOnGoogle Failed: System.IO.FileNotFoundException: Could
not load file or assembly 'Interop.SHDocVw, Version=1.1.0.0,
Culture=neutral etc...
Okay, solved the error, it is as the following other overflow thread concludes;
WatiN System.IO.FileNotFoundException Interop.SHDocVw
BUT, a key action in the sequence is to build the class library project AFTER setting the Interop.SHDocVw dlls' 'Embed Interop Types' property to 'False';
Then you can hit the green arrow in NUNIT Sessions window and you will see the IE browser startup after a second or two. Simply click it and you will see whatever actions you have programmed.
God is in the details!
Setting the Interop.SHDocVw, Microsoft.mshtml dlls' 'Embed Interop Types' property to 'False';
Of course Visual Studio would give you warnings on how to amend.
The Use of Nugget Package Manager
Check for the availability of Interop.SHDocVw.dll,
Make sure that your project has a reference to Interop.SHDocVw.dll and the dll is present in the Bin/Release Folder depending upon how you are running..
Just select Build from the main menu...then select Configuration Manager. In the list select you project and change its Plateform 'Any CPU' etc to x86.
If you have only Only CPU option, you can use ... option when chosing platform and create new setting, that is for X86 platform and then choose it.
ref:
Change target to x86 in VS2010
I already had a reference to Interop.SHDocVw. The easiest fix for me was simply changing .NET from 4.5 to 3.5 in Visual Studio settings. After making the change, it worked fine.

How does visual studio associate mfc dialog classes with dialog resources?

I was wondering how Visual Studio associates MFC CDialog derived classes with their corresponding dialog resources. I'm not interested in how the connection is made at run time (as asked here), but rather at design time.
When I add a message handler to a dialog, how does it know which class to add the handler to.
Also, is it possible to have several CDialog derived classes associated with the same dialog resource and vice versa?
I have searched the project directory for the IDD_SOMEDIALOG string but have only found it in SomeDialog.h, resource.h and Project.rc in the expected places so I guess it somehow deduces the connection from those files, most likely the enum in SomeDialog.h:
// in class CSomeDialog:
enum { IDD = IDD_SOMEDIALOG };
I'm asking this mostly out of curiosity.
It depends on what version of dev studio.
In VS6 it was all kept in the CLW (Class Wizard File).
In newer versions of dev studio it doesn't use the CLW anymore and I don't know specifically how it knows, but i suspect its a live parsing instead of using a cached CLW.
As for having multiple derived dialogs using the same resource, it can be done manually. You can duplicate the created class files and rename them and remove the enum from header and edit the use of the IDD enum in the source file to be the actual dialog resource id (IDD_SOMEDIALOG).
AFAIK Dev Studio will only 'happily' handle one class to a dialog at a time. In my experience trying to re-use a dialog resource like this just ends up in a bit of battle with MFC & Dev Studio since they were not intended to do this.
To add to Ruddy's answer:
I noticed that some of my dialog classes in which I replaced the enum { IDD } with static const int IDD was not any longer associated with its dialog resource. Reverting to the enum re-associated them. So it seems that visual studio parses the source code to determine the relationships.
As for resource sharing, it would be ambiguous as to which class should receive the event handler code. Class sharing seems to be be impossible since it relies on the IDD which can not be assigned to a IDD_SOMETHING and IDD_SOMETHING_ELSE simultaneously.

Resources