那位高手能帮忙解决一下  如何在DLL中封装一个类  然后在MFC中将类导出 

解决方案 »

  1.   

    Microsoft introduced __export in the 16-bit compiler version of Visual C++ to allow the compiler to generate the export names automatically and place them in a .lib file. This .lib file can then be used just like a static .lib to link with a DLL.In the 32-bit compiler version, you can export data, functions, classes, or class member functions from a DLL using the __declspec(dllexport) keyword. __declspec(dllexport) adds the export directive to the object file so you do not need to use a .def file.This convenience is most apparent when trying to export decorated C++ function names. Because there is no standard specification for name decoration, the name of an exported function might change between compiler versions. If you use __declspec(dllexport), recompiling the DLL and dependent .exe files is necessary only to account for any naming convention changes.Many export directives, such as ordinals, NONAME, and PRIVATE, can be made only in a .def file, and there is no way to specify these attributes without a .def file. However, using __declspec(dllexport) in addition to using a .def file does not cause build errors.To export functions, the __declspec(dllexport) keyword must appear to the left of the calling-convention keyword, if a keyword is specified. For example:  Copy Code 
    __declspec(dllexport) void __cdecl Function1(void);
     To export all of the public data members and member functions in a class, the keyword must appear to the left of the class name as follows:  Copy Code 
    class __declspec(dllexport) CExampleExport : public CObject
    { ... class definition ... };
     When building your DLL, you typically create a header file that contains the function prototypes and/or classes you are exporting and add __declspec(dllexport) to the declarations in the header file. To make your code more readable, define a macro for __declspec(dllexport) and use the macro with each symbol you are exporting:  Copy Code 
    #define DllExport   __declspec( dllexport ) 
     __declspec(dllexport) stores function names in the DLL's export table. If you want to optimize the table's size, see Exporting Functions from a DLL by Ordinal Rather Than by Name.Note  
    When porting DLL source code from Win16 to Win32, replace each instance of __export with __declspec(dllexport).
     As a reference, search through the Win32 Winbase.h header file. It contains examples of __declspec(dllimport) usage.
      

  2.   

    创建DLL工程时,选MFC Extension DLL,可以把整个类封装
      

  3.   

    建Extension Dll 然后把你的类声明的地方写成class AFX_EXT_CLASS yourclass
    这个类就可以导出了