tags:

views:

243

answers:

4

I need help with converting c++ header file to delphi. I spent several days on this problem without success.

Below is the original header file and my Delphi translation.

C++ header

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifdef DVP7010BDLL_EXPORTS
#define DVP7010BDLL_API __declspec(dllexport)
#else
#define DVP7010BDLL_API __declspec(dllimport)
#endif

#define MAXBOARDS 4
#define MAXDEVS 4
#define ID_NEW_FRAME 37810
#define ID_MUX0_NEW_FRAME 37800
#define ID_MUX1_NEW_FRAME 37801
#define ID_MUX2_NEW_FRAME 37802
#define ID_MUX3_NEW_FRAME 37803

typedef enum
{
    SUCCEEDED       = 1,
    FAILED          = 0,
    SDKINITFAILED   = -1,
    PARAMERROR      = -2,
    NODEVICES       = -3,
    NOSAMPLE        = -4,
    DEVICENUMERROR  = -5,
    INPUTERROR      = -6,
//  VERIFYHWERROR   = -7
} Res;

typedef enum tagAnalogVideoFormat 
{
    Video_None       = 0x00000000,
    Video_NTSC_M     = 0x00000001, 
    Video_NTSC_M_J   = 0x00000002,  
    Video_PAL_B      = 0x00000010,
    Video_PAL_M      = 0x00000200,
    Video_PAL_N      = 0x00000400,
    Video_SECAM_B    = 0x00001000
} AnalogVideoFormat;

typedef enum 
{
    SIZEFULLPAL=0,
    SIZED1,
    SIZEVGA,
    SIZEQVGA,
    SIZESUBQVGA
} VideoSize;

typedef enum
{
    STOPPED         = 1,
    RUNNING         = 2,
    UNINITIALIZED   = -1,
    UNKNOWNSTATE    = -2
} CapState;

class IDVP7010BDLL 
{
public:
    int AdvDVP_CreateSDKInstence(void **pp);
    virtual int AdvDVP_InitSDK() PURE;
    virtual int AdvDVP_CloseSDK() PURE;
    virtual int AdvDVP_GetNoOfDevices(int *pNoOfDevs) PURE;
    virtual int AdvDVP_Start(int nDevNum, int SwitchingChans, HWND Main, HWND hwndPreview) PURE;
    virtual int AdvDVP_Stop(int nDevNum) PURE;
    virtual int AdvDVP_GetCapState(int nDevNum) PURE;
    virtual int AdvDVP_IsVideoPresent(int nDevNum, BOOL* VPresent) PURE;
    virtual int AdvDVP_GetCurFrameBuffer(int nDevNum, int VMux, long* bufSize, BYTE* buf) PURE; 
    virtual int AdvDVP_SetNewFrameCallback(int nDevNum, int callback) PURE;
    virtual int AdvDVP_GetVideoFormat(int nDevNum, AnalogVideoFormat* vFormat) PURE;
    virtual int AdvDVP_SetVideoFormat(int nDevNum, AnalogVideoFormat vFormat) PURE;
    virtual int AdvDVP_GetFrameRate(int nDevNum, int *nFrameRate) PURE;
    virtual int AdvDVP_SetFrameRate(int nDevNum, int SwitchingChans, int nFrameRate) PURE;
    virtual int AdvDVP_GetResolution(int nDevNum, VideoSize *Size) PURE; 
    virtual int AdvDVP_SetResolution(int nDevNum, VideoSize Size) PURE; 
    virtual int AdvDVP_GetVideoInput(int nDevNum, int* input) PURE;
    virtual int AdvDVP_SetVideoInput(int nDevNum, int input) PURE;
    virtual int AdvDVP_GetBrightness(int nDevNum, int input, long *pnValue) PURE;
    virtual int AdvDVP_SetBrightness(int nDevNum, int input, long nValue) PURE;
    virtual int AdvDVP_GetContrast(int nDevNum, int input, long *pnValue) PURE;
    virtual int AdvDVP_SetContrast(int nDevNum, int input, long nValue) PURE;
    virtual int AdvDVP_GetHue(int nDevNum, int input, long *pnValue) PURE;
    virtual int AdvDVP_SetHue(int nDevNum, int input, long nValue) PURE;
    virtual int AdvDVP_GetSaturation(int nDevNum, int input, long *pnValue) PURE;
    virtual int AdvDVP_SetSaturation(int nDevNum, int input, long nValue) PURE;
    virtual int AdvDVP_GPIOGetData(int nDevNum, int DINum, BOOL* value) PURE;
    virtual int AdvDVP_GPIOSetData(int nDevNum, int DONum, BOOL value) PURE;
};

