明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2293|回复: 0

[求助]如何在VC中调用DLL

[复制链接]
发表于 2003-9-24 09:58:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2003-9-24 11:13:19 编辑

这有一个例子,能帮我写出来吗?(不用MFC)
dll路径:C:\web.dll
有一个函数:int _stdcall connect(HTTP_CONNECTION **connection, const char *host, short port, const char *username, const char *password)
其中HTTP_CONNECTION 是一个结构体,定义如下
struct http_connection {
SOCKET socketd;
int status;
char *host;
struct sockaddr_in address;
int persistent;
HTTP_AUTH_INFO *auth_info;
};
(其它定义略)
问题:我怎么调用这个函数?比如在head.h 中如何声明,head.cpp中如何使用?
静态如何?
动态如何?
谢谢!
声明:
#define DllImport _declspec(dllimport)

typedef struct http_connection      HTTP_CONNECTION;
typedef struct http_auth_parameter  HTTP_AUTH_PARAMETER;
typedef struct http_auth_info       HTTP_AUTH_INFO;

struct http_connection {
SOCKET socketd;
int status;
char *host;
struct sockaddr_in address;
int persistent;
HTTP_AUTH_INFO *auth_info;
};

struct http_auth_parameter {
char *name;
char *value;
HTTP_AUTH_PARAMETER *next_parameter;
HTTP_AUTH_PARAMETER *prev_parameter;
};

struct http_auth_info {
char *method;
int count;
HTTP_AUTH_PARAMETER *first_parameter;
HTTP_AUTH_PARAMETER *last_parameter;
};

extern "C" int _stdcall dav_init(void);

extern "C" int _stdcall dav_connect(HTTP_CONNECTION **connection, const char *host, short port, const char *username, const char *password);
调用:
HTTP_CONNECTION *connection = NULL;
connection = (HTTP_CONNECTION *) malloc(sizeof(HTTP_CONNECTION));
typedef int(proc1)(HTTP_CONNECTION **connection, const char *host, short port, const char *username, const char *password);

proc1* pFunc1;
HINSTANCE hInstance;
hInstance=:oadLibrary("C:\\ploting\\webdav.dll");
if(hInstance==NULL)
{
        acutPrintf("\n can not fine dll file.");
}
        pFunc1=(proc1*)::GetProcAddress(hInstance,"dav_connect");
int test=(*pFunc1)(&connection,(char *)"192.168.0.22",8080,(char *)"maf",(char *)"maf");
acutPrintf("\n test is %d",test);
编译错误:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

是为什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 18:37 , Processed in 0.168962 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表