简体   繁体   中英

Linking a MFC dll in a non MFC application

I need to call a MFC DLL method in a non-MFC application (Uses Standard Windows Libraries). I am getting a

"include 'stdafx.h' before including this file for PCH"

error. I have included the stdafx.h in all of my headers and cpp files. No luck. What is the procedure to call a MFC DLLin a non-MFC application?

This error ha nothing to do, with a DLL problem. Or with the way to share code in a DLL with another project.

You setup a project that uses precompiled headers. Precompiled headers are setup for each project seperatly. You should never share such a file between projects.

Setup your project that it compiles without the external DLL reference. If it compiles add the header file of the external DLL interface (and nothing more), add the LIB file to the linker options (or use #pragma comment(lib,..)).

Again: Your main problem ist that you didn't understand precompiled headers, for a fast try you can turn it of at all. But I suppose that you way to share the project file is a "little bit chaotic".

Method 1:

You can check the project properties in the non-mfc application not to use the precompiled header.

ie Project Properties->Configuration Properties->C/C++->Precompiled Header and make the Precompled Header Property to 'Not Using precompiled Header' If you are in visual studio. The is equivalent to removing the '/Yu' flag while compiling.

Method 2: Ensure that you use precompiled header in the non-mfc app too.

ie create a precompiled header (can be of any name, here stdafx.h) and configure the above said property as needed. The property of the .h should be /Yc.

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