W
whaway
Unregistered / Unconfirmed
GUEST, unregistred user!
//用DELPHI来调用C++编写的DLL(此DLL有VC的调用例程),涉及C++译成相应的DELPHI程序问题,
//怀疑是不是C++的指针和DELPHI的指针有细小的差别,环境为Win2000+sp4,Delphi 6,VC 6,
//问题如下:
//●●DLL中的函数声明*.h头文件(部分):
//================================================
//结构声明
typedef struct _HKCANHANDLE {
HANDLE mHandle;
DWORD mGuid;
WORD mClass;
WORD mDev;
WORD mType;
WORD mState;
}HKCANHANDLE,*PHKCANHANDLE;
typedef struct _HKCANFRAME {
UCHAR nPort;
UCHAR mFrame[10];
}HKCANFRAME,*PHKCANFRAME;
//函数声明
extern BOOL _stdcall HKCanSendFrame(PHKCANHANDLE mDevHandle,
PHKCANFRAME pSendFrame);
extern int _stdcall HKCanReadFrame(PHKCANHANDLE mDevHandle,
int nPort,
PHKCANFRAME pReadFrame);
//●●VC中对这两个函数的调用(运行完全正常):
//================================================
HKCANFRAME m_snd,m_rec;
HKCANHANDLE m_devicehandle;
int Temp;
Send = HKCanSendFrame(&m_devicehandle,&m_snd);
Read = HKCanReadFrame(&m_devicehandle,Temp,&m_rec);
//●●DELPHI转译*.h文件为*.PAS文件(对应):
//================================================
//结构声明
type
_HKCANHANDLE = record
mHandle: THandle;
mGuid: DWord;
mClass: Word;
mDev: Word;
mType: Word;
mState: Word;
end {_HKCANHANDLE};
HKCANHANDLE = _HKCANHANDLE;
PHKCANHANDLE = ^_HKCANHANDLE;
type
_HKCANFRAME = record
nPort: UCHAR;
mFrame: array[0..10- 1] of UCHAR;
end {_HKCANFRAME};
HKCANFRAME = _HKCANFRAME;
PHKCANFRAME = ^_HKCANFRAME;
//函数声明
function HKCanSendFrame(var mDevHandle: HKCANHANDLE;
var pSendFrame: HKCANFRAME): Bool cdecl{$IFDEF WIN32} stdcall{$ENDIF};
function HKCanReadFrame(var mDevHandle: HKCANHANDLE;
nPort: Integer;
pReadFrame: HKCANFRAME): Integer cdecl{$IFDEF WIN32} stdcall{$ENDIF};
//●●DELPHI对函数的调用(问题在这里):
//================================================
m_snd, m_rec: HKCANFRAME;
m_devicehandle: HKCANHANDLE;
TempPort:integer;
Send := HKCanSendFrame(m_devicehandle, m_snd);//此函数运行完全正常,返回值正确
Read := HKCanReadFrame(m_devicehandle, TempPort, m_snd);
//调用就出现'access violation at 0x10001ebd:write of address 0x01080100'错误
//HKCanSendFrame两个参数都是输入
//HKCanReadFrame三个参数是输入,输入,输出
//因此怀疑问题就出在这,不知道怎么解决
//怀疑是不是C++的指针和DELPHI的指针有细小的差别,环境为Win2000+sp4,Delphi 6,VC 6,
//问题如下:
//●●DLL中的函数声明*.h头文件(部分):
//================================================
//结构声明
typedef struct _HKCANHANDLE {
HANDLE mHandle;
DWORD mGuid;
WORD mClass;
WORD mDev;
WORD mType;
WORD mState;
}HKCANHANDLE,*PHKCANHANDLE;
typedef struct _HKCANFRAME {
UCHAR nPort;
UCHAR mFrame[10];
}HKCANFRAME,*PHKCANFRAME;
//函数声明
extern BOOL _stdcall HKCanSendFrame(PHKCANHANDLE mDevHandle,
PHKCANFRAME pSendFrame);
extern int _stdcall HKCanReadFrame(PHKCANHANDLE mDevHandle,
int nPort,
PHKCANFRAME pReadFrame);
//●●VC中对这两个函数的调用(运行完全正常):
//================================================
HKCANFRAME m_snd,m_rec;
HKCANHANDLE m_devicehandle;
int Temp;
Send = HKCanSendFrame(&m_devicehandle,&m_snd);
Read = HKCanReadFrame(&m_devicehandle,Temp,&m_rec);
//●●DELPHI转译*.h文件为*.PAS文件(对应):
//================================================
//结构声明
type
_HKCANHANDLE = record
mHandle: THandle;
mGuid: DWord;
mClass: Word;
mDev: Word;
mType: Word;
mState: Word;
end {_HKCANHANDLE};
HKCANHANDLE = _HKCANHANDLE;
PHKCANHANDLE = ^_HKCANHANDLE;
type
_HKCANFRAME = record
nPort: UCHAR;
mFrame: array[0..10- 1] of UCHAR;
end {_HKCANFRAME};
HKCANFRAME = _HKCANFRAME;
PHKCANFRAME = ^_HKCANFRAME;
//函数声明
function HKCanSendFrame(var mDevHandle: HKCANHANDLE;
var pSendFrame: HKCANFRAME): Bool cdecl{$IFDEF WIN32} stdcall{$ENDIF};
function HKCanReadFrame(var mDevHandle: HKCANHANDLE;
nPort: Integer;
pReadFrame: HKCANFRAME): Integer cdecl{$IFDEF WIN32} stdcall{$ENDIF};
//●●DELPHI对函数的调用(问题在这里):
//================================================
m_snd, m_rec: HKCANFRAME;
m_devicehandle: HKCANHANDLE;
TempPort:integer;
Send := HKCanSendFrame(m_devicehandle, m_snd);//此函数运行完全正常,返回值正确
Read := HKCanReadFrame(m_devicehandle, TempPort, m_snd);
//调用就出现'access violation at 0x10001ebd:write of address 0x01080100'错误
//HKCanSendFrame两个参数都是输入
//HKCanReadFrame三个参数是输入,输入,输出
//因此怀疑问题就出在这,不知道怎么解决