class="java" name="code">
使用vc++创建dll,调用其它dll函数
1.File-->New-->Projects-->Win32 Dynamic-Link Library
2.录入工程名称,选择 An empty DLL project.
3.File-->New-->Files-->C/C++ Header File-->输入文件名称MyDll.h
4.内容如下
?
#ifndef _MYDLL_H_ #define _MYDLL_H_ extern "C" _declspec (dllexport) int send(char *text,int com,int rate,int addr,int displayMode,int speed,int delayTime); #endif
?
5.File-->New-->Files-->C++ Source File-->输入文件名称MyDll.cpp
6.内容如下
?
?
#include "MyDll.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int send(char *text,int com,int rate,int addr,int displayMode,int speed,int delayTime){
	char *dlladdr = "dll\\zy\\dlltpzp.dll";  
	HMODULE hModule = ::LoadLibrary(dlladdr);
	if (NULL == hModule) {
		return 0;
	}
	//加载函数
	int(_stdcall *SendDatafun)(int, long, int, char *, int, int, int, int);
	SendDatafun = (int(_stdcall *)(int, long, int, char *, int, int, int, int))GetProcAddress(hModule, "SendDatafun");
	if (NULL == SendDatafun)
	{
		::FreeLibrary(hModule);
		return -1;
	}
	UINT m_nDelayTime = 1;
	int nRetVal = SendDatafun(com, rate, addr, text,17, displayMode, speed, delayTime);
	if (0 > nRetVal)
	{
		return -2;
	}
	::FreeLibrary(hModule);
	return 1;
}
?
7.工程右键build编译完成
8.此类是加载了一个目录在dll\\zy\\dlltpzp.dll的dll文件,并调用该dll中的SendDatafun方法
?