以下是为SDK单独写的一个单元
unit caTest;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
SERIALNO_LEN = 48;
type
NET_DVR_DEVICEINFO = record
sSerialNumber: array[1..SERIALNO_LEN-1] of BYTE;
byAlarmInPortNum:BYTE;
byAlarmOutPortNum:BYTE;
byDiskNum:BYTE;
byDVRType:BYTE;
byChanNum:BYTE;
byStartChan:BYTE;
end;
LPNET_DVR_DEVICEINFO=^NET_DVR_DEVICEINFO;
const
dllfile = 'HCNetSDK.dll';
function NET_DVR_Login(sDVRIP:pchar; wDVRPort:WORD; sUserName:pchar; sPassword:pchar; lpDeviceInfo:LPNET_DVR_DEVICEINFO) : LongInt; stdcall; external dllfile;
implementationend.
在这个单元中被引用
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, caTest;
其他的东西不贴出来了,看下我调用caTest单元中的函数
var
UserName: pchar;
UserPassword: pchar;
ServerIP: pchar;
ServerPost: WORD;
UserID: LongInt;
procedure TMainForm.FormShow(Sender: TObject);
var pDEVICEINFO:LPNET_DVR_DEVICEINFO;
begin
ServerIP := pchar('102.168,0,88');
ServerPost := WORD(strToint('8000'));
MainForm.UserName := pchar('admin');
MainForm.UserPassword := pchar('12345');
UserID := NET_DVR_Login(ServerIP, ServerPost, UserName, UserPassword, @pDEVICEINFO);
if(UserID < 0) then
showmessage('登录失败!')
else
showmessage('登录成功!')
end;执行后,得到UserID=0,且pDEVICEINFO的值也非常正确,会弹出登录成功对话框。再向下执行就会报错:
access violation at 0x7c9579d1:write of address 0x00030ffc
process stopped.use step or run to continue.
后面我没有执行任何操作。能告诉我这是为什么吗~?
unit caTest;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
SERIALNO_LEN = 48;
type
NET_DVR_DEVICEINFO = record
sSerialNumber: array[1..SERIALNO_LEN-1] of BYTE;
byAlarmInPortNum:BYTE;
byAlarmOutPortNum:BYTE;
byDiskNum:BYTE;
byDVRType:BYTE;
byChanNum:BYTE;
byStartChan:BYTE;
end;
LPNET_DVR_DEVICEINFO=^NET_DVR_DEVICEINFO;
const
dllfile = 'HCNetSDK.dll';
function NET_DVR_Login(sDVRIP:pchar; wDVRPort:WORD; sUserName:pchar; sPassword:pchar; lpDeviceInfo:LPNET_DVR_DEVICEINFO) : LongInt; stdcall; external dllfile;
implementationend.
在这个单元中被引用
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, caTest;
其他的东西不贴出来了,看下我调用caTest单元中的函数
var
UserName: pchar;
UserPassword: pchar;
ServerIP: pchar;
ServerPost: WORD;
UserID: LongInt;
procedure TMainForm.FormShow(Sender: TObject);
var pDEVICEINFO:LPNET_DVR_DEVICEINFO;
begin
ServerIP := pchar('102.168,0,88');
ServerPost := WORD(strToint('8000'));
MainForm.UserName := pchar('admin');
MainForm.UserPassword := pchar('12345');
UserID := NET_DVR_Login(ServerIP, ServerPost, UserName, UserPassword, @pDEVICEINFO);
if(UserID < 0) then
showmessage('登录失败!')
else
showmessage('登录成功!')
end;执行后,得到UserID=0,且pDEVICEINFO的值也非常正确,会弹出登录成功对话框。再向下执行就会报错:
access violation at 0x7c9579d1:write of address 0x00030ffc
process stopped.use step or run to continue.
后面我没有执行任何操作。能告诉我这是为什么吗~?
或许 new(pDEVICEINFO) 然后NET_DVR_Login(ServerIP, ServerPost, UserName, UserPassword, pDEVICEINFO);用完了释放空间dispose(pDEVICEINFO)
var pDEVICEINFO: NET_DVR_DEVICEINFO;
begin
ServerIP := pchar('102.168,0,88');
ServerPost := WORD(strToint('8000'));
MainForm.UserName := pchar('admin');
MainForm.UserPassword := pchar('12345');
UserID := NET_DVR_Login(ServerIP, ServerPost, UserName, UserPassword, @pDEVICEINFO);
if(UserID < 0) then
showmessage('登录失败!')
else
showmessage('登录成功!')
end;
SERIALNO_LEN = 48;NET_DVR_DEVICEINFO = record
sSerialNumber: array[0..SERIALNO_LEN-1] of BYTE;
byAlarmInPortNum:BYTE;
byAlarmOutPortNum:BYTE;
byDiskNum:BYTE;
byDVRType:BYTE;
byChanNum:BYTE;
byStartChan:BYTE;
end;procedure TMainForm.FormCreate(Sender: TObject);
var
pDEVICEINFO :NET_DVR_DEVICEINFO;
begin
if NET_DVR_Init then
begin
showmessage('SDK初始化成功,请登录DVR');
LoginForm:=TLoginForm.Create(Application);
LoginShowAction:
LoginForm.ShowModal; UserID := NET_DVR_Login(PChar(ServerIP), ServerPost, PChar(UserName), PChar(UserPassword), pDEVICEINFO);
begin
if(UserID < 0) then
showmessage('登录失败!');
else
showmessage('登录成功!');
end;
end
else
begin
showmessage('SDK初始化失败,主程序将关闭');
end;
end;