0
点赞
收藏
分享

微信扫一扫

GetModuleHandle("qq.dll");hDll_debug2=LoadLibrary("..\\qq\\Debug\\qq.dll");


// qq.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include <stdio.h>
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}

void sayhello()
{
#ifdef _DEBUG
	printf("hello debug!\n");
#else
	printf("hello release!\n");
#endif
}

; lib.def : 导出DLL函数


LIBRARY qq


EXPORTS


sayhello @ 1


;.def文件的规则为:


;  (1)LIBRARY语句说明.def文件相应的DLL;


;  (2)EXPORTS语句后列出要导出函数的名称。可以在.def文件中的导出函数名后加@n,表示要导出函数的序号为n(在进行函数调用时,这个序号将发挥其作用);


;  (3).def 文件中的注释由每个注释行开始处的分号 (;) 指定,且注释不能与语句共享一行。


;  由此可以看出,例子中lib.def文件的含义为生成名为“dllTest”的动态链接库,导出其中的add函数,并指定add函数的序号为1。


// TestQQ.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

int main(int argc, char* argv[])
{
	typedef void (*TPsayhello)();
	TPsayhello psayhello=NULL;
	HINSTANCE hDll_debug=LoadLibrary("..\\qq\\Debug\\qq.dll");
	HINSTANCE hDll_release=LoadLibrary("..\\qq\\Release\\qq.dll");
	psayhello=(TPsayhello)GetProcAddress(hDll_debug, "sayhello");//获得dll中的函数指针
	psayhello();
	psayhello=(TPsayhello)GetProcAddress(hDll_release, "sayhello");//获得dll中的函数指针
	psayhello();

	HINSTANCE hDll_=GetModuleHandle("qq.dll");
	HINSTANCE hDll_debug2=LoadLibrary("..\\qq\\Debug\\qq.dll");
	printf("hDll_debug:%x;hDll_release:%x;hDll_:%x;hDll_debug2:%x\n",hDll_debug,hDll_release,hDll_,hDll_debug2);

	FreeLibrary(hDll_debug2);
	FreeLibrary(hDll_debug);
	FreeLibrary(hDll_release);
	printf("Hello World!\n");
	return 0;
}
/*
hello debug!
hello release!
hDll_debug:10000000;hDll_release:3b0000;hDll_:10000000;hDll_debug2:10000000
Hello World!
Press any key to continue
*/




举报

相关推荐

0 条评论