0
votes

I have an MFC .exe application, and I created another project for a DLL with MFC dynamically linked to it.

Now, when I import that DLL through LoadLibrary, it crashes my application, because when the importing is done, the DLL calls AfxWinInit().

Should the DLL call AfxWinInit()? How do I avoid it? Or is something else wrong?

1
If it is already a MFC application, you don't need to call in in that DLLMatt
@Matt I did not create any code calling it myself, It is called inside internal MFC/windows API codemanatttta

1 Answers

3
votes

In your MFC application WinMain() calls AfxWinMain(). The AfxWinInit() is called at the beginning of AfxWinMain(). So the initialization is done by framework for you. There is no need to initialize it again.

MFC DLLs provide their own entry point, so you're not supposed to write one yourself. If you plan to write a DLL with MFC support, I'd suggest you start with a fresh MFC DLL created by the app wizard and then move your code there.

For MFC applications that load extension DLLs, use AfxLoadLibrary instead of LoadLibrary.