I’m just experimenting with mixing a native C++ (that uses MFC) static lib and a C++/CLI WinForms application. When I try to include my NativeClass.h, compiling the C++/CLI app fails because it doesn’t understand AFX_EXT_CLASS used to export the class for the lib.
Just to get it working, I was able to build the native lib, then remove the AFX_EXT_CLASS from the header, then build the C++/CLI linked to the native lib. The C++/CLI app will run, the dialog comes up and outputs some dummy value from my NativeClass::NativeFunction() method. Everything seems to work great, except I can’t build the C++/CLI app without removing AFX_EXT_CLASS. Any ideas how to make this work without having to edit the header? I would prefer a single step build.
// NativeClass.h
class AFX_EXT_CLASS NativeClass {
public:
NativeClass();
~NativeClass();
int NativeFunction();
};
This is the error I get when building the C++/CLI app while AFX_EXT_CLASS is in the header:
NativeClass.h(3): error C2470: 'NativeClass' : looks like a function definition, but there is no parameter list; skipping apparent body
I got it compiled and running by adding
#define AFX_EXT_CLASSto my C++/CLI app’s stdafx.h. I figured since the C++/CLI app isn’t really concerned with the macro, there’s no need for it to worry, so defining it makes the compiler happy and doesn’t seem to cause any ill effects.