隐式连接dll
  加.h和.lib 直接调用函数就行了显式连接dll  HINSTANCE dd;
  char * temp;
  temp=NULL;
  char * (__stdcall *ddd)();
    dd = AfxLoadLibrary("procshow.dll");
  if (dd)
  {
     ddd = (char * (__stdcall *)(        ))GetProcAddress(dd , "test");//test是DLL中你要调用的函数
     if (ddd)  
 { 
 temp=ddd();
  }
  }
  AfxFreeLibrary(dd);

解决方案 »

  1.   

    我用regular dll shared mfc 启动程序的
    然后在a.cpp 中加入
    extern "C" __declspec(dllexport) double Ex21cSquareRoot(double d)
    { AFX_MANAGE_STATE(AfxGetStaticModuleState());
    TRACE("Entering Ex21cSquareRoot\n");
    if (d >= 0.0) {
    return sqrt(d);
    }
    AfxMessageBox("Can't take square root of a negative number.");
    return 0.0;
    }
    编译产生lib dll在客户中set\link设置lib路径
    在某个头文件中extern "C" __declspec(dllimport) double Ex21cSquareRoot(doubled);
    我是这么做的不知道对不对
    你说 的h文件是那个?
      

  2.   

    这样是可以的,我只是把
    extern "C" __declspec(dllexport) double Ex21cSquareRoot(double d)
    写在了 a.h中
      

  3.   

    -------Link----------Link an Executable to a DLL
    An executable file links to (or loads) a DLL in one of two ways: 
    · Implicit linking 隐式连接
    · Explicit linking  显式连接
    Note   Implicit linking is sometimes referred to as static load or load-time dynamic linking. Explicit linking is sometimes referred to as dynamic load or run-time dynamic linking.
    隐式连接有时指静态载入或载入时动态连接。显式连接有时指动态载入或运行时动态连接。
    With implicit linking, the executable using the DLL links to an import library (.LIB file) provided by the maker of the DLL. The operating system loads the DLL when the executable using it is loaded. The client executable calls the DLL’s exported functions just as if the functions were contained within the executable. 
    使用隐式连接时,可执行部分将DLL连接到一个输入库(LIB文件)。当可执行部分载入时,系统载入DLL。客户端就可以调用存在于可执行部分的DLL输出函数。
    With explicit linking, the executable using the DLL must make function calls to explicitly load and unload the DLL, and to access the DLL’s exported functions. The client executable must call the exported functions through a function pointer.
    使用显示连接时,可执行部分必须显示的载入或卸载DLL,来访问DLL输出函数。客户端可执行部分通过函数指针访问输出函数。
    An executable can use the same DLL with either linking method. Furthermore, these mechanisms are not mutually exclusive, as one executable can implicitly link to a DLL and another can attach to it explicitly.
    一个可执行部分可同时使用两种方法访问同一个DLL。Link Implicitly
    To implicitly link to a DLL, executables must obtain the following from the provider of the DLL: 
    · A header file (.H file) containing the declarations of the exported functions and/or C++ classes.
    包含输出函数和/或C++类声明的头文件(.H文件)
    · An import library (.LIB files) to link with. (The linker creates the import library when the DLL is built.)
    输入库(LIB文件)
    · The actual DLL (.DLL file). 
    DLL文件(.DLL)
    Executables using the DLL must include the header file containing the exported functions (or C++ classes) in each source file that contains calls to the exported functions. From a coding perspective, the function calls to the exported functions are just like any other function call.
    每个调用输出函数的源文件必须包含(include)输出函数的头文件。调用输出函数同调用其他函数一样。
    To build the calling executable file, you must link with the import library. If you are using an external makefile, specify the file name of the import library where you list other object (.OBJ) files or libraries that you are linking with. If you are working in the Visual C++ development environment, specify the file name of the import library in the Object/Library Modules text box on the Link tab of the Project Settings dialog box.
    如果用外部makefile,指定输入库名称。输入库中列举其他对象文件(.obj)或连接库。如果使用VC开发环境,在工程设置对话框中设置输入库名(Link \ Object/Library Modules \.lib files)
    The operating system must be able to locate the .DLL file when it loads the calling executable.Link Explicitly
    With explicit linking, applications must make a function call to explicitly load the DLL at run time. To explicitly link to a DLL, an application must: 
    · Call LoadLibrary (or a similar function) to load the DLL and obtain a module handle.
    LoadLibrary:载入DLL,获得模块句柄
    · Call GetProcAddress to obtain a function pointer to each exported function that the application wants to call. Because applications are calling the DLL’s functions through a pointer, the compiler does not generate external references, so there is no need to link with an import library.
    GetProcAddress :获得应用要调用的每个输出函数的指针。因为应用通过指针调用DLL函数,编译器不需产生额外的说明,所以不需连接输入库。
    · Call FreeLibrary when done with the DLL. 
    FreeLibrary :释放DLL
    For example: 
    typedef UINT (CALLBACK* LPFNDLLFUNC1)(DWORD,UINT);
    .
    .
    .
    HINSTANCE hDLL;               // Handle to DLL
    LPFNDLLFUNC1 lpfnDllFunc1;    // Function pointer
    DWORD dwParam1;
    UINT  uParam2, uReturnVal;hDLL = LoadLibrary("MyDLL");
    if (hDLL != NULL)
    {
       lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
                                               "DLLFunc1");
       if (!lpfnDllFunc1)
       {
          // handle the error
          FreeLibrary(hDLL);       
          return SOME_ERROR_CODE;
       }
       else
       {
          // call the function
          uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
       }
    }Determine Which Linking Method to Use
    Most applications use implicit linking because it is the easiest linking method to use. However, there are times when explicit linking is necessary. Here are some common reasons to use explicit linking: 
    使用显式连接的原因:
    · The application does not know the name of a DLL that it will have to load until run time. For example, the application might need to obtain the name of the DLL and the exported functions from a configuration file.
    应用要到运行时才能知道要载入的DLL的名称。例如,应用要从一个配置文件中获取DLL输出函数的名称。
    · A process using implicit linking is terminated by the operating system if the DLL is not found at process startup. A process using explicit linking is not terminated in this situation and can attempt to recover from the error. For example, the process could notify the user of the error and have the user specify another path to the DLL.
    如果一个使用隐式连接的过程在开始时找不到DLL,将被系统终止。而使用显式连接则不会。
    · A process using implicit linking is also terminated if any of the DLLs it is linked to have a DllMain function that fails. A process using explicit linking is not terminated in this situation.
    隐式连接的过程如果DLL的DllMain功能失败,也将终止运行。显式连接则不会。
    · An application that implicitly links to many DLLs can be slow to start because Windows loads all the DLLs when the application loads. To improve startup performance, an application can implicitly link to those DLLs needed immediately after loading and wait to explicitly link to the other DLLs when they are needed.
    应用如果隐式连接许多DLL,将启动很慢,因为要载入所有的DLL。要提高启动性能,应用可以隐式连接即刻需要的DLL,其他需要时再显式连接。
    · Explicit linking eliminates the need to link the application with an import library. If changes in the DLL cause the export ordinals to change, applications using explicit linking do not have to relink (assuming they are calling GetProcAddress with a name of a function and not with an ordinal value), whereas applications using implicit linking must relink to the new import library. 
    显式连接不需要连接输入库。如果DLL改变导致输出顺序改变,使用显式连接的应用不需重新连接(因为使用GetProcAddress调用函数名称而不是顺序值)。而隐式连接的应用需要重新连接新的输入库。
    Here are two hazards of explicit linking to be aware of: 
    使用显式连接的不利因素:
    · If the DLL has a DllMain entry point function, the operating system calls the function in the context of the thread that called LoadLibrary. The entry-point function is not called if the DLL is already attached to the process because of a previous call to LoadLibrary with no corresponding call to the FreeLibrary function. Explicit linking can cause problems if the DLL is using a DllMain function to perform initialization for each thread of a process because threads existing when LoadLibrary (or AfxLoadLibrary) is called will not be initialized. 
    如果DLL入口函数为DllMain,系统在调用LoadLibrary的线程中调用此函数。这时如果没有相应调用FreeLibrary函数,以后的过程中不再调用入口点函数。如果DLL使用DllMain功能执行每个线程的初始化时,显式连接会出现问题。因为现有的线程在调用LoadLibrary(或AfxLoadLibrary)时没有初始化。· If a DLL declares static-extent data as __declspec(thread), it can cause a protection fault if explicitly linked. After the DLL is loaded with LoadLibrary, it causes a protection fault whenever the code references this data. (Static-extent data includes both global and local static items.) Therefore, when you create a DLL, you should either avoid using thread-local storage, or inform DLL users about potential pitfalls (in case they attempt dynamic loading). 
    如果DLL声明静态范围数据如__declspec(thread),则在显式连接时将导致保护错误。在调用LoadLibrary载入DLL后,无论何时引用这类数据都将导致保护错误。(静态范围数据包括全局和局部静态数据)。因此,创建DLL时,应避免使用局部线程存储,或通知使用者这一缺陷(如果他们要使用动态载入)。
      

  4.   

    教一招#pragma comment(lib,"someone.dll")