unit IDVP7010BDLL_h;
interface
uses
Windows;
const
DVP7010B = 'DVP7010B.dll';
MAXBOARDS = 4;
MAXDEVS = 4;
MAXMUXS = 4;
ID_NEW_FRAME = 37810;
ID_MUX0_NEW_FRAME = 37800;
ID_MUX1_NEW_FRAME = 37801;
ID_MUX2_NEW_FRAME = 37802;
ID_MUX3_NEW_FRAME = 37803;
// TRec
SUCCEEDED = 1;
FAILED = 0;
SDKINITFAILED = -1;
PARAMERROR = -2;
NODEVICES = -3;
NOSAMPLE = -4;
DEVICENUMERROR = -5;
INPUTERROR = -6;
// TRec
// TAnalogVideoFormat
Video_None = $00000000;
Video_NTSC_M = $00000001;
Video_NTSC_M_J = $00000002;
Video_PAL_B = $00000010;
Video_PAL_M = $00000200;
Video_PAL_N = $00000400;
Video_SECAM_B = $00001000;
// TAnalogVideoFormat
// TCapState
STOPPED = 1;
RUNNING = 2;
UNINITIALIZED = -1;
UNKNOWNSTATE = -2;
// TCapState
type
TCapState = Longint;
TRes = Longint;
TtagAnalogVideoFormat = DWORD;
TAnalogVideoFormat = TtagAnalogVideoFormat;
PAnalogVideoFormat = ^TAnalogVideoFormat;
TVideoSize = (SIZEFULLPAL = 0, SIZED1, SIZEVGA, SIZEQVGA, SIZESUBQVGA);
PVideoSize = ^TVideoSize;
P_Pointer = ^Pointer;
//TAdvDVP_CreateSDKInstence = function(var p: PIDVP7010BDLL): Integer of object; stdcall; // not needed in class
TAdvDVP_InitSDK = function(): Integer of object; stdcall;
TAdvDVP_CloseSDK = function(): Integer of object; stdcall;
TAdvDVP_GetNoOfDevices = function(var pNoOfDevs: Integer): Integer of object; stdcall;
TAdvDVP_Start = function(nDevNum: Integer; SwitchingChans: Integer; Main: HWND; hwndPreview: HWND): Integer of object; stdcall;
TAdvDVP_Stop = function(nDevNum: Integer): Integer of object; stdcall;
TAdvDVP_GetCapState = function(nDevNum: Integer): Integer of object; stdcall;
TAdvDVP_IsVideoPresent = function(nDevNum: Integer; var VPresent: Bool): Integer of object; stdcall;
TAdvDVP_GetCurFrameBuffer = function(nDevNum: Integer; VMux: Integer; var bufSize: LongInt; buf: PByte): Integer of object; stdcall;
TAdvDVP_SetNewFrameCallback = function(nDevNum: Integer; callback: Integer): Integer of object; stdcall;
TAdvDVP_GetVideoFormat = function(nDevNum: Integer; var vFormat: TAnalogVideoFormat): Integer of object; stdcall;
TAdvDVP_SetVideoFormat = function(nDevNum: Integer; vFormat: TAnalogVideoFormat): Integer of object; stdcall;
TAdvDVP_GetFrameRate = function(nDevNum: Integer; nFrameRate: Integer): Integer of object; stdcall;
TAdvDVP_SetFrameRate = function(nDevNum: Integer; SwitchingChans: Integer; nFrameRate: Integer): Integer of object; stdcall;
TAdvDVP_GetResolution = function(nDevNum: Integer; var Size: TVideoSize): Integer of object; stdcall;
TAdvDVP_SetResolution = function(nDevNum: Integer; Size: TVideoSize): Integer of object; stdcall;
TAdvDVP_GetVideoInput = function(nDevNum: Integer; var input: Integer): Integer of object; stdcall;
TAdvDVP_SetVideoInput = function(nDevNum: Integer; input: Integer): Integer of object; stdcall;
TAdvDVP_GetBrightness = function(nDevNum: Integer; input: Integer; var pnValue: LongInt) :Integer of object; stdcall;
TAdvDVP_SetBrightness = function(nDevNum: Integer; input: Integer; nValue: LongInt) :Integer of object; stdcall;
TAdvDVP_GetContrast = function(nDevNum: Integer; input: Integer; var pnValue: LongInt) :Integer of object; stdcall;
TAdvDVP_SetContrast = function(nDevNum: Integer; input: Integer; nValue: LongInt) :Integer of object; stdcall;
TAdvDVP_GetHue = function(nDevNum: Integer; input: Integer; var pnValue: LongInt) :Integer of object; stdcall;
TAdvDVP_SetHue = function(nDevNum: Integer; input: Integer; nValue: LongInt) :Integer of object; stdcall;
TAdvDVP_GetSaturation = function(nDevNum: Integer; input: Integer; var pnValue: LongInt) :Integer of object; stdcall;
TAdvDVP_SetSaturation = function(nDevNum: Integer; input: Integer; nValue: LongInt) :Integer of object; stdcall;
TAdvDVP_GPIOGetData = function(nDevNum: Integer; DINum: Integer; var value: Bool): Integer of object; stdcall;
TAdvDVP_GPIOSetData = function(nDevNum: Integer; DONum: Integer; value: Boolean): Integer of object; stdcall;
TIDVP7010BDLL = class
public
//AdvDVP_CreateSDKInstence: TAdvDVP_CreateSDKInstence; // not needed in class
AdvDVP_InitSDK: TAdvDVP_InitSDK;
AdvDVP_CloseSDK: TAdvDVP_CloseSDK;
AdvDVP_GetNoOfDevices: TAdvDVP_GetNoOfDevices;
AdvDVP_Start: TAdvDVP_Start;
AdvDVP_Stop: TAdvDVP_Stop;
AdvDVP_GetCapState: TAdvDVP_GetCapState;
AdvDVP_IsVideoPresent: TAdvDVP_IsVideoPresent;
AdvDVP_GetCurFrameBuffer: TAdvDVP_GetCurFrameBuffer;
AdvDVP_SetNewFrameCallback: TAdvDVP_SetNewFrameCallback;
AdvDVP_GetVideoFormat: TAdvDVP_GetVideoFormat;
AdvDVP_SetVideoFormat: TAdvDVP_SetVideoFormat;
AdvDVP_GetFrameRate: TAdvDVP_GetFrameRate;
AdvDVP_SetFrameRate: TAdvDVP_SetFrameRate;
AdvDVP_GetResolution: TAdvDVP_GetResolution;
AdvDVP_SetResolution: TAdvDVP_SetResolution;
AdvDVP_GetVideoInput: TAdvDVP_GetVideoInput;
AdvDVP_SetVideoInput: TAdvDVP_SetVideoInput;
AdvDVP_GetBrightness: TAdvDVP_GetBrightness;
AdvDVP_SetBrightness: TAdvDVP_SetBrightness;
AdvDVP_GetContrast: TAdvDVP_GetContrast;
AdvDVP_SetContrast: TAdvDVP_SetContrast;
AdvDVP_GetHue: TAdvDVP_GetHue;
AdvDVP_SetHue: TAdvDVP_SetHue;
AdvDVP_GetSaturation: TAdvDVP_GetSaturation;
AdvDVP_SetSaturation: TAdvDVP_SetSaturation;
AdvDVP_GPIOGetData: TAdvDVP_GPIOGetData;
AdvDVP_GPIOSetData: TAdvDVP_GPIOSetData;
constructor Create; // For method 2
end;
PIDVP7010BDLL = ^TIDVP7010BDLL;
PPIDVP7010BDLL = ^PIDVP7010BDLL;
TIAdvDVP_CreateSDKInstence = function(var p: PIDVP7010BDLL): Integer; stdcall;
var
hDVP7010B: THandle;
IAdvDVP_CreateSDKInstence: TIAdvDVP_CreateSDKInstence;
implementation
{ TIDVP7010BDLL }
constructor TIDVP7010BDLL.Create;
begin
if hDVP7010B <> 0 then
begin
//@IAdvDVP_CreateSDKInstence := GetProcAddress(hDVP7010B, 'AdvDVP_CreateSDKInstence'); // not needed
@AdvDVP_InitSDK := GetProcAddress(hDVP7010B, 'AdvDVP_InitSDK');
@AdvDVP_CloseSDK := GetProcAddress(hDVP7010B, 'AdvDVP_CloseSDK');
@AdvDVP_GetNoOfDevices := GetProcAddress(hDVP7010B, 'AdvDVP_GetNoOfDevices');
@AdvDVP_Start := GetProcAddress(hDVP7010B, 'AdvDVP_Start');
@AdvDVP_Stop := GetProcAddress(hDVP7010B, 'AdvDVP_Stop');
@AdvDVP_GetCapState := GetProcAddress(hDVP7010B, 'AdvDVP_GetCapState');
@AdvDVP_IsVideoPresent := GetProcAddress(hDVP7010B, 'AdvDVP_IsVideoPresent');
@AdvDVP_GetCurFrameBuffer := GetProcAddress(hDVP7010B, 'AdvDVP_GetCurFrameBuffer');
@AdvDVP_SetNewFrameCallback := GetProcAddress(hDVP7010B, 'AdvDVP_SetNewFrameCallback');
@AdvDVP_GetVideoFormat := GetProcAddress(hDVP7010B, 'AdvDVP_GetVideoFormat');
@AdvDVP_SetVideoFormat := GetProcAddress(hDVP7010B, 'AdvDVP_SetVideoFormat');
@AdvDVP_GetFrameRate := GetProcAddress(hDVP7010B, 'AdvDVP_GetFrameRate');
@AdvDVP_SetFrameRate := GetProcAddress(hDVP7010B, 'AdvDVP_SetFrameRate');
@AdvDVP_GetResolution := GetProcAddress(hDVP7010B, 'AdvDVP_GetResolution');
@AdvDVP_SetResolution := GetProcAddress(hDVP7010B, 'AdvDVP_SetResolution');
@AdvDVP_GetVideoInput := GetProcAddress(hDVP7010B, 'AdvDVP_GetVideoInput');
@AdvDVP_SetVideoInput := GetProcAddress(hDVP7010B, 'AdvDVP_SetVideoInput');
@AdvDVP_GetBrightness := GetProcAddress(hDVP7010B, 'AdvDVP_GetBrightness');
@AdvDVP_SetBrightness := GetProcAddress(hDVP7010B, 'AdvDVP_SetBrightness');
@AdvDVP_GetContrast := GetProcAddress(hDVP7010B, 'AdvDVP_GetContrast');
@AdvDVP_SetContrast := GetProcAddress(hDVP7010B, 'AdvDVP_SetContrast');
@AdvDVP_GetHue := GetProcAddress(hDVP7010B, 'AdvDVP_GetHue');
@AdvDVP_SetHue := GetProcAddress(hDVP7010B, 'AdvDVP_SetHue');
@AdvDVP_GetSaturation := GetProcAddress(hDVP7010B, 'AdvDVP_GetSaturation');
@AdvDVP_SetSaturation := GetProcAddress(hDVP7010B, 'AdvDVP_SetSaturation');
@AdvDVP_GPIOGetData := GetProcAddress(hDVP7010B, 'AdvDVP_GPIOGetData');
@AdvDVP_GPIOSetData := GetProcAddress(hDVP7010B, 'AdvDVP_GPIOSetData');
end
else
MessageBox(0, 'DVP7010B.dll not found!', 'Error', MB_ICONERROR);
end;
initialization
hDVP7010B := LoadLibrary(DVP7010B);
// For method 1
if hDVP7010B <> 0 then
begin
@IAdvDVP_CreateSDKInstence := GetProcAddress(hDVP7010B, 'AdvDVP_CreateSDKInstence');
if @IAdvDVP_CreateSDKInstence = nil then
MessageBox(0, 'AdvDVP_CreateSDKInstence not found in DVP7010B.dll', 'Error', MB_ICONERROR);
end
else
MessageBox(0, 'DVP7010B.dll not found!', 'Error', MB_ICONERROR);
finalization
FreeLibrary(hDVP7010B);
end.
Тестовый код:
procedure TForm8.Button1Click(Sender: TObject);
var
pDVPSDK: PIDVP7010BDLL;
res: Integer;
begin
// Method 1
pDVPSDK := nil;
res := IAdvDVP_CreateSDKInstence(pDVPSDK);
if not (res = SUCCEEDED) then
begin
Application.MessageBox('AdvDVP_CreateSDKInstence error!', 'Error', MB_ICONERROR);
end
else
begin
Application.MessageBox('AdvDVP_CreateSDKInstence will not work for this!!!', 'Error', MB_ICONERROR);
end;
end;
Почему это не будет работать с Delphi:
Пустой класс Delphi 2009 имеет 8 байтов (см. http://blogs.teamb.com/craigstuntz/2009/03/25/38138/ для получения дополнительной информации), и поэтому смещение AdvDVP_InitSDK и AdvDVP_CloseSDK сгорает и вызывает ошибки в остальных функциях, и я полагаю, что оно также содержит ошибку самого класса.
Посмотрите на локальные переменные при отладке:
- pDVPSDK $ 1C71100
- + AdvDVP_InitSDK ( 10001253 , 1000123A)
- + AdvDVP_CloseSDK (1000101E, 10001285)
- + AdvDVP_GetNoOfDevices ($ 100011D1, $ 1000112C)
- + ....
А из МАР:
.text: 10001253 public AdvDVP_GetNoOfDevices
AdvDVP_InitSDK указывает на TAdvDVP_GetNoOfDevices !!!
Попробуйте, если у вас есть карточка самостоятельно:
procedure TForm8.Button2Click(Sender: TObject);
var
DVPSDK: TIDVP7010BDLL;
res: Integer;
nDevCount: Integer;
i: Integer;
begin
// Method 2
DVPSDK := TIDVP7010BDLL.Create;
try
res := DVPSDK.AdvDVP_InitSDK;
if res = SUCCEEDED then
begin
if not (DVPSDK.AdvDVP_GetNoOfDevices(nDevCount) = SUCCEEDED) then
Exit;
if (nDevCount > MAXBOARDS*MAXDEVS) then
Exit;
for i := 0 to nDevCount - 1 do
begin
m_DevNum.Items.Add(Format('Device_%d', [i])); // TComboBox
end;
end
else
begin
case res of
FAILED: Application.MessageBox('SDK function failed!', 'Error', MB_ICONERROR);
SDKINITFAILED: Application.MessageBox('SDK initiation failed!', 'Error', MB_ICONERROR);
PARAMERROR: Application.MessageBox('Number of the devices out of the range!', 'Error', MB_ICONERROR);
NODEVICES: Application.MessageBox('No device be found!', 'Error', MB_ICONERROR);
end;
end;
finally
DVPSDK.Free;
end;
end;
Я не знаю, нужно ли для событий другое преобразование вызова, кроме stdcall, но вы можете попробовать использовать cdecl и другие в зависимости от того, какие данные вы получаете от функций.
Удачи.