Article View: borland.public.cppbuilder.nativeapi
Article #2844Calling Pascal and C dll from the same application
From: Renald Yazmir
Date: Fri, 01 Dec 2006 14:08
Date: Fri, 01 Dec 2006 14:08
81 lines
2716 bytes
2716 bytes
I have C application that calls Pascal dll written in Delphi 4
Here is the function in C application that calls a function in Pascal
dynamically:
double do_something(void)
{
double a;
typedef double FAR PASCAL (* p)(void);
p fun_name;
fun_name = (p)GetProcAddress(hLib, "do_something_in_dll");
if(fun_name != NULL)
a = (fun_name)();
return a;
}
I converted Pascal dll into C.
In dll I declare export function:
extern "C" double __declspec(dllexport) do_something_in_dll(void);
In my calling appication I kill "FAR PASCAL "
double do_something(void)
{
double a;
typedef double (* p)(void);
p fun_name;
fun_name = (p)GetProcAddress(hLib, "do_something_in_dll");
if(fun_name != NULL)
a = (fun_name)();
return a;
}
Works fine!!!
----------------------------------------------
My goal now is to be able to use both Pascal and C dlls with the same
calling application.
Therefore I want to preserve old style calling convention with FAR PASCAL:
double do_something(void)
{
double a;
typedef double FAR PASCAL (* p)(void);
p fun_name;
fun_name = (p)GetProcAddress(hLib, "do_something_in_dll");
if(fun_name != NULL)
a = (fun_name)();
return a;
}
My question is how can I declare a function in the C dll with FAR PASCAL so
it can be compatible
with "my old style" calling convention.
I tried def file. It did not work.
Here is what I did in dll:
in def:
LIBRARY my_new_c_dll
EXPORTS
do_something_in_dll
in c:
double FAR PASCAL do_something_in_dll(void)
{
.....
}
in h:
double FAR PASCAL do_something_in_dll(void);
Thank you.
Renald
Technical Details
Message-ID:
<4570372f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f406291c6c807ecb,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Renald Yazmir" <renald@partmaker.com> From: "Renald Yazmir" <renald@partmaker.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Calling Pascal and C dll from the same application Date: Fri, 1 Dec 2006 09:08:19 -0500 Lines: 89 Organization: IMCS Inc X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 NNTP-Posting-Host: 66.106.28.123 Message-ID: <4570372f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1164982063 66.106.28.123 (1 Dec 2006 06:07:43 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail