使用.def文件 是不是就不用 __declspec(dllexport)
使用.def文件 是不是就不用 extern "C" 
不使用.def文件,直接用__declspec(dllexport),且不加extern "C" 导出函数 A,那么名字很乱。如果用显式链接::GetProcAddress的时候,就要写那个变乱的名字,那么如果用隐式链接是不是就不用写那个乱的名字,直接写A就可以了呢?怎么使用.def文件导出类?用__declspec(dllexport)导出的类,名字会乱。如果使用隐式链接,那么没关系,直接写原来类名就OK了。那么怎么使用显示链接呢?尤其是后三个问题,特别是后两个问题.
                                      先谢谢大家了

解决方案 »

  1.   

    使用.def文件 是不是就不用 __declspec(dllexport) 
    使用.def文件 是不是就不用 extern "C" 
    ============================================
    不用
    不使用.def文件,直接用__declspec(dllexport),且不加extern "C" 导出函数 A,那么名字很乱。如果用显式链 
    ============================================
    dllexport of a C++ function will expose the function with C++ name mangling. If C++ name mangling is not desired, either use a .def file (EXPORTS keyword) or declare the function as extern "C".
      

  2.   

    __declspec(dllexport)是声明导出函数,其导出函数的名称是编译自动生成的,在原名称基础上增加了一些字母用于表示函数的调用约定、返回值、各个参数类型,连接器可以通过函数名对函数类型做严格检查,在使用lib时应才用这种方式;
    当需要动态加载时(包括被其它编程语言调用),可以使用def文件来定义导出函数名称,此时__declspec(dllexport)可有可无;
    extern "C"是采用C语言方式来生成函数名(在原名称前面加一个下划线),可以与__declspec(dllexport)组合而使导出函数名简化,建议不要使用这种方式。
      

  3.   

    导出类的时候必须使用__declspec(dllexport),不能用def文件。只能隐式加载,不能显示加载。只能被VC程序使用,不能被别的语言使用。
      

  4.   

    使用def文件,头文件不用__declspec(dllexport),直接声明函数就可以了.
    例如求最大值:
    typedef int (*pMax)(int, int);
    pMax Max;
    Max = (pMax)(GetProcAddress(hInst,"Max"));
      

  5.   

    使用def文件
    .def中
    LIBRARY "MyDll"
    EXPORTS
    Max
    .h中
    int Max(int iFisrtNum, int iSecondNum);
    .cpp
    Max(iFrstNumber, iSecondNum);
      

  6.   

    dll头文件中
    extern "C" _declspec(dllexport) int Max(int iFirstNum, int iSecondNum);
    APP头文件中
     extern "C"_declspec(dllimport) int Max(int iFirstNum,int iSecondNum);
    .cpp
    HINSTANCE hInst = NULL;
    typedef int (*pMax)(int, int);
    pMax Max;
    hInst = LoadLibrary(_T("../debug/MyDll.dll"));
    Max = (pMax)(GetProcAddress(hInst,"Max"));