加载动态库
加载动态链接库(.dll)
下述示例代码,适用于 Windows 系统的 C 语言开发。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <stdio.h> #include <windows.h>
int main() {
HINSTANCE hInstance;
hInstance = LoadLibrary("./socketclient.dll"); if (hInstance == NULL) { printf("LoadLibrary() 调用失败, ErrorCode: %d", GetLastError()); return -1; }
typedef int (*CltSocketInit)(void** handle);
CltSocketInit cltSocketInit = (CltSocketInit)GetProcAddress(hInstance, "cltSocketInit"); if (cltSocketInit != NULL) { void* handle = NULL; int result = cltSocketInit(&handle); printf("result = %d", result); }
if (hInstance != NULL) { FreeLibrary(hInstance); }
return 0; }
|