using a MFC DLL in C++ .Net
-
Hi, I have to use a MFC C++ DLL (unmanaged of course) in a C++ .Net project. I have problems to do that. I've created a C++ .Net project and includes the MFC DLL. My problems comes as soon as I call a method (ctor, dtor or method) from the MFC DLL. I've got this kind of error :
error LNK2001: unresolved external symbol "public: __thiscall toto::toto(void)" (??0toto@@$$FQAE@XZ) fatal error LNK1120: 2 unresolved externals
toto is the unmanaged class from the MFC DLL. I call it in the C++ .Net class like this :toto *p; p = new toto();
(the first line compile but not the second) Thanks, Denis (denissohet AT hotmail DOT com -
Hi, I have to use a MFC C++ DLL (unmanaged of course) in a C++ .Net project. I have problems to do that. I've created a C++ .Net project and includes the MFC DLL. My problems comes as soon as I call a method (ctor, dtor or method) from the MFC DLL. I've got this kind of error :
error LNK2001: unresolved external symbol "public: __thiscall toto::toto(void)" (??0toto@@$$FQAE@XZ) fatal error LNK1120: 2 unresolved externals
toto is the unmanaged class from the MFC DLL. I call it in the C++ .Net class like this :toto *p; p = new toto();
(the first line compile but not the second) Thanks, Denis (denissohet AT hotmail DOT comThat unresolved external symbol is pretty common; and generally, it means that you somehow failed to reference whatever it was (DLL), or failed to link to the LIB file. In this case, since you are importing an unmanaged function into a managed .NET project, you must use the System::Runtime::InteropServices namespace and the DLLImport attribute preceeding the function declaration. This explains and shows the correct syntax: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp[^]
-
That unresolved external symbol is pretty common; and generally, it means that you somehow failed to reference whatever it was (DLL), or failed to link to the LIB file. In this case, since you are importing an unmanaged function into a managed .NET project, you must use the System::Runtime::InteropServices namespace and the DLLImport attribute preceeding the function declaration. This explains and shows the correct syntax: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp[^]
DllImport must be use to import an unmanaged function but I have to import into my C++ .Net code, classes from unmanaged code... And I don't know how to do. I want to do a wrapper but I can't call my unmanaged classes un .Net code. That's my problem in fact. I've try the DllImport, but I can't call a constructor :s Is it possible to do this ? Thks
-
DllImport must be use to import an unmanaged function but I have to import into my C++ .Net code, classes from unmanaged code... And I don't know how to do. I want to do a wrapper but I can't call my unmanaged classes un .Net code. That's my problem in fact. I've try the DllImport, but I can't call a constructor :s Is it possible to do this ? Thks
Sorry for not replying. I'm not a big fan of MFC, but, I've read that using MFC classes in a .NET CLR project can be problematic. As I recall there is a conflict with a compiler switch that enables runtime type checks in MFC, and this conflicts with the operation of the Common Language Runtime. Sorry for my previous post, it could just be making things more difficult for you. There is an article on MSDN Magazine about this problem. I suggest that you search there.