简体   繁体   中英

MFC DLL calls AfxWinInit and crashes application

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM