> I need to call a function in a legacy, unmanaged DLL that
> has the following syntax:
[quoted text clipped - 4 lines]
> function both zero-terminate the version string as well as
> return the length of the version string.
I would try something like
[ DllImport("Unmanaged.dll", CharSet=CharSet.Ansi, ExactSpelling=true) ]
private static extern void GetVersion(StringBuilder buf);
and pass a StringBuilder with a capacity of at least 250 characters.
Jens.

Signature
http://ManagedXLL.net/ | http://jens-thiel.de/ | http://QuantLib.net/
Replace MSDN with my first name when replying to my email address!
Well, I have been down that road and it does not work :(
A snip of my C# code:
[DllImport("MyGetVersion.dll", CharSet=CharSet.Ansi,
ExactSpelling=true)]
private static extern int MyGetVersion(StringBuilder
version);
private static void Test()
{
StringBuilder version = new StringBuilder(250);
MyGetVersion(version);
System.Diagnostics.Debug.WriteLine(version);
}
I have created my own unmanaged DLL to try a few things
out and the MyGetVersion function looks like this:
extern "C" MYGETVERSION_API int MyGetVersion(char
**version)
{
char *target = *version;
strncpy(target, "Version 1.1", 249);
return (int) strlen(target);
}
Calling the C++ from C# gives me an access denied error...
Thanks,
Hakon
>-----Original Message-----
>> I need to call a function in a legacy, unmanaged DLL that
[quoted text clipped - 14 lines]
>
>Jens.
Mattias Sj?gren - 25 Nov 2003 12:10 GMT
Hakon,
>A snip of my C# code:
>[DllImport("MyGetVersion.dll", CharSet=CharSet.Ansi,
>ExactSpelling=true)]
>private static extern int MyGetVersion(StringBuilder
>version);
Make the StringBuilder a ref parameter to add the extra level of
indirection needed.
private static extern int MyGetVersion(ref StringBuilder version);
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Hehe - I was sure that I tried that before but now it
works :D
Thanks Mattias and Jens
/H
>-----Original Message-----
>Hakon,
[quoted text clipped - 11 lines]
>
>Mattias