jhordies
asked on
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(applic ation);
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:=tr ue;
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.Track1D ata;
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(TFo rm2, Form2);
Application.Run;
end.
########################## ########## ########## ########## #
Please help !!!!
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(applic
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:
OPOSMSR1.DecodeData:=true;
OPOSMSR1.DeviceEnabled:=tr
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:
begin
If (OPOSMSR1.DeviceEnabled = False)then
begin
testWide:=OPOSMSR1.Track1D
close();
end;
end;
procedure TForm1.Button1Click(Sender
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
begin
Label1.Caption:=chopeID();
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(TFo
Application.Run;
end.
##########################
Please help !!!!
ASKER
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.
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
May or may not be the issue...