Dll c++

chowdid Messages postés 1 Date d'inscription lundi 10 mai 2004 Statut Membre Dernière intervention 30 juin 2009 - 30 juin 2009 à 22:01
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 3 juil. 2009 à 00:44
Bonjour, comment interfacer sous delphi cette fonction d'une dll en c++

Code de la dll

typedef enum{
    YUY2=0,
    RGB555,
    RGB24
}ColorSpace;

typedef enum{
    NTSC160X120=0,
    NTSC320X240,
    NTSC640X480,
    NTSC704X480,
    NTSC720X480,
    PAL176X144,
    PAL352X288,
    PAL640X576,
    PAL704X576,
    PAL720X288,
    PAL720X576
}VideoSize;

int IVASDK89_SetDeviceOutputFormat(ColorSpace  pCSType, VideoSize  pVSize);

Merci pour vos réponses.

4 réponses

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
1 juil. 2009 à 08:13
type
  ColorSpace = (
    YUY2 = 0,
    RGB555,
    RGB24
  );

  VideoSize = (
    NTSC160X120 = 0,
    NTSC320X240,
    NTSC640X480,
    NTSC704X480,
    NTSC720X480,
    PAL176X144,
    PAL352X288,
    PAL640X576,
    PAL704X576,
    PAL720X288,
    PAL720X576
  );

function IVASDK89_SetDeviceOutputFormat(
    pCSType: ColorSpace;
    pVSize : VideoSize
  ) : integer;

<hr size="2" width="100%" />
0
Guillemouze Messages postés 991 Date d'inscription samedi 25 octobre 2003 Statut Membre Dernière intervention 29 août 2013 6
1 juil. 2009 à 11:39
pour completer la reponse de foxi, je dirai plutot

{$Z4} // on set à 4 octets
type
  ColorSpace = (
    YUY2 = 0,
    RGB555,
    RGB24
  );

  VideoSize = (
    NTSC160X120 = 0,
    NTSC320X240,
    NTSC640X480,
    NTSC704X480,
    NTSC720X480,
    PAL176X144,
    PAL352X288,
    PAL640X576,
    PAL704X576,
    PAL720X288,
    PAL720X576
  );
{$Z1} //on remet la taille par defaut

function IVASDK89_SetDeviceOutputFormat(
    pCSType: ColorSpace;
    pVSize : VideoSize
  ) : integer;

car il me semble que les enums en C++ sont codés sur 4 octets
0
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
2 juil. 2009 à 11:51
L'union fait la force.

Pour compléter la réponse de Guillemouze, je dirais plutôt :

function IVASDK89_SetDeviceOutputFormat(
    pCSType: ColorSpace;
    pVSize : VideoSize
  ) : integer; cdecl; external 'toto.dll';

Encore que la convention d'appel et la taille des enums peuvent varier en fonction des options de compilation du C++, de pragma...
0
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
3 juil. 2009 à 00:44
oui j'avais pas mis la convention d'appel a cause du fait qu'on ne sait pas si c'est cdecl (convention C) ou stdcall (convention C++ win 32) ...

on pourrait même ajouter, pour faire complet :

Unit Test;

interface

uses Windows, SysUtils;

{.$DEFINE USEENUMSIZE2}
{$DEFINE USECCSTDCALL}
{.$DEFINE USELOCALIMPLEMENT}
{.$DEFINE USESAFEENUM}

{$IFNDEF USESAFEENUM}
  {$IFDEF USEENUMSIZE2}
    {$Z2}
  {$ENDIF}
type
  {$EXTERNALSYM ColorSpace}
  ColorSpace = (
    YUY2   = 0,
    RGB555,
    RGB24
  );

  {$EXTERNALSYM VideoSize}
  VideoSize = (
    NTSC160X120 = 0,
    NTSC320X240,
    NTSC640X480,
    NTSC704X480,
    NTSC720X480,
    PAL176X144,
    PAL352X288,
    PAL640X576,
    PAL704X576,
    PAL720X288,
    PAL720X576
  );
  {$IFDEF USEENUMSIZE4}
    {$Z1}
  {$ENDIF}
{$ELSE}
const
  ColorSpaceYUY2   = 0;
  ColorSpaceRGB555 = 1;
  ColorSpaceRGB24  = 2;
                            // oops :)
  VideoSizeNTSC160X120 = 0; // $0000;
  VideoSizeNTSC320X240 = 1; // $0001;
  VideoSizeNTSC640X480 = 2; // $0002;
  VideoSizeNTSC704X480 = 3; // $0004;
  VideoSizeNTSC720X480 = 4; // $0008;
  VideoSizePAL176X144  = 5; // $0010;
  VideoSizePAL352X288  = 6; // $0020;
  VideoSizePAL640X576  = 7; // $0040;
  VideoSizePAL704X576  = 8; // $0080;
  VideoSizePAL720X288  = 9; // $0100;
  VideoSizePAL720X576  = 10;// $0200;

{$ENDIF}

function IVASetDeviceOutputFormat(pCSType: ColorSpace; pVSize: VideoSize): integer; {$IFDEF USECCSTDCALL}stdcall{$ELSE}cdecl{$ENDIF};

implementation

{$IFNDEF USELOCALIMPLEMENT}
const
  DLLNAME = 'MyLib.dll';

function IVASetDeviceOutputFormat;  external DLLNAME name 'IVASDK89_SetDeviceOutputFormat';

{$ELSE}

function IVASetDeviceOutputFormat(pCSType: ColorSpace; pVSize: VideoSize): integer;
begin
  result := -1;
  { ... todo ... }
end;
{$ENDIF}

end.

<hr size="2" width="100%" />
0
Rejoignez-nous