• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 986
  • Last Modified:

EWin32Error an Win32 API function failed (after a dll function call)

I made the folowing Dll to check to check a track on a magnetic strip.
On then "END." of the caller project, if i did call the dll function, i get an "EWin32Error an Win32 API function failed "(translated from french).

Sorry for the 30 points, i'm new and that's all i have
Please help
Jerome


THE DLL:
##########################################################
unit Unit1;

interface

uses
  ShareMem, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OleCtrls, OposMSR_1_5_Lib_TLB, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    OPOSMSR1: TOPOSMSR;
    Timer1: TTimer;
    Panel1: TPanel;
    Label1: TLabel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Diclarations privies }
  public
    { Diclarations publiques }
  end;

var
testWide:ShortString;
 Form1: TForm1;
function getId():ShortString;

implementation


{$R *.DFM}
function getId():ShortString;
var Form:TForm1;

begin
     Form:=Tform1.create(application);
     Form.ShowModal();
     Result:=testWide;
end;

exports getId name 'GetId';

procedure TForm1.FormCreate(Sender: TObject);
begin
testWide:='';
OPOSMSR1.Open('MSR2');
OPOSMSR1.ClaimDevice(1000);
OPOSMSR1.AutoDisable:=true;
OPOSMSR1.DataEventEnabled:=true;
OPOSMSR1.DecodeData:=true;
OPOSMSR1.DeviceEnabled:=true;
Timer1.Enabled:=true;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  OPOSMSR1.ReleaseDevice();
  OPOSMSR1.Close();
  Timer1.Enabled:=false;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
 If (OPOSMSR1.DeviceEnabled = False)then
   begin
     testWide:=OPOSMSR1.Track1Data;
     close();
   end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  OPOSMSR1.ReleaseDevice();
  OPOSMSR1.Close();
close();
end;

end.
__________________________________________________________
library Project2;



uses   ShareMem,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin

end.
#########################################################



THE PROJECT:
#########################################################
unit Uutildll;

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Diclarations privies }
  public
    { Diclarations publiques }
  end;

var
  Form2: TForm2;
  testWide: ShortString;
implementation
{$R *.DFM}
Function chopeID():ShortString; stdcall;external 'Project2.dll' name 'GetId';

procedure TForm2.Button1Click(Sender: TObject);
begin
 Label1.Caption:=chopeID(); //DLL FUNCTION CALL
end;

initialization
 CoInitialize(nil);
finalization
 CoUnInitialize();

end. // <-- THE BUG HERE APPEARS HERE
__________________________________________________________

program Putildll;

uses
  Forms,
  Uutildll in 'Uutildll.pas' {Form2};

{$R *.RES}

begin
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.
#########################################################

Please help !!!!


0
jhordies
Asked:
jhordies
1 Solution
 
andrewjbCommented:
You need to uses ShareMem in both the dll and the project - in teh project file (not the form unit).
May or may not be the issue...
0
 
jhordiesAuthor Commented:
I've tried with an without sharemem, in the dll and the project, in only the unit, only the project file, etc but that's not issue.
0
 
CleanupPingCommented:
jhordies:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
ee_ai_constructCommented:
PAQed, with points refunded (30)

ee_ai_construct
Community Support Moderator
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now