调用dll报错(100)

  • 主题发起人 主题发起人 常广荣
  • 开始时间 开始时间

常广荣

Unregistered / Unconfirmed
GUEST, unregistred user!
我在调用dll时大约过了几分钟主程序报错:raised too many consecutive exceptions:'privileged instruction at 0x0013ff64'.退出程序时提示:Invalid pointer operation.请哪个高手帮我看看,代码如下:unit UnitJLCapMain;interfaceuses Sharemem,windows, classes, SysUtils, UntDVSNETDefine, forms, lib_xvid;type //数据回调函数 PDataCallBack = ^TDataCallBack; TDataCallBack = procedure(AData: Pointer; //数据 ALen: Integer; //长度 ACallBackCameraID: Integer; //摄像机号 ADataType: Integer; //数据类型 AParam1: Integer; //参数一 AParam2: Integer; //参数二 AParam3: Integer; //参数三 AParam4: Integer; //参数四 AParam5: Integer //参数五 ); stdcall; PTJLCamInfo = ^TJLCamInfo; TJLCamInfo = packed record IP: string; //IP地址 Port: Integer; //端口号 LoginName: string; //登录名 LoginPwd: string; //登录密码 ChannelID: Integer; //------通道号 CallBackChannelID: Integer; //外部摄像机号 ServerName: string; //摄像机名称 Serverwnp: THandle; //------登录时返回的句柄 Channelwnp: THandle; //------打开通道的句柄 DataSize: Integer; //数据大小 RecvSize: Integer; //接收数据大小 Dec_LeftSize: integer; //解码后剩余的数据 VideoData: array[0..100000 - 1] of byte; //视频数据 RawVideo: array[0..720 * 576 * 3 - 1] of byte; //已接收视频数据 xVid_decode: xvid_dec_create_t; //创建解码器类型 xvid_decFrame: xvid_dec_frame_t; //-----解码数据帧类型 DecHaveCreate: Boolean; //判断解码器是否创建 FRawCallBackOn: Boolean; //判断是否打开压缩视频回调 FEncCallBackOn: Boolean; //判断是否打开原始视频回调 OpenCallBackOn: Boolean; end; //设置回调函数procedure SetDataCallBack(ACallBack: TDataCallBack); stdcall;//打开摄像机, 成功返回Truefunction OpenCamera(AHostName: Pointer; //摄像机的域名或IP地址 AHostNameLen: Integer; //AHostName的长度 APort: Integer; //端口号 ALoginName: Pointer; //登录用户名 ALoginNameLen: Integer; //登录用户名的长度 ALoginPwd: Pointer; //登录密码 ALoginPwdLen: Integer; //登录密码长度 ACameraID: Integer; //要打开的摄像机在视频服务器中的通道号 ACallBackCameraID: Integer; //回调时返回的通道号(也就是外部程序使用的通道号) hWndf: Hwnd; //------新的显示窗口句柄 ABakParam1: Integer; //备用参数1 ABakParam2: Integer //备用参数2 ): Boolean; stdcall;//关闭摄像机procedure CloseCamera(ACallBackCameraID: Integer); stdcall;//设置视频参数(亮度、对比度、饱和度、色度),设置成功就返回True//对于AParamType的定义: 1-亮度 2-对比度 3-饱和度 4-色度function SetVideoParam(ACallBackCameraID: Integer; AParamType: Integer; AParamValue: Integer): Boolean; stdcall;//获取视频参数(亮度、对比度、饱和度、色度),取参数成功就返回True//对于AParamType的定义: 1-亮度 2-对比度 3-饱和度 4-色度function GetVideoParam(ACallBackCameraID: Integer; AParamType: Integer; AParamValue: PInteger): Boolean; stdcall;//打开或关闭某种数据回调//对于ACallBackType的定义:1-原始视频 2-原始音频 3-压缩视频 4-压缩音频 5-报警事件 6-日志procedure SetCallBackEnable(ACallBackCameraID: Integer; ACallBackType: Integer; AEnable: Boolean); stdcall;//云台控制//ACommand:云台控制命令//AValue是命令的值,这个值只有在设置和调用预置位时才有效//AStop是让云台停止动作还是开始动作,0-开始,1-停止,云台的每一个动作都要调用该//函数两次,前面两个参数一样,只是AStop一次为0,一次为1//返回值:TRUE表示成功,FALSE表示失败。//ACommand的详细定义//PTZ_IN = 1; //焦距以变大(倍率变大)//PTZ_OUT = 2; //焦距变小(倍率变小)//PTZ_UP = 3; //云台向上//PTZ_DOWN = 4; //云台向下//PTZ_LEFT = 5; //云台左转//PTZ_RIGHT = 6; //云台右转//PTZ_SET = 7; //设置预置位//PTZ_GET = 8; //调用预置位function PtzControl(ACallBackCameraID: Integer; ACommand: Integer; AValue: Integer; AStop: Integer): Boolean; stdcall;//多功能备用函数function CustomFunction(AData: Pointer; ALen: Integer): Integer; stdcall;//获得多路视频信息function GetCamInfoA(ACallBackCameraID: Integer): PTJLCamInfo;implementationconst IsDebug = False;var OutCallBack: TDataCallBack; //数据回调结构 xvid_Version: Integer; //解码数据帧结构 xvid_gbl: xvid_gbl_init_t; haveinit: boolean = false; //判断解码器是否初始化 FCameraList: TList; //Pointer type is PTJLCamInfo FCameraListHaveCreate: Boolean = False; FChannelInfo: DVSNET_CHANNEL_INFO; //-------通道结构 FChannelInfoHaveCreate: Boolean; //----判断是否创建列表 FAcallBackID: integer;procedure DecompressFrame(ACallBackCameraID: Integer; AInputBuffer: Pointer; AInputLen: Integer; AOutputBuffer: Pointer; var AOutputLen: Integer);var ret: Integer; pci: PTJLCamInfo;begin pci := GetCamInfoA(ACallBackCameraID); if pci <> nil then begin //初始化解码数据帧结构 pci^.xvid_decFrame.version := xvid_Version; pci^.xvid_decFrame.general := 0; pci^.xvid_decFrame.bitstream := AInputBuffer; //输入解压的位流 pci^.xvid_decFrame.length := AInputLen; //输入位流长度 pci^.xvid_decFrame.output.csp := XVID_CSP_BGR; //XVID_CSP_YUY2 ; //色彩空间 pci^.xvid_decFrame.output.plane[0] := AOutputBuffer; //解压后输出的缓冲区 pci^.xvid_decFrame.output.stride[0] := 320 * 3; //320 * 2; //每行字节数 ret := xvid_decore(pci^.xVid_decode.handle, XVID_DEC_DECODE, @(pci^.xvid_decFrame), nil); AOutputLen := ret; end;end;//----------添加摄像机信息保存在FCameraList中(AIP--IP地址 APORT---端口号 ChnID---通道号)function GetCamInfo(AIP: string; APort: Integer; ChnID: Integer): PTJLCamInfo;var p: PTJLCamInfo; i, c: Integer;begin result := nil; if FCameraListHaveCreate then begin c := FCameraList.Count; for i := 0 to c - 1 do begin p := FCameraList.Items; if (p^.IP = AIP) and (p^.Port = APort) and (p^.ChannelID = ChnID) then begin result := p; break; end; end; end;end;//------根据ACallBackCameraID外部摄像机号获取摄像机信息function GetCamInfoA(ACallBackCameraID: Integer): PTJLCamInfo;var p: PTJLCamInfo; i, c: Integer;begin result := nil; if FCameraListHaveCreate then begin c := FCameraList.Count; for i := 0 to c - 1 do begin p := FCameraList.Items; if p^.CallBackChannelID = ACallBackCameraID then begin result := p; break; end; end; end;end;//------服务器回调函数procedure ServerMsgCallback(hServer: THandle; dwCmd: dword; nChannel: dword; pBuf: Pointer; dwBufSize: dword; pcontext: Pointer); stdcall;var pci: PTJLCamInfo; dcmd: Dword; ret: Boolean;begin pci := GetCamInfoA(Integer(pcontext)); if pci <> nil then begin if dwcmd = $70000 then begin pci^.OpenCallBackOn := false; end; end;end;//---------时间回调函数procedure TimerProc(hwnd: HWND; uMsg: UINT; idEvent: UINT; dwTime: DWORD);var pci: PTJLCamInfo; i, c: Integer; ret: boolean;begin c := FCameraList.Count; for i := 0 to c - 1 do begin pci := FCameraList.Items; if pci^.OpenCallBackOn = false then begin //--------打开服务器 ret := OpenCamera(Pchar(pci^.IP), Length(pci^.IP), pci^.Port, Pchar(pci^.LoginName), Length(pci^.LoginName), Pchar(pci^.LoginPwd), Length(pci^.LoginPwd), pci^.ChannelID, pci^.CallBackChannelID, 0, 0, 0); if ret then begin pci^.OpenCallBackOn := true; end; end; end;end;//---------回调函数procedure OnStreamCallback(hChannel: THandle; pDataPacket: DATA_PACKET; pcontext: Pointer); stdcall;var iRawSize, UsedSize, Size: Integer; pci: PTJLCamInfo; Buf: pointer;begin pci := pcontext; if pci <> nil then begin if Assigned(OutCallBack) then begin try if pDataPacket^.FrameHeader.nVideoSize > 0 then begin if pDataPacket^.bIsDataHead = #1 then begin pci^.RecvSize := 0; pci^.DataSize := pDataPacket.FrameHeader.nVideoSize; end; if pDataPacket^.nBufSize > 0 then begin if pci^.Dec_LeftSize > 0 then begin CopyMemory(@(pci^.VideoData[pci^.DataSize - pci^.Dec_LeftSize]), @(pci^.VideoData[0]), pci^.Dec_LeftSize); pci^.RecvSize := pci^.Dec_LeftSize; pci^.DataSize := pci^.DataSize + pci^.Dec_LeftSize; pci^.Dec_LeftSize := 0; end; CopyMemory(@(pci^.VideoData[pci^.RecvSize]), @(pDataPacket^.PackData[0]), pDataPacket^.nBufSize); pci^.RecvSize := pci^.RecvSize + pDataPacket.nBufSize; if pci^.RecvSize >= pci^.DataSize then begin if pci^.FEncCallBackOn then OutCallBack(@(pDataPacket^.PackData[0]), pci^.RecvSize, pci^.CallBackChannelID, 3, 0, 0, 0, 0, 0); if pci^.FRawCallBackOn then begin Size := pci^.DataSize; Buf := @(pci^.VideoData[0]); while (Size > 3) do //or(UsedSize <> 0) begin DecompressFrame(pci^.CallBackChannelID, Buf, Size, @(pci^.RawVideo[0]), UsedSize); if UsedSize > 0 then begin Buf := Pointer(Longint(Buf) + UsedSize); Size := Size - UsedSize; end else break; OutCallBack(@(pci^.RawVideo[0]), 153600, pci^.CallBackChannelID, 1, 0, 0, 0, 0, 0); ; end; pci^.Dec_LeftSize := Size; end; end; end; end; except end; end; end;end;//设置回调函数procedure SetDataCallBack(ACallBack: TDataCallBack);begin OutCallBack := ACallBack; //FillChar(OutCallBack, 100, #0);end;//打开摄像机, 成功返回Truefunction OpenCamera(AHostName: Pointer; //摄像机的域名或IP地址 AHostNameLen: Integer; //AHostName的长度 APort: Integer; //端口号 ALoginName: Pointer; //登录用户名 ALoginNameLen: Integer; //登录用户名的长度 ALoginPwd: Pointer; //登录密码 ALoginPwdLen: Integer; //登录密码长度 ACameraID: Integer; //要打开的摄像机在视频服务器中的通道号 ACallBackCameraID: Integer; //回调时返回的通道号(也就是外部程序使用的通道号) hWndf: Hwnd; //------新的显示窗口句柄 ABakParam1: Integer; //备用参数1 ABakParam2: Integer //备用参数2 ): Boolean;var servername: string; pci: PTJLCamInfo; mHostName, mLoginName, mLoginPwd: string; iRet: Integer;begin result := False; if not FCameraListHaveCreate then begin FCameraList := TList.Create; FCameraListHaveCreate := True; end; if AHostNameLen > 0 then begin SetLength(mHostName, AHostNameLen); CopyMemory(@mHostName[1], AHostName, AHostNameLen); end; if ALoginNameLen > 0 then begin SetLength(mLoginName, ALoginNameLen); CopyMemory(@mLoginName[1], ALoginName, ALoginNameLen); end; if ALoginPwdLen > 0 then begin SetLength(mLoginPwd, ALoginPwdLen); CopyMemory(@mLoginPwd[1], ALoginPwd, ALoginPwdLen); end; if not haveinit then begin xvid_Version := XVID_MAKE_VERSION(1, 1, 3); //XVID库初始化操作 xvid_gbl.version := xvid_Version; //Version:1.1.0 xvid_gbl.cpu_flags := Word(XVID_CPU_FORCE or XVID_CPU_ASM); //0:自动检查CPU,XVID_CPU_FORCE or XVID_CPU_ASM:强制使用ASM汇编优化 xvid_gbl.debug := 0; //调试级别 //初始化编解码 xvid_global(nil, XVID_GBL_INIT, @xvid_gbl, nil); haveinit := true; end; pci := GetCamInfo(mHostName, APort, ACameraID); if pci = nil then begin new(pci); FillChar(pci^, Sizeof(pci^), #0); with pci^ do begin IP := mHostName; Port := APort; LoginName := mLoginName; LoginPwd := mLoginPwd; ChannelID := ACameraID; CallBackChannelID := ACallBackCameraID; ServerName := ''; xVid_decode.version := xvid_Version; xVid_decode.width := 320; xVid_decode.height := 240; end; //创建解码器 xvid_decore(nil, XVID_DEC_CREATE, @(pci^.xVid_decode), nil); pci^.DecHaveCreate := True; FCameraList.Add(pci); end;//----打开服务器 iRet := DVSNET_OpenServer(Pchar(pci^.ServerName), AHostName, APort, ALoginName, ALoginPwd, @(pci^.Serverwnp), 0); if iRet = 0 then begin pci^.OpenCallBackOn := true; if IsDebug then application.MessageBox('登录服务器成功!', '提示', 64); //----打开通道 if not FChannelInfoHaveCreate then begin New(FChannelInfo); fillchar(FChannelInfo^, sizeof(tagDVSNET_CHANNEL_INFO), 0); FChannelInfo^.nProtocol := PROTOCOL_TCP; FChannelInfo^.bPlayStart := 0; end; DVSNET_OpenChannel(pci^.Serverwnp, ACameraID, FChannelInfo, @(pci^.Channelwnp)); DVSNET_RegServerMsgCallback(pci^.Serverwnp, ServerMsgCallback, pointer(pci^.CallBackChannelID)); Settimer(0, 1, 20, @TimerProc); result := true; end;end; //关闭摄像机procedure CloseCamera(ACallBackCameraID: Integer);var pci: PTJLCamInfo;begin pci := GetCamInfoA(ACallBackCameraID); if pci <> nil then begin //----关闭通道号 if pci^.Channelwnp <> 0 then DVSNET_CloseChannel(pci^.Channelwnp); //------注销服务器 if pci^.Serverwnp <> 0 then DVSNET_CloseServer(pci^.Serverwnp); end;end;//设置视频参数(亮度、对比度、饱和度、色度),设置成功就返回True//对于AParamType的定义: 1-亮度 2-对比度 3-饱和度 4-色度function SetVideoParam(ACallBackCameraID: Integer; AParamType: Integer; AParamValue: Integer): Boolean;var pParam: DVSNET_VIDEO_PARAM; pci: PTJLCamInfo; IRet: integer;begin pci := GetCamInfoA(ACallBackCameraID); if pci <> nil then begin if AParamType = 1 then pParam.bBrightness := AParamValue; if AParamType = 2 then pParam.bContrast := AParamValue; if AParamType = 3 then pParam.bSaturation := AParamValue; if AParamType = 4 then pParam.bHue := AParamValue; IRet := DVSNET_SetServerParam(pci^.Serverwnp, SET_VIDEO_ATTR, pci^.ChannelID, pParam, sizeof(pParam)); if IRet = 0 then result := true else result := false; end;end;//获取视频参数(亮度、对比度、饱和度、色度),取参数成功就返回True//对于AParamType的定义: 1-亮度 2-对比度 3-饱和度 4-色度function GetVideoParam(ACallBackCameraID: Integer; AParamType: Integer; AParamValue: PInteger): Boolean;var pParam: DVSNET_VIDEO_PARAM; pci: PTJLCamInfo; IRet: integer;begin pci := GetCamInfoA(ACallBackCameraID); if pci <> nil then begin IRet := DVSNET_GetServerParam(pci^.Serverwnp, GET_VIDEO_ATTR, pci^.ChannelID, pParam, sizeof(pParam)); if AParamType = 1 then AParamValue := @(pParam.bBrightness); if AParamType = 2 then AParamValue := @(pParam.bContrast); if AParamType = 3 then AParamValue := @(pParam.bSaturation); if AParamType = 4 then AParamValue := @(pParam.bHue); if IRet = 0 then result := true else result := false; end;end;//打开或关闭某种数据回调//对于ACallBackType的定义:1-原始视频 2-原始音频 3-压缩视频 4-压缩音频 5-报警事件 6-日志procedure SetCallBackEnable(ACallBackCameraID: Integer; ACallBackType: Integer; AEnable: Boolean);var pci: PTJLCamInfo;begin FAcallBackID := ACallBackCameraID; pci := GetCamInfoA(ACallBackCameraID); if pci <> nil then begin if AEnable and ((ACallBackType = 1) or (ACallBackType = 3)) then begin if (not pci^.FEncCallBackOn) and (not pci^.FRawCallBackOn) then DVSNET_SetNetStreamCallback(pci^.Channelwnp, OnStreamCallback, pci); end; if ACallBackType = 3 then begin if AEnable then pci^.FEncCallBackOn := True else pci^.FEncCallBackOn := False; end; if ACallBackType = 1 then begin if AEnable then pci^.FRawCallBackOn := True else pci^.FRawCallBackOn := False; end; if (not AEnable) and ((ACallBackType = 1) or (ACallBackType = 3)) then begin if (not pci^.FEncCallBackOn) and (not pci^.FRawCallBackOn) then DVSNET_SetNetStreamCallback(pci^.Channelwnp, nil, pci); end; end;end;//云台控制function PtzControl(ACallBackCameraID: Integer; ACommand: Integer; AValue: Integer; AStop: Integer): Boolean;var ptzCmd: DVSNET_PTZ_CMD; dwcmd: Dword;begin {ptzCmd.nCmd := ACommand; ptzCmd.nValue := AValue; DVSNET_GetServerParam(Serverwnp[ACallBackCameraID], dwcmd, Channelcount[ACallBackCameraID], ptzCmd, sizeof(ptzCmd)); if DVSNET_SetServerParam(Serverwnp[ACallBackCameraID], dwcmd, Channelcount[ACallBackCameraID], ptzCmd, sizeof(ptzCmd)) = 0 then result := true else result := false; }end;//多功能备用函数function CustomFunction(AData: Pointer; ALen: Integer): Integer;beginend;end.
 
raised too many consecutive exceptions:'privileged instruction at 0x0013ff64'翻译过来大体是说:抛出了太多的连续异常,在这个地址出使用了特权指令。退出程序时提示:Invalid pointer operation.无效的指针操作。另外,作为stdcall使用时最好使用BOOL代替Boolean。BOOL应该是4字节布尔量,而Boolean是1字节布尔量。在于Windows交互式容易产生隐患。因为没有视频的经验,所以不打算看你的代码,关键是你只能靠别人来帮你分析错误,而不能指望别人来给你调试和推演错误。代码是你的,你自己调试是关键,你自己都对程序的异常毫无概念,别人就更是在猜谜了。要别人帮你,就需要你给出尽可能多和详细的调试信息,系统环境和背景。一般统称系统上下文。
 
看看有什么东东没有释放。
 
IP: string; //IP地址 LoginName: string; //登录名 LoginPwd: string; //登录密码DLL用string就是有问题
 

Similar threads

S
回复
0
查看
895
SUNSTONE的Delphi笔记
S
S
回复
0
查看
873
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
后退
顶部