Einzelnen Beitrag anzeigen

Pow3rus3r

Registriert seit: 17. Apr 2012
43 Beiträge
 
Delphi XE Professional
 
#7

AW: Fehler "access violation" - keine Ahnung, warum...

  Alt 14. Aug 2012, 13:23
Dieser Thread hat einen Vorgänger: c DLL in Delphi einbinden (Prozedureinsprungspunkt nicht gefunden)

Also ganz offensichtlich befüllst du nicht alle Member des Records Manipulationtag.
Dadurch können die nicht-befüllten Member zufällige Werte annehmen, was dann zu einem Fehler in der DLL führen kann.
Doch, das Record "Manipulationtag" hat sich mittlerweile geändert. Ich habe den Code nun mal aufs wesentliche zusammengestaucht und nur die beteiligten Funktionen rausgesucht.

Hier ist quasi das komplette projekt drin und der Fehler tritt auch hier auf:

Delphi-Quellcode:
unit Unit1;

interface

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

 type
  Manipulationtag = record
    TriggerType: byte; ///< Trigger 1: Identify whether the TriggerValue is an address or a value (0: trigger not active; 1: trigger at value; 2: trigger at address; 3: trigger at value cyclic; 4: trigger at address cyclic)
    TriggerMode: byte; ///< Trigger 1: Identify the trigger mode (1: '=='; 2: '!='; 3: '>'; 4: '<'; 5: '<='; 6: '>='; 7: 'edge')
    TriggerSource: longword; ///< Trigger 1: The trigger source is the signal which value is used to trigger
    TriggerValue: longword; ///< Trigger 1: The trigger value to compare with the trigger source value
    TriggerHysterese: longword; ///< Trigger 1: Trigger hysteresis identify the hysteresis at trigger mode "edge"
    DelayValue: word; ///< Delay to start the manipulation
    DelayType: byte; ///< The delay value type (0: events since sequence start; 1: cycles since sequence start; 2: ms since sequence start; 3: events since last manipulation; 4: cycles since last manipulation; 5: ms since last manipulation)
    SequenceNumber: byte; ///< Identify the position of this manipulation in a sequence. For trigger manipulations the sequence number is '0'
    ManipulationType: byte; ///< Identify the manipulation type (1: loss; 2: offset; 3: value; 4: factor; 5: drift - from n to m in p steps ; 6: ramp - from n to m in p steps ; 7: disable manipulation; 8: freeze; 9: ramp with hold final value - from n to m in p steps; 10: drift with hold final value - from n to m in p steps; 11: factor linear; 12: offset negative)
    ManipulationDuration: word; ///< Identify the duration of a manipulation (0 means infinite duration)
    ManipulationDurationType: byte; ///< Identify the unit of the duration (0: duration is given in events; 1: duration is given in cycles; 1: duration is given in ms)
    ManipulationMode: byte; ///< Identify the manipulation target type (1: frame; 2: PDU; 3: signal group; 4: signal; 5: ECU)
    ManipulationTarget: longword; ///< Identify the address or identifier of the element to manipulate
    ManipulationTargetValue: word; ///< Sets a parameter for the manipulated target (e.g. ecu index number )
    ManipulationValue1: longword; ///< The value one of the manipulation (n)
    ManipulationValue2: longword; ///< The value two of the manipulation (m)
    ManipulationSteps: word; ///< The value three of the manipulation (p)
  end;

type
  TForm1 = class(TForm)
    btnconnect: TButton;
    btndisconnect: TButton;
    btngetversion: TButton;
    lblstatus: TLabel;
    btnclose: TButton;
    btnstartmanipulation: TButton;
    btnstopmanipulation: TButton;
    btnchangemanipulation: TButton;
    txtvalue: TEdit;
    btnreadfile: TButton;
    Button1: TButton;
    procedure btnconnectClick(Sender: TObject);
    procedure btndisconnectClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnstartmanipulationClick(Sender: TObject);
    procedure btnstopmanipulationClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
  var
    { Public-Deklarationen }
    zeiger:Pointer;
    return:NativeUInt;
    ipAddress:ANSIString;
    port:smallint;
    tagmanipulation: Manipulationtag;
    tagmanipulation2: Manipulationtag;
    boolconnected: boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function COM_TcpOpen(var zeiger:Pointer; ipAddress:AnsiString; port:smallint): NativeUInt; stdcall; external 'HwCom.dll';
function COM_Close(zeiger:Pointer):NativeUInt; stdcall; external 'HwCom.dll';
function COM_RbsManipulationReq(zeiger:Pointer; manipulation:Manipulationtag): NativeUInt; stdcall; external 'HwCom.dllname '_COM_RbsManipulationReq@112';
function COM_StartRbsManipulationReq(zeiger:Pointer): NativeUInt; stdcall; external 'HwCom.dllname '_COM_StartRbsManipulationReq@4';
function COM_StopRbsManipulationReq(zeiger:Pointer): NativeUInt; stdcall; external 'HwCom.dllname '_COM_StopRbsManipulationReq@4';

{ Programmstart: Variablen initialisieren }
procedure TForm1.FormCreate(Sender: TObject);
  begin
     lblstatus.Caption := '';
     ipAddress:='192.168.1.15';
     port := 1500;
     new(zeiger);
     zeiger := NIL;
     boolconnected := false;

      tagmanipulation.TriggerType:=0;
      tagmanipulation.TriggerMode:=1;
      tagmanipulation.TriggerSource:=0;
      tagmanipulation.TriggerValue:=0;
      tagmanipulation.TriggerHysterese:=0;

      tagmanipulation.DelayValue:=0;
      tagmanipulation.DelayType:=0;

      tagmanipulation.SequenceNumber:=0;
      tagmanipulation.ManipulationType:=3;
      tagmanipulation.ManipulationDuration:=0;
      tagmanipulation.ManipulationDurationType:=1;
      tagmanipulation.ManipulationMode:=4;
      tagmanipulation.ManipulationTarget:=123456;
      tagmanipulation.ManipulationTargetValue:=0;

      tagmanipulation.ManipulationValue1:=1000;
      tagmanipulation.ManipulationValue2:=0;
      tagmanipulation.ManipulationSteps:=0;
  end;

{ Signal manipulieren }
procedure TForm1.btnstartmanipulationClick(Sender: TObject);
  begin
    return := COM_RbsManipulationReq(zeiger, tagmanipulation);
    return := COM_StartRbsManipulationReq(zeiger);
  end;

{ Manipulation stoppen }
procedure TForm1.btnstopmanipulationClick(Sender: TObject);
  begin
    return := COM_StopRbsManipulationReq(zeiger);
  end;

{ Verbindungsaufbau }
procedure TForm1.btnconnectClick(Sender: TObject);
  begin
    { Verbindungsaufbau zu Flexcon midget }
    return := COM_TcpOpen(zeiger, ipAddress, port);
    boolconnected := true;
  end;

{ Verbindungsabbau }
procedure TForm1.btndisconnectClick(Sender: TObject);
  begin
    { Verbindungsabbau }
    return := COM_Close(zeiger);
    zeiger := NIL;
  end;
end.

Geändert von Pow3rus3r (14. Aug 2012 um 13:25 Uhr) Grund: lesbarkeit
  Mit Zitat antworten Zitat