Delphi

    unit IDVP7010BDLL_h;

interface

uses
    Windows, Messages, SysUtils, Classes;

//{$if _MSC_VER > 1000}
//pragma once
//{$endif} // _MSC_VER > 1000

{$ifdef DVP7010BDLL_EXPORTS}
//const DVP7010BDLL_API =  __declspec(dllexport);
{$else}
//const DVP7010BDLL_API =  __declspec(dllimport);
{$endif}

const
   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, SIZED1, SIZEVGA, SIZEQVGA, SIZESUBQVGA);
   PVideoSize = ^TVideoSize;
   P_Pointer = ^Pointer;

   TIDVP7010BDLL = class
      function AdvDVP_CreateSDKInstence(pp: P_Pointer): integer; virtual; stdcall; abstract;
      function AdvDVP_InitSDK():Integer; virtual; stdcall; abstract;
      function AdvDVP_CloseSDK():Integer; virtual; stdcall; abstract;
      function AdvDVP_GetNoOfDevices(pNoOfDevs : PInteger) :Integer; virtual; stdcall; abstract;
      function AdvDVP_Start(nDevNum : Integer; SwitchingChans : Integer; Main : HWND; hwndPreview: HWND ) :Integer; virtual; stdcall; abstract;
      function AdvDVP_Stop(nDevNum : Integer ):Integer; virtual; stdcall; abstract;
      function AdvDVP_GetCapState(nDevNum : Integer ):Integer; virtual; stdcall; abstract;
      function AdvDVP_IsVideoPresent(nDevNum : Integer;  VPresent : PBool) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetCurFrameBuffer(nDevNum : Integer; VMux : Integer;  bufSize : PLongInt; buf : PByte) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetNewFrameCallback(nDevNum : Integer; callback : Integer ) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetVideoFormat(nDevNum : Integer; vFormat : PAnalogVideoFormat) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetVideoFormat(nDevNum : Integer; vFormat : TAnalogVideoFormat ) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetFrameRate(nDevNum : Integer; nFrameRate : Integer) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetFrameRate(nDevNum : Integer; SwitchingChans : Integer; nFrameRate : Integer) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetResolution(nDevNum : Integer; Size : PVideoSize) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetResolution(nDevNum : Integer;  Size : TVideoSize ) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetVideoInput(nDevNum : Integer;  input : PInteger) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetVideoInput(nDevNum : Integer;  input : Integer) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetBrightness(nDevNum : Integer;  input: Integer; pnValue : PLongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetBrightness(nDevNum : Integer;  input: Integer; nValue : LongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetContrast(nDevNum : Integer;  input: Integer; pnValue : PLongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetContrast(nDevNum : Integer;  input: Integer; nValue : LongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetHue(nDevNum : Integer; input: Integer; pnValue : PLongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetHue(nDevNum : Integer; input: Integer; nValue : LongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GetSaturation(nDevNum : Integer;  input: Integer; pnValue : PLongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_SetSaturation(nDevNum : Integer;  input: Integer; nValue : LongInt) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GPIOGetData(nDevNum : Integer;  DINum:Integer;  value : PBool) :Integer; virtual; stdcall; abstract;
      function AdvDVP_GPIOSetData(nDevNum : Integer;  DONum:Integer; value : Boolean) :Integer; virtual; stdcall; abstract;
   end;

   function IDVP7010BDLL : TIDVP7010BDLL ; stdcall;


implementation


function IDVP7010BDLL; external 'DVP7010B.dll';

end.
+1  A: 

Well, the first thing I notice is that you're trying to convert a C++ class into a Delphi class. You can't do that. The object models are very different. Delphi is going to make certain assumptions about the way the object is laid out, and especially about the way the object's VMT is laid out, that are only valid for Delphi, not for C++.

What you need is either a non-object-oriented interface (plain C) or a COM object.

Mason Wheeler
I need to connect witn Advantech DVP7010B video card (http://www.advantech.com/products/DVP-7010BE/mod_1-2JKF46.aspx). This card has samples only for C++. I do not know how to use dll for this card with Delphi. I read a lot about making translation dll header file to delphi but my result onlu get Access Violation. Could anybody help me what I must do to get proper file?
C++ Classes do not cross DLL boundaries (Portably anyway). You need to lookup the C API to use that DLL.
Billy ONeal
Does this mean that there is no possibility to use this card in Delphi? Manufacturer provides only the header file as above.
@grzegorz1 - I suspect that it CAN work, but whether it WILL work depends on whether the vendor will cooperate with you. I agree with @BillyONeal, they should provide a native C header. As a seemingly unnecessary work-around, you could write a "shim" wrapper in C++, which exposes a more paletable API.
Chris Thornton
Thank you for your help. Unfortunately, I do not know enough C++ to deal with this problem. Anyway I wish you all a good night (I go to sleep) or a nice day.
+1  A: 

Apparently AdvDVP_CreateSDKInstence does some Magic(tm) to create a VMT that is then used to dispatch the virtual function calls.

You should leave behind the c++ header file and program directly to the DLL, wrapping them in a Delphi class if you wish. There are tons of tutorials out there that you can pick from, for starters, try this one. It also shows how to create enums in Delphi, and it has a handy little tool to create a unit from the functions the DLL exports.

Ozan
I read this totorial and many more but I don't know how to solve problem. I tried solve problem with help from Rudy's Delphi Corner (Using C++ objects in Delphi) but without success. Could you give me few sample lines ?
@grzegorz1: Please edit your question and post the unit you have after following one of those tutorials, and the error you get when compiling or running it.
Ozan
+2  A: 

I agree with Mason you should not use a class (at least at the beginning when you are building the wrapper and testing it)
the first objective here is to have calls to the library functions working.

so try like this :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  public
    procedure DisplayStatus(r:integer);
  end;

  Function AdvDVP_InitSDK():Integer ; stdcall;  external 'DVP7010B.dll';

var
  Form1: TForm1;
  DVP_DLL_Handle:THandle;

const
   SUCCEEDED = 1;
   FAILED = 0;
   SDKINITFAILED = -1;
   PARAMERROR = -2;
   NODEVICES = -3;
   NOSAMPLE = -4;
   DEVICENUMERROR = -5;
   INPUTERROR = -6;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var r:integer;
begin
   if DVP_DLL_Handle <>0 then begin
       r := AdvDVP_InitSDK();
       DisplayStatus(r);
   end else begin
     showmessage('error loading library');
   end;
end;

procedure TForm1.DisplayStatus(r: integer);
begin
   case r of
     SUCCEEDED:showmessage('SUCCEEDED');
     FAILED:showmessage('FAILED');
     SDKINITFAILED:showmessage('SDKINITFAILED');
     PARAMERROR:showmessage('PARAMERROR');
     NODEVICES:showmessage('NODEVICES');
     NOSAMPLE:showmessage('NOSAMPLE');
     DEVICENUMERROR:showmessage('DEVICENUMERROR');
     INPUTERROR:showmessage('INPUTERROR');
   end;
end;

initialization
  DVP_DLL_Handle:=LoadLibrary('DVP7010B.dll');

finalization
  if DVP_DLL_Handle <>0 then begin
     FreeLibrary(DVP_DLL_Handle);
  end;

end.

it's an incomplete conversion, and I put all into one single unit...

but I downloaded the SDK and tried it : it works : i get 'NODEVICES' when i push the button.

DamienD
Unfortunately your solution not working with real card. Function AdvDVP_InitSDK causes Access Violation. Thank you for help.
you should check dll dependencies...just an example : in the past I had similar problems playing with Delphi and SketchupReader.dll (access violations) because this dll in fact need Microsoft Visual C++ 2005 Redistributable Package to be installed.
DamienD
A: 
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.

Test code:

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;

Why it will not work with Delphi: An empty Delphi 2009 class has 8 bytes (see http://blogs.teamb.com/craigstuntz/2009/03/25/38138/ for more info) and so AdvDVP_InitSDK & AdvDVP_CloseSDK offset get eaten and bug the rest functions and my guess it also bug the class itself.

Take a look at Local Variables while debugging:

  • pDVPSDK $1C71100
  • +AdvDVP_InitSDK ($10001253,$1000123A)
  • +AdvDVP_CloseSDK ($1000101E,$10001285)
  • +AdvDVP_GetNoOfDevices ($100011D1,$1000112C)
  • +....

And from IDA:

.text:10001253 public AdvDVP_GetNoOfDevices

AdvDVP_InitSDK points to TAdvDVP_GetNoOfDevices !!!

Try this if you have a card yourself:

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;

I don't know if events need a different calling conversion other than stdcall, but you can try with cdecl and others depending of what data you get from the functions.

Good luck.

pani
Unfortunately, despite your help, we still have no success. Calling a function "AdvDVP_InitSDK" generate Access Violation. Last night I tried connect card with TVideoGrabber component - it works perfectly - so probably I give up fight. Once again, thank you very much for help.