没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论



















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 并单击 Finish.在 File View 里你会看到如下的工程
文件:
第二步
在 Test.cpp 里,你将看到如下代码:
// Test.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "Test.h"

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 Test.h for the class definition
CTest::CTest()
{
return;
}
Test.cpp 包含了 fnTest 和 CTest::CTest.如果你现在编译 Test.dll, 你将会得到一
个可以被其他 VC++应用程序直接调用的 DLL.
允许其他 VC++程序调用的关键机制?( key mechanism)就包含在 Test.h 中:
// The following ifdef block is the standard way of creating macros
// which make exporting from a DLL simpler. All files within this DLL
// are compiled with the TEST_EXPORTS symbol defined on the command 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.
剩余10页未读,继续阅读
资源评论

- runalone2015-06-23有用,谢谢分享!
- maomao1314182013-11-18还不错吧 有用

执着的老李
- 粉丝: 5
- 资源: 25
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
