- 积分
- 1771
- 明经币
- 个
- 注册时间
- 2003-7-22
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 作者 于 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.
是为什么? |
|