Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C DLL in Delphi 2

Posted on 1998-11-14
4
Medium Priority
?
297 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 100 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 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