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

c++ dll porting

I am using external dll written in C++.  I need to port it to delphi.

the function declare as

DLLEXPORT short WINAPI cpiEndStream(long FAR *FAR *jobIDs);      

How do I declare it in delphi?

Thanks for the help.

Manlar
0
manlar
Asked:
manlar
  • 3
  • 3
  • 2
1 Solution
 
robert_marquardtCommented:
This is easy because it is C not C++. C++ classes are often not convertible.

type
  PInteger = ^Integer; // already in Windows unit
  PPInteger = ^PInteger;

function cpiEndStream(jobIDs: PPInteger): Smallint; stdcall;

There are other conversions possible.

function cpiEndStream(var jobIDs: PInteger): Smallint; stdcall;

The correct one is determined by the documentation. If nil (NULL in C notation) is a valid parameter value then the first conversion is correct. Also if the doc tells that it is an array of job IDs.
0
 
manlarAuthor Commented:
The document said it is array of long int.  Which conversion I should use?  Thanks.
0
 
robert_marquardtCommented:
Best post a C example here. The help text would not hurt also.
0
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!

 
smurffCommented:
listening
0
 
manlarAuthor Commented:
There is no detail doc but there are some notes from .h file:

The list of job IDs is returned to you. The buffer is a simple allocated (into the CPI.DLL) array of longs, terminated with a 0. The amount of elements in this array equal to amount of sent faxes.

DLLEXPORT short WINAPI cpiEndStream(long FAR *FAR *jobIDs);      /* YOU must cpiFree() this */
DLLEXPORT void WINAPI cpiFree(void FAR *memory);

I need to call cpiFree to deallocate any memory that CPI has allocated.  But the call cpiFree causes the appication is crashed.

How do I declare these two functions in delphi?  Thnaks for the help.


0
 
robert_marquardtCommented:
Now it is much clearer.

function cpiEndStream(var jobIDs: PInteger): Smallint; stdcall;
procedure cpiFree(Memory: Pointer); stdcall;

is the best conversion. The function allocates memory and places it in a pointer variable.

var
  JobList: PInteger;
begin
  cpiEndStream(JobList);
  // do something
  cpiFree(JobList);
end;
0
 
manlarAuthor Commented:
Thanks for the help.
0
 
smurffCommented:
robert does it again :)
Good work mate.
Kind regards
Smurff
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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