Using MFC classes in non-mfc .net application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am including a class into my mixed managed/unmanaged C++ application that
uses MFC classes such as CSTRING.

#include <afx.h> // have to include this in order to compile
#include "CSharedMemory.h"

In order to get my project to build, I have to change the project settings
to use MFC in a shared dll. However, if I do this, I get the following
exception both if I include the files above or if I leave them out:

An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

If I change the project setting back to "Use standard window libraries",
everything works fine if the two files are not included, but if they are
there, I get the following link errors:

Linking...
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void
*)" (??3@YAXPAX@Z) already defined in msvcrtd.lib(MSVCR71D.dll)
nafxcwd.lib(afxmem.obj) : warning LNK4006: "void __cdecl operator
delete(void *)" (??3@YAXPAX@Z) already defined in msvcrtd.lib(MSVCR71D.dll);
second definition ignored

These go away if I use MFC in a shared dll, but as I said, then I get the
resource exception.

Any clues as to what I should do? I've searched and searched and can't find
anything.

Thanks!
 
Hi Chris,
Can you try calling AfxWinInit(..) in your main function?Please find the
code snippet from MSDN below?

if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << "MFC failed to initialize!" << endl;
return 1;
}


Also ensure that you create an instance of CWinapp class.
 
Back
Top