码迷,mamicode.com
首页 > 其他好文 > 详细

调用动态库!

时间:2017-05-06 10:11:12      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:include   客户端   动态   资源   

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


}


调用动态库!

标签:include   客户端   动态   资源   

原文地址:http://ji123.blog.51cto.com/11333309/1922563

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!