Article View: comp.lang.pascal.delphi.misc
Article #5Delphi calls to a C++ DLL
From: John C. Lund
Date: Wed, 31 Jan 1996 20:52
Date: Wed, 31 Jan 1996 20:52
53 lines
2022 bytes
2022 bytes
I have written a DLL in C++ that I am attempting to call from a Delphi EXE. I can call
DLL functions from my C++ apps, but not from my Delphi program. The Delphi app calls the
DLL function, but most of the parameters passed are garbage. I tried the same techniques
and syntax I found in the Delphi libraries, but to no avail.
For whatever reason it looks like the parameters are pushed and popped from the stack
differently beween environments. I've tried declaring the function in Delphi with
"stdcall" and "cdecl", and I've tried other data types in place of pchar. Any
suggestions?
***************
Delphi SNIPPETS
***************
{type, private}
function GetFieldsForTable(
pcharDataSourceName,
pcharUsername,
pcharPassword,
pcharTableName: pChar
): integer;
{implementation}
function TODBCInformant.GetFieldsForTable;
external 'patrik.dll' name 'GetFieldsForTable';
{I call the function like this:}
nIndex:= GetFieldsForTable(strpcopy(pcharBuiffer,'Test'),
strpcopy(pcharBuiffer,''),
strpcopy(pcharBuiffer,''),
strpcopy(pcharBuiffer,'Employees'));
************
C++ SNIPPETS
************
// My C++ header (.H) declares the prototype like this:
extern "C" INT FAR PASCAL EXPORT GetFieldsForTable(
LPSTR lpszDataSourceName,
LPSTR lpszUsername,
LPSTR lpszPassword,
LPSTR lpszTableName
);
/*
My implementation uses the same format, and the function is named in the
exports section of the .DEF file.
*/
// John C. Lund jlund@allaire.com http//:www.allaire.com/
Technical Details
Message-ID:
<310FD68B.208B@allaire.com>Path:
arc1-ca.pugleaf.net!scream.ing.com!newsShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!scream.ing.com!news From: "John C. Lund" <jlund@allaire.com> Newsgroups: comp.lang.pascal.delphi.misc,comp.lang.c++ Subject: Delphi calls to a C++ DLL Date: Wed, 31 Jan 1996 14:52:27 -0600 Organization: Allaire Message-ID: <310FD68B.208B@allaire.com> NNTP-Posting-Host: 206.144.133.15 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 2.0b6a (Win95; I)