温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

调用动态库!

发布时间:2020-06-27 22:43:24 来源:网络 阅读:524 作者:神迹难觅 栏目:编程语言

#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");


}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI