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