下载此文档

一步一步教你用vc和vb调用c++ dll.doc


文档分类:IT计算机 | 页数:约11页 举报非法文档有奖
1/11
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/11 下载此文档
文档列表 文档介绍
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);
//

一步一步教你用vc和vb调用c++ dll 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数11
  • 收藏数0 收藏
  • 顶次数0
  • 上传人文库旗舰店
  • 文件大小467 KB
  • 时间2018-06-06