473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Calling a Delphi DLL

How can I call a function in a Delphi DLL from C++/CLI?

The Delphi function is declared as follows:

function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;

I've tried

[DllImport("mydll", EntryPoint="Func1")]
extern "C" char *Func1(int isDsb, char *firstString, char
*secondString);

Func1(0, "kl;kl;sdfk", "kdlks;ldfk");

but I get an access violation. What should I be doing?

What calling convention will the Delphi function use? Does it need to
have stdcall added?

TIA,
KK
Aug 1 '08 #1
5 3833
ke***********@googlemail.com wrote:
How can I call a function in a Delphi DLL from C++/CLI?

The Delphi function is declared as follows:

function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;

I've tried

[DllImport("mydll", EntryPoint="Func1")]
extern "C" char *Func1(int isDsb, char *firstString, char
*secondString);

Func1(0, "kl;kl;sdfk", "kdlks;ldfk");

but I get an access violation. What should I be doing?

What calling convention will the Delphi function use? Does it need to
have stdcall added?
In Delphi you should...

- Use "PChar" instead of "String" (String is a delphi type, C++ CLI doesn't
known anything about Delphi strings)
- Use "stdcall" calling convention (By default Delphi use its own calling
convention).

Regards
--
Cholo Lennon
Bs.As.
ARG

Aug 1 '08 #2
Cholo Lennon wrote:
ke***********@googlemail.com wrote:
>How can I call a function in a Delphi DLL from C++/CLI?

The Delphi function is declared as follows:

function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;

I've tried

[DllImport("mydll", EntryPoint="Func1")]
extern "C" char *Func1(int isDsb, char *firstString, char
*secondString);

Func1(0, "kl;kl;sdfk", "kdlks;ldfk");

but I get an access violation. What should I be doing?

What calling convention will the Delphi function use? Does it need to
have stdcall added?

In Delphi you should...

- Use "PChar" instead of "String" (String is a delphi type, C++ CLI
doesn't known anything about Delphi strings)
- Use "stdcall" calling convention (By default Delphi use its own
calling convention).
One more thing...

If you use "int" for boolean type in C++ CLI and if you're in 32 bits
architecture, use LongBool in Delphi. Or, in opposition, use bool in C++ CLI if
you use boolean in delphi.
Regards
--
Cholo Lennon
Bs.As.
ARG

Aug 1 '08 #3
On 1 Aug, 17:41, "Cholo Lennon" <chololen...@hotmail.comwrote:
kelvin.koo...@googlemail.com wrote:
How can I call a function in a Delphi DLL from C++/CLI?
The Delphi function is declared as follows:
function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;
I've tried
[DllImport("mydll", EntryPoint="Func1")]
extern "C" char *Func1(int isDsb, char *firstString, char
*secondString);
Func1(0, "kl;kl;sdfk", "kdlks;ldfk");
but I get an access violation. What should I be doing?
What calling convention will the Delphi function use? Does it need to
have stdcall added?

In Delphi you should...

- Use "PChar" instead of "String" (String is a delphi type, C++ CLI doesn't
known anything about Delphi strings)
- Use "stdcall" calling convention (By default Delphi use its own calling
convention).

Regards

--
Cholo Lennon
Bs.As.
ARG- Hide quoted text -

- Show quoted text -
Thanks. I ShortString as good as PChar in this instance?

KK
Aug 1 '08 #4
On Aug 1, 11:39*pm, kelvin.koo...@googlemail.com wrote:
On 1 Aug, 17:41, "Cholo Lennon" <chololen...@hotmail.comwrote:
- Use "PChar" instead of "String" (String is a delphi type, C++ CLI doesn't
known anything about Delphi strings)
Thanks. I ShortString as good as PChar in this instance?
No. You need to use PChar (which is really just Char^, that is, a
pointer to characters of the string).
Aug 1 '08 #5
ke***********@googlemail.com wrote:
On 1 Aug, 17:41, "Cholo Lennon" <chololen...@hotmail.comwrote:
>kelvin.koo...@googlemail.com wrote:
>>How can I call a function in a Delphi DLL from C++/CLI?
>>The Delphi function is declared as follows:
>>function Func1(IsDsb: Boolean; FirstStr, SecondStr : String):
String;
>>I've tried
>>[DllImport("mydll", EntryPoint="Func1")]
extern "C" char *Func1(int isDsb, char *firstString, char
*secondString);
>>Func1(0, "kl;kl;sdfk", "kdlks;ldfk");
>>but I get an access violation. What should I be doing?
>>What calling convention will the Delphi function use? Does it need
to have stdcall added?

In Delphi you should...

- Use "PChar" instead of "String" (String is a delphi type, C++ CLI
doesn't known anything about Delphi strings)
- Use "stdcall" calling convention (By default Delphi use its own
calling convention).

Regards

--
Cholo Lennon
Bs.As.
ARG- Hide quoted text -

- Show quoted text -

Thanks. I ShortString as good as PChar in this instance?
No. PChar (pointer to char) is equivalent to char*. ShortString is another
Delphi type and C++ CLI doesn't know anything about it. BTW ShortString
internally has (or Is) an array with up 255 chars. In this array the string
length is stored at the 1st byte and IIRC the string isn't terminated with NULL
(necessary in every C function that expects a tipical string). This shows the
incompatiblity between ShortString and the C++ CLI point of view about the array
of chars.
--
Cholo Lennon
Bs.As.
ARG

Aug 1 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Brad Tilley | last post by:
Is it possible to write a file open, then read program in C and then call the C program from a Python script like this: for root, files, dirs in os.walk(path) for f in files: try:...
6
by: Erva | last post by:
Hi, Is there someone who has moved from Delphi to VS.NET? I'am using Delphi currently but seriously considering to moving VS.NET. I would like to hear if someone has already done that, is it...
1
by: ARTMIC | last post by:
Hello, could someone please help me out, i'm trying to call a Delphi 6.0 custom DLL from inside of a C# windows project. what am i doing wrong? i use the following declaration: public class...
1
by: ARTMIC | last post by:
Hello, could someone please help me out, i'm trying to call a Delphi 6.0 custom DLL from inside of a C# windows project. i use the following declaration: static extern double...
4
by: Three | last post by:
Hi there, I have to integrate a .Net application into a Delphi application somehow. The simplest method is to get the Delphi app to call a .Net console app, however it would be better for...
2
by: Prabhat | last post by:
Hello ALL, I have ASP pages that calls some ISAPI dll that created using Delphi for generating reports. The report page opens fine for 1st time when invoked but next time i get error like "Name...
2
by: jewalsh2k | last post by:
Hi, I have a delphi dll which I am trying to call from C# but something isn't working, I get an SEHException thrown by the dll but I don't get enough info to debug it. I can't change the dll...
11
by: gnuist006 | last post by:
Is there a Delphi equivalent in the C world or Scheme/LISP world ? Recently, Delphi is in resurgence. In Russia people are using like crazy. For example, Bolega has written a free image...
0
by: BornTOCode | last post by:
Hello, I am attempting to call a (Delphi) win32 DLL from a Delphi.Net webservice. I am using a slightly modified version of the hello world webservice that comes with Delphi 2006. The DLL...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.