调用动态库!(include,动态,客户端,编程语言)

时间:2024-04-29 09:51:11 作者 : 石家庄SEO 分类 : 编程语言
  • TAG :

    %E8%B0%83%E7%94%A8%E5%8A%A8%E6%80%81%E5%BA%93%EF%BC%81

#include<windows.h>

#include<iostream>

//客户端初始化 获取handle上下

typedef int(*CltSocketInit)(void **handle);

//客户端发报文

typedef int(*CltSocketSend)(void *handle, unsigned char *buf, int buflen);

//客户端收报文

typedef int(*CltSocketRev)(void *handle, unsigned char *buf, int *buflen);

//客户端释放资源

typedef int(*CltSocketDestory)(void *handle);//以上都是指针函数

int main(){


HINSTANCE hinstance = NULL;

hinstance = ::LoadLibrary("D:\\SocketClient.dll");//获得句柄

CltSocketInit cltSocketInit = (CltSocketInit)GetProcAddress(hinstance, "cltSocketInit");//获取函数地址传给函数指针!

CltSocketSend cltSocketSend = (CltSocketSend)GetProcAddress(hinstance, "cltSocketSend");

CltSocketRev cltSocketRev = (CltSocketRev)::GetProcAddress(hinstance, "cltSocketRev");

CltSocketDestory cltSocketDestory = (CltSocketDestory)::GetProcAddress(hinstance, "cltSocketDestory");

void *handle = NULL;

unsigned char buf[100];

int buflen = 10;

memcpy(buf, "ddddddddddssssssssss", 10);


unsigned char out[100] = { 0 };

int outlen = 0;


int ret = cltSocketInit(&handle);


ret = cltSocketSend(handle, buf, buflen);

ret = cltSocketRev(handle, out, &outlen);

ret = cltSocketDestory(handle);


printf("out:%s", out);

system("pause");


}


本文:调用动态库!的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:C++ 防止重定义下一篇:

14 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18