DLL Export

I'm modifying an existing solution that has a DLL and an app. I added a new function in the DLL in the cpp file. I added the function prototype in the class definition section in the header file. The class has the AFX_EXT_CLASS modifier so the entire class should be exported. However, I get an error when linking the app, because it doesn't know about my new function in the DLL.

unresolved external symbol "__declspec(dllimport)public:bool __thiscall <classname>::<function name>

I verified that the DLL *.def file doesn't list any of the existing functions as being exported. This makes sense to me, because the class has AFX_EXT_CLASS - so I think they don't need to be listed in the *.def file.

I did a global search for an existing DLL function (which links successfully) and the only place it is found is in the DLL cpp file, DLL header file, and where the function is called in the app.

How do I tell the linker where the DLL function is



Answer this question

DLL Export

  • cepe

    From http://msdn.microsoft.com/library/default.asp url=/library/en-us/vccore98/HTML/_core_export_and_import_using_afx_ext_class.asp:

    AFX_EXT_CLASS: "This macro is defined by MFC as __declspec(dllexport) when the preprocessor symbols _AFXDLL and _AFXEXT are defined. But the macro is defined as __declspec(dllimport) when _AFXDLL is defined and _AFXEXT is not defined. When defined, the preprocessor symbol _AFXDLL indicates that the shared version of MFC is being used by the target executable (either a DLL or an application). When both _AFXDLL and _AFXEXT are defined, this indicates that the target executable is an extension DLL. "

     

    So you need to make sure you compile your dll with _AFXEXT.  For more on MFC extension DLLs: http://msdn.microsoft.com/library/default.asp url=/library/en-us/vccore98/HTML/_core_extension_dlls.3a_.overview.asp

     

    Louis Lafreniere

    VC++ Compiler back-end dev



  • Fraadl

    The import lib that gets created when you link the dll should define you're symbol foo (as well as __imp_foo).  Use "link -dump -exports mydll.lib" to see what's exported.

    You should be linking in this lib when building your app.

     Louis Lafreniere

    VC++ Compiler dev

     



  • ckebabo

    ok... for some reason, my new functions are not being exported.

    The function prototype is in the public section of the class definition in the header file.  Since the class is AFX_EXT_CLASS, shouldn't it automatically be exported


  • DLL Export