?
Solved

c++ dll porting

Posted on 2003-02-26
8
Medium Priority
?
220 Views
Last Modified: 2010-04-04
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
Comment
Question by:manlar
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 8031272
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
 

Author Comment

by:manlar
ID: 8031582
The document said it is array of long int.  Which conversion I should use?  Thanks.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 8031617
Best post a C example here. The help text would not hurt also.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:smurff
ID: 8032293
listening
0
 

Author Comment

by:manlar
ID: 8036805
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
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 1000 total points
ID: 8039574
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
 

Author Comment

by:manlar
ID: 8043578
Thanks for the help.
0
 
LVL 3

Expert Comment

by:smurff
ID: 8055983
robert does it again :)
Good work mate.
Kind regards
Smurff
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 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