请问,在exe中采用隐式链接的方法调用dll中的导出函数时,必须得在exe中加__declspec(dllimport) void fun()声明该函数为导入函数,然后再使用该函数吗?怎么我测试的时候发现,不声明,直接使用也是可以的。

解决方案 »

  1.   

    一般来说需要导入函数的时候要加__declspec(dllimport),若不加,则需要在.def文件中添加相应的项也可以。还有就是添加__declspec(dllimport)可以优化部分代码,以下是msdn的原文:You do not need to use _declspec(dllimport) for your code to compile correctly, but doing so allows the compiler to generate better code. The compiler is able to generate better code because it knows for sure whether a function exists in a DLL or not, so the compiler can produce codes that skip a level of indirection that would normally be present in a function call that crossed a DLL boundary. 
      

  2.   

    你肯定包括了DLL的头文件,里面有
    #ifdef DLL_OBJECT_EXPORTS#define DLL_OBJECT_API __declspec(dllexport)#else#define DLL_OBJECT_API __declspec(dllimport)#endif
      

  3.   

    隐式链接需要dll的头文件和lib库,头文件里声明了哪些函数是导出的
      

  4.   

    加__declspec(dllimport)主要是为了防止编译时修改函数名,与其他语言兼容。
    windows核心编程》这么说的
      

  5.   

    加__declspec(dllimport)主要是为了防止编译时修改函数名,与其他语言兼容。
    windows核心编程》这么说的
    不加也没有错.
      

  6.   

    这个问题前段时间刚讨论过的,结果自己去看:
    http://topic.csdn.net/u/20100322/00/17389242-a3f7-46d1-992b-ae4c4e2976bb.html?6299