Step by Step: Calling C++ DLLs from VC++ and VB 一步一步教你用VC和VB调用C++ DLL. 本系列教程讨论了普通情况下4种使用DLL的方法 Part 1 从VC++应用程序调用C++ DLL的函数 从VC++应用程序调用C++ DLL的类 Part 2 从VB应用程序调用C++ DLL的函数 Part 3 从VB应用程序调用C++ DLL的类 Part 4 从VC++应用程序动态的调用C++ DLL的函数 从VC++应用程序调用C++ DLL的函数 Visual Studio 6 使创建包含函数或类的动态连接库(DLL) 变得非常容易。 第一步: 打开 Visual Studio 然后选择 File | New菜单项: 选择 Win32 Dynamic Link Library, 输入工程名, 敲 OK. 选择 A DLL that exports some symbols View里你会看到如下的工程文件: 第二步 ,你将看到如下代码: // : Defines the entry point for the DLL application. // #include "" #include "" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } // This is an example of an exported variable TEST_API int nTest=0; // This is an example of an exported function. TEST_API int fnTest(void) { return 42; } // This is the constructor of a class that has been exported. // see for the class definition CTest::CTest() { return; } 包含了 fnTest 和 CTest::, 你将会得到一个可以被其他VC++应用程序直接调用的DLL. 允许其他VC++程序调用的关键机制?( key mechanism)就包含在 : // The following ifdef block is the standard way of creating macros // which make exporting from a DLL simpler. All files within this DLL // piled with the TEST_EXPORTS symbol defined on mand line. // This symbol should not be defined on any project that uses this DLL. // This way any other project whose source files include this file see // TEST_API functions as being imported from a DLL, whereas this DLL // sees symbols defined with this macro as being exported. #ifdef TEST_EXPORTS #define TEST_API __declspec(dllexport) #else #define TEST_API __declspec(dllimport) #endif // This class is exported from the class TEST_API CTest { public: CTest(void); //