Einzelnen Beitrag anzeigen

Dawn87

Registriert seit: 15. Feb 2007
Ort: Lüdenscheid
189 Beiträge
 
Delphi XE5 Professional
 
#1

Header Konvertierung: Schutzverletzung bei Funktionsaufruf

  Alt 17. Mär 2010, 17:08
Hallo Zusammen!

Ich bin gerade dabei eine Header-File in C nach Delphi zu übersetzen.

Ich scheitere aber zur Zeit an einem Funktionsaufruf dem ein Record übergeben wird. Ich

erhalte beim Aufruf der Funktion eine Schutzverletzung.

Der Abschnitt in der Header-File sieht wie folgt aus:

Code:
typedef short XLstatus;

typedef struct {                                                                         
  unsigned int busType;
  union {
    struct {
      unsigned int bitRate;
      unsigned char sjw;
      unsigned char tseg1;
      unsigned char tseg2;
      unsigned char sam; // 1 or 3
      unsigned char outputMode;
    }can;
    unsigned char raw[32];
  }data;
} XLbusParams;

// structures for xlGetDriverConfig
typedef struct s_xl_channel_config {
          char               name [XL_MAX_LENGTH + 1];
          unsigned char      hwType;                
          unsigned char      hwIndex;                
          unsigned char      hwChannel;              
          unsigned short     transceiverType;        
          unsigned int       transceiverState;        
          unsigned char      channelIndex;            
          XLuint64            channelMask;            
          unsigned int       channelCapabilities;
          unsigned int       channelBusCapabilities;  
                             
          // Channel        
          unsigned char      isOnBus;                
          unsigned int       connectedBusType;            
          XLbusParams        busParams;              
                                                       
          unsigned int       driverVersion;          
          unsigned int       interfaceVersion;      
          unsigned int       raw_data[10];
                             
          unsigned int       serialNumber;
          unsigned int       articleNumber;
                             
          char               transceiverName [XL_MAX_LENGTH + 1];
                             
          unsigned int       specialCabFlags;          
          unsigned int       dominantTimeout;          
          unsigned char      dominantRecessiveDelay;  
          unsigned char      recessiveDominantDelay;  
          unsigned char      connectionInfo;          
          unsigned char      reserved01;
          unsigned int       reserved[7];
        } XL_CHANNEL_CONFIG;

typedef struct s_xl_driver_config {
          unsigned int     dllVersion;
          unsigned int     channelCount; // total number of channels
          unsigned int     reserved[10];
          XLchannelConfig  channel[XL_CONFIG_MAX_CHANNELS];   // [channelCount]
        } XL_DRIVER_CONFIG;

typedef XL_CHANNEL_CONFIG XLchannelConfig;
typedef XL_CHANNEL_CONFIG *pXLchannelConfig;

DECL_STDXL_FUNC( xlGetDriverConfig, XLGETDRIVERCONFIG, (XLdriverConfig *pDriverConfig));
// XLstatus xlGetDriverConfig(XLdriverConfig *pDriverConfig);
Den Abschnitt der Header-File habe ich wie folgt übersetzt:

Delphi-Quellcode:

  type
    TXLBUsParams = packed record
      busType: Word;
      case Integer of
        0: (bitRate: Word;
            sjw: Char;
            tseg1: Char;
            tseg2: Char;
            sam: Char;
            outputMode: Char);

        1: (raw: array[0..31] of char);
  end;

  type
    TXLChannelConfig = packed record
      name: array[0..XL_MAX_LENGTH] of Char;
      hwType: Char;
      hwIndex: Char;
      hwChannel: Char;
      transceiverType: Smallint;
      transceiverState: Word;
      channelIndex: Char;
      channelMask: XLuint64;
      channelCapabilities: Word;
      // Channel
      isOnBus: Char;
      connectedBusType: Word;
      busParams: TXLbusParams;
      driverVersion: Word;
      interfaceVersion: Word;
      raw_data: array[0..9] of Word;
      serialNumber: Word;
      articleNumber: Word;
      transceiverName: array[0..XL_MAX_LENGTH] of char;
      specialCabFlags: Word;
      dominantTimeout: Word;
      dominantRecessiveDelay: Char;
      recessiveDominantDelay: Char;
      connectionInfo: Char;
      reserved01: Char;
      reserved: array[0..6] of Word;
  end;

  type TXLDriverConfig = packed record
    dllVersion: Word;
    channelCount: Word;
    reserved: array[0..9] of Word;
    XLChannelConfig: array[0..XL_CONFIG_MAX_CHANNELS -1] of TXLChannelConfig;
  end;

  type TXLstatus = Integer;

  function xlGetDriverConfig(XLDriverConfig: TXLDriverConfig): TXLStatus; cdecl;

  // ....

  function xlGetDriverConfig; external XLDriverDLL name 'xlGetDriverConfig'; cdecl;
Ich rufe die Funktion in der eingebundenen Unit wie folgt auf:

Delphi-Quellcode:
var
  hStatus: TxlStatus;
  DrvConf: TXLDriverConfig;
begin
  hStatus := xlOpenDriver();

  if hStatus = XL_SUCCESS then // zero means success
  begin
    hStatus := xlGetDriverConfig(DrvConf); // <-- Schutzverletzung

    ShowMessage('DLLVersion: ' + IntToStr(DrvConf.dllVersion));

    xlCloseDriver();
  end
  else
  begin
    ShowMessage('Treiber konnte nicht geladen werden.');
  end;
end;
Da ich sehr unerfahren in der Konvertierung solcher Header-Files bin erkenn ich einfach nicht was ich falsch mache. Hat da wer einen Tipp oder sieht möglicherweise was ich falsch gemacht habe?

Ich möchte der Funktion xlGetDriverConfig einen Record übergeben. Dieser Record soll dann von der Funktion mit einigen Daten die später benötigt werden gefüllt werden.

Grüße
  Mit Zitat antworten Zitat