473,399 Members | 2,858 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,399 software developers and data experts.

Calling DLL functions, strings, pointers

Hi,

If I make a DLL in Delphi (5..7, so not NET) to manipulate strings, then I
assume I have to do something like this:

[DllImport("test.dll")]
public static extern TestProc(String C);

and in the Delphi DLL:

procedure TestProc(C: PChar); stdcall;

I think so because I have made such P/Invoke things for Win32 API whitch
also accept a pointer to null terminated data and are fine working.

This also mean I can modify the data of C safely in my DLL ?

All advice is very welcome, I'm still a newbe for dotnet :)

--
rgds, Wilfried
http://www.mestdagh.biz
Nov 16 '05 #1
2 2516
Wilfried,

What does PChar map to? This will affect the declaration on the .NET
side. If PChar is a char string, then you would do this:

[DllImport("test.dll", CharSet=CharSet.Ansi)]
public static extern void TestProc(String C);

If it is a unicode string then you would do this:

[DllImport("test.dll", CharSet=CharSet.Unicode)]
public static extern void TestProc(String C);

Now, if you modified the contents of C in the string, you would have to
declare your function using a StringBuilder, like so:
[DllImport("test.dll", CharSet=CharSet.Unicode)]
public static extern void TestProc(StringBuilder C);

Of course, you would have to allocate space in the string builder before
you pass it to the function (otherwise, you could get a nasty access
violation).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wilfried Mestdagh" <Wi**************@discussions.microsoft.com> wrote in
message news:2F**********************************@microsof t.com...
Hi,

If I make a DLL in Delphi (5..7, so not NET) to manipulate strings, then I
assume I have to do something like this:

[DllImport("test.dll")]
public static extern TestProc(String C);

and in the Delphi DLL:

procedure TestProc(C: PChar); stdcall;

I think so because I have made such P/Invoke things for Win32 API whitch
also accept a pointer to null terminated data and are fine working.

This also mean I can modify the data of C safely in my DLL ?

All advice is very welcome, I'm still a newbe for dotnet :)

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 16 '05 #2
Hi Nicholas,
What does PChar map to? This will affect the declaration on the .NET
side. If PChar is a char string, then you would do this:
Thanks for your reply. Yes, PChar is pointer to null terminated string. So I
guess StringBuilder is what I need if I make changes into the string,
otherwise String.

rgds, Wilfried
http://www.mestdagh.biz

"Nicholas Paldino [.NET/C# MVP]" wrote:
Wilfried,

What does PChar map to? This will affect the declaration on the .NET
side. If PChar is a char string, then you would do this:

[DllImport("test.dll", CharSet=CharSet.Ansi)]
public static extern void TestProc(String C);

If it is a unicode string then you would do this:

[DllImport("test.dll", CharSet=CharSet.Unicode)]
public static extern void TestProc(String C);

Now, if you modified the contents of C in the string, you would have to
declare your function using a StringBuilder, like so:
[DllImport("test.dll", CharSet=CharSet.Unicode)]
public static extern void TestProc(StringBuilder C);

Of course, you would have to allocate space in the string builder before
you pass it to the function (otherwise, you could get a nasty access
violation).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wilfried Mestdagh" <Wi**************@discussions.microsoft.com> wrote in
message news:2F**********************************@microsof t.com...
Hi,

If I make a DLL in Delphi (5..7, so not NET) to manipulate strings, then I
assume I have to do something like this:

[DllImport("test.dll")]
public static extern TestProc(String C);

and in the Delphi DLL:

procedure TestProc(C: PChar); stdcall;

I think so because I have made such P/Invoke things for Win32 API whitch
also accept a pointer to null terminated data and are fine working.

This also mean I can modify the data of C safely in my DLL ?

All advice is very welcome, I'm still a newbe for dotnet :)

--
rgds, Wilfried
http://www.mestdagh.biz


Nov 16 '05 #3

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

Similar topics

4
by: OzgurGul | last post by:
int main(){ /* I have a function :) and I want to use it but I dunno how to call it... (I have trouble that pointers) please help me... mmm... thanks for all advance!! */
2
by: MJL | last post by:
I am working on a small project that involves the manipulation of dynamically allocated memory for strings. I was wondering why the string.h functions are the way they are and why not as follows:...
6
by: Ruben | last post by:
I'm trying to pass an array of string to a function without knowing how many strings I have beforehand. I've defined one functions as char * insert(char table,int cols, char values); out of...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
4
by: Henning M | last post by:
Hej All Im relativ new to VB.net and im trying to collect som device information using cfgmgr32.dll I use - Declare Function GetListLength Lib "cfgmgr32.dll" Alias...
15
by: Christian Christmann | last post by:
Hi, in which situations pointers to functions might be more efficient/convenient than a direct function call? In the example I've found so far, I see no advantage of using pointers to...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
12
by: bgold | last post by:
Hey. I have a base class (SPRITE), and using this base class I have derived a large number of derived classes (PERSON, BULLET, MISSILE, etc.). Now, at a certain point in my program, I have a pair...
2
by: =?Utf-8?B?SmFuIExpbmRo?= | last post by:
Hi Is there a preferable way to write a C# dll that should be called from an existing application (running native code). It is not possible to change this application and its source code isn't...
2
by: unauthorized | last post by:
The short story: I need to be able to cast a function pointer for any function and class to an intermediate type, so I could call it from any point of my program using the "__asm call" instruction....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.