Solved

C DLL in Delphi 2

Posted on 1998-11-14
4
296 Views
Last Modified: 2010-04-04
I wrote a DLL in MS Visual C++, and I want to call it from a Delphi 2 app. How do I do this? Here is my declaration of the function in C++:

BOOL UnpackFile(const char* Resource, const char* InFile)
0
Comment
Question by:mmarvi
[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
  • 2
4 Comments
 

Accepted Solution

by:
kashif063098 earned 50 total points
ID: 1346804
first you need to declare this function in delphi in following way
function UnpackFile(Resource,InFile:PChar):boolean;cdecl;
external 'C:\YourCdll.dll' name 'UnpackFile';

then simply call UnpackFile() with appropriate parameters.

Any question please ask!

regards

0
 

Author Comment

by:mmarvi
ID: 1346805
Dear kashif:

I put your code into a test program, and at build time, I encountered an error "field defintion not allowed after methods or procedures." I included the unit's code below, please find my error and correct it.

Thanx!

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure OnExtract(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function UnpackFile(Resource,InFile:PChar):boolean; cdecl; external 'WPLANE.DLL';
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.OnExtract(Sender: TObject);
var
     h: boolean;
begin
     h := UnpackFile('WINGS.WAD', 'JEX.EXE');
     if h = true then ShowMessage('Success!');
     else ShowMessage('Fail!');
end;

end.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1346806
Don't place UnpackFile in the form class.  Just place it by itself in the module.
0
 

Expert Comment

by:kashif063098
ID: 1346807
scrapdog is right put the following declaration after the uses clause
>>uses
>>  Windows, Messages, SysUtils, Classes, Graphics, Controls, >>  Forms, Dialogs,StdCtrls;

function UnpackFile(Resource,InFile:PChar):boolean;cdecl;
external 'C:\YourCdll.dll' name 'UnpackFile';
After this change your exmaple should look like following

unit Unit1;

interface

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

/*Remember to include the full path to your dll*/
function UnpackFile(Resource,InFile:PChar):boolean; cdecl; external 'WPLANE.DLL' name 'UnpackFile';


type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure OnExtract(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
   
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.OnExtract(Sender: TObject);
var
     h: boolean;
begin
     h := UnpackFile('WINGS.WAD', 'JEX.EXE');
     if h = true then ShowMessage('Success!');
     else ShowMessage('Fail!');
end;

end.


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month6 days, 1 hour left to enroll

627 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