我们现在有一个视频监控的SDK,其中的DLL是用VC++编的,我知道调用DELPHI自己编的DLL,但却对调用VC编的有些不明白---主要是不知道那些函数在DELPHI中该怎样声明以及参数该怎样调用?该SDK中有个socketdll.dll,然后有个用VC调用这个DLL的示例文件socketdll.h,socketdll.h内容如下:
#ifndef SOCKETDLL_H
#define SOCKETDLL_H#include <windows.h>
#include <time.h>//==================macro define=====================#define OK 0
#define FAIL -1
#define INVALID_CHANNEL_NUM (short)-1
#define MAX_PEER_NUM 64//====================消息定义========================#define WM_CONNECT_OK WM_USER+10
#define WM_CONNECT_FAIL WM_USER+11
#define WM_READ_CTRL_MSG WM_USER+12//===================报文类型定义=====================#define MT_OPEN_CHANNEL 'A'
#define MT_CLOSE_CHANNEL 'B'
#define MT_CHANNEL_PHOT_DATA 'C'
#define MT_FILE_PHOT_DATA 'D'#define MT_ALARM_MSG '$'#define MT_NET_TEST_REQU '>'
#define MT_NET_TEST_RESP '<'//====================帧类型定义======================#define FT_HEAD 'H'
#define FT_IFRAME 'I'
#define FT_BFRAME 'B'
#define FT_PFRAME 'P'
#define FT_AUDIO 'A'//====================结构定义========================//链表头结点
typedef struct HeadNode{
long nlNodeNum; //链表结点个数
void *lpNext; //指向的链表指针
}HEADNODE;//报文头结构
typedef struct MsgHead{
long nlMsgBodyLen; //数据包长度(不含包头)
char cMsgType; //报文类型
char cFrameType; //帧类型
struct in_addr stxPhotSourAddr; //图像源服务器IP
u_short usPhotServPort; //图像源服务器端口号
short nsChannel; //图像源服务器通道编号
short nsRouteNum; //路由表节点数
short nsNextPos; //下一节点在路由表中的序号(0,1,2...)
//节点收到报文时,表示本节点在路由表的序号
//发送报文时,该序号递增1
//eg: |源结点|路由结点1|路由结点2|...|路由结点n|目的结点|
time_t lTimeStamp; //报文到达结点时间(秒)
short nsWaitTime; //报文等待发送时间(秒)
}MSGHEAD;//主机信息结构(唯一标识一台主机)
typedef struct RouteInf{
struct in_addr ulAddr;
u_short usPort;
}ROUTEINF;//端口通道信息(用于向主线程发送连接信息)
typedef union PortCh{
struct{
short nsChannel;
u_short usPort;
} stxPortChannel;
long lPortChannel;
}PORTCHANINF;
//==================function define=================typedef int APIENTRY GETROUTEINF(struct in_addr *lpRemoteAddr, u_short usRemotePort, ROUTEINF RouteInf[]);
typedef int APIENTRY LOCALMSGHANDLE(MSGHEAD *lpMsgHead, byte *lpMsgBody);//====================结构定义========================//导出全局变量结构
typedef struct GlobVar{
HWND hWnd; //Main window handle
HANDLE hReadEvent; //Read message event
char TransferListFile[MAX_PATH]; //transfer list map file
char ReconnListFile[MAX_PATH]; //reconnect list map file
char LoclReqListFile[MAX_PATH]; //local request list map file
GETROUTEINF *lpGetRouteInf; //
LOCALMSGHANDLE *lpLocalMsgHandle; //}GLOBVAR;//==================== Class define ========================
class CSocketDll
{
public: //Initial SocketDll
virtual void APIENTRY InitSocketDll()=0;
//Transfer the global var address pointer
virtual GlobVar *APIENTRY GetGlobVarAddr()=0; //Start Server
virtual int APIENTRY StartServ(u_short ServPort)=0;
//Connect Server
virtual int APIENTRY ConnectServ(struct in_addr *lpRemoteAddr, u_short usServPort)=0;
virtual int APIENTRY ConnectServ(char *lpRemoteAddr, u_short usServPort)=0;
//Disconnect from server
virtual int APIENTRY DisConnect(struct in_addr *lpRemoteAddr, u_short usServPort)=0;
virtual int APIENTRY DisConnect(char *lpRemoteAddr, u_short usServPort)=0; //Server send the photo data message
virtual void APIENTRY ServSendPhotMsg(short nsChannel, char cMsgType, char cFrameType, byte *lpPhotData, int niPhotDataLen)=0;
//Client send the control message
virtual void APIENTRY ClientSendCtrlMsg(struct in_addr *lpPhotServAddr, u_short usPhotServPort, short nsChannel, char cMsgType, byte *lpMsg, int niMsgLen)=0;
virtual void APIENTRY ClientSendCtrlMsg(char *lpPhotServAddr, u_short usPhotServPort, short nsChannel, char cMsgType, byte *lpMsg, int niMsgLen)=0;
//Server send the control message
virtual void APIENTRY ServSendCtrlMsg(ROUTEINF RouteInf[], int niRouteNum, short nsChannel, char cMsgType, char cFrameType, byte *lpMsg, int niMsgLen)=0;
//Server send the alarm message
virtual void APIENTRY ServSendAlarmMsg(short nsChannel, char cMsgType, byte *lpMsg, int niMsgLen)=0; //Local Photo Request
virtual void APIENTRY OpenChannelReq(struct in_addr *lpPhotSrcAddr, u_short usPhotSrcPort, u_short nsChannel)=0;
virtual void APIENTRY OpenChannelReq(char *lpPhotSrcAddr, u_short usPhotSrcPort, u_short nsChannel)=0;
//Close channel Request
virtual void APIENTRY CloseChannelReq(struct in_addr *lpPhotSrcAddr, u_short usPhotSrcPort, u_short nsChannel)=0;
virtual void APIENTRY CloseChannelReq(char *lpPhotSrcAddr, u_short usPhotSrcPort, u_short nsChannel)=0; //reverse the route information in the message body
virtual void APIENTRY ReverseRouteInf(short nsRouteNum, ROUTEINF RouteInf[])=0; //read the control message from list
virtual BOOL APIENTRY ReadCtrlMsg(MSGHEAD *lpMsgHead, byte *lpMsgBody)=0;
};//====================Export function======================
//Create the SocketDll object
CSocketDll *APIENTRY CreateSocketDll();
//Release the SocketDll resource
void APIENTRY ReleaseSocketDll();#endif
从这个文件的内容看,这个DLL能在DELPHI中调用吗?有人说这种方法定义的DLL在DELPHI中不能调用,是这样的吗?我对VC不熟,特别不明白:
typedef int APIENTRY GETROUTEINF(struct in_addr *lpRemoteAddr, u_short usRemotePort, ROUTEINF RouteInf[]);
typedef int APIENTRY LOCALMSGHANDLE(MSGHEAD *lpMsgHead, byte *lpMsgBody);
和//====================Export function======================
//Create the SocketDll object
CSocketDll *APIENTRY CreateSocketDll();
//Release the SocketDll resource
void APIENTRY ReleaseSocketDll();
的含义。敬请VC版高手指教,谢谢!

解决方案 »

  1.   

    这个DLL导出的是C++的类,DELPHI不能调用,DELPHI调用的必需是C的函数
      

  2.   

    哦,楼上的刚刚在我前面一点发出,所以没看见!那有没有没的办法能够用这个DLL呢?
      

  3.   

    1)把上面的dll改成c代码;
    2)如果没有源代码,可再用vc封装一次上面的dll,封出一个c版本的dll
      

  4.   

    用c++写一个包装dll,包装这个dll.并且引出标准api函数ps:这dll引出的是c++类,于是它不仅仅和语言相关,还和编译器相关,如果你要写这个dll,如果原来那个是vc写个,这个也要用vc
      

  5.   

    填写.def文件,然后用API GetProcAddress来加载
      

  6.   

    各位大侠;如何包装DLL,能否详细告之!?