VC动态调用DLL
1、
//函数指针声明 typedef int (_stdcall MYDLLFUN)(char* _pcOut, /*INOUT*/int *_piOutBufLen, char* _pcIn, int _iInBufLen);
2、
HINSTANCE hmydll=::LoadLibrary("_DrCompressDll.DLL"); mydllfun=(MYDLLFUN *)::GetProcAddress(hmydll, "CompressZ");
3、VS2010 动态调用 DLL示例:
#include <stdio.h> #include <Windows.h> typedef int (__stdcall *TfnC_ExecJS)( void *_pSvgFrm, char* _pcJS );//定义形式对应的函数指针类型 typedef int (__stdcall *TfnD_PassStId)( void *Sender, char* _pcStId ); #define DLL_NAME "DrRemoteCall.dll" TfnC_ExecJS g_fnExecJS = NULL;//声明一个函数指针 TfnD_PassStId g_fnPassStId = NULL; void main() { HINSTANCE hDll = LoadLibraryA(DLL_NAME); if(hDll == NULL) { printf("无法载入dll : %s\n", DLL_NAME); FreeLibrary(hDll); getchar(); return; } g_fnExecJS = (TfnC_ExecJS)GetProcAddress(hDll, "ExecJS"); if(g_fnExecJS == NULL) { printf("无法获取函数地址(ExecJS)\n"); FreeLibrary(hDll); getchar(); return; } g_fnPassStId = (TfnD_PassStId)GetProcAddress(hDll, "PassStId"); if(g_fnPassStId == NULL) { printf("无法获取函数地址(PassStId)\n"); FreeLibrary(hDll); getchar(); return; } // 调用函数 int iRtn = g_fnPassStId(NULL, "TestA"); printf("PassStId return %d\n", iRtn); FreeLibrary(hDll); getchar(); return; }
4、
5、