?
Solved

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

Posted on 2003-02-27
5
Medium Priority
?
974 Views
Last Modified: 2010-05-18
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
Comment
Question by:jhordies
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 8032668
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
 

Author Comment

by:jhordies
ID: 8032703
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
 

Expert Comment

by:CleanupPing
ID: 9317042
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
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 10606515
PAQed, with points refunded (30)

ee_ai_construct
Community Support Moderator
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question