Groups | Blog | Home
all groups > dotnet interop > april 2006 >

dotnet interop : Pinvoke reading files, returning char * values.


anirudh
4/4/2006 7:18:47 AM
Hello,
I am trying to use an Win32 DLL developed using Visual C++ 6.0 in my
C# .net application.

The signature of the original function is as follows :

BOOL __stdcall GetXMLString(
const char* strInputFileName, // The input STL or RP file
name
const char* strPassword,
char* strOutput, // The output XML string
char* strErrorMessage) // The error message if
functions returns FALSE

So, this function takes the path of a file and a password and returns
back a string.

I translated like this :

[DllImport("STLKit.dll", CharSet=CharSet.Auto )]
public static extern bool GetXMLString(string inputFileName,
string
password,
ref
StringBuilder output,
string
errorMessage);

However this is not working at all and the output parameter is being
populated by weird messages like "publictoken" or "Dependancy
Evaluated" and so on.
My questions are :

Are these the correct mappings ?
Could there be a problem sending a file path to the function ?

Any help/pointers would really be very appreciated.

Thanks,
Anirudh
Mattias Sjögren
4/4/2006 5:47:20 PM
[quoted text, click to view]

The last two parameters should both be StringBuilders passed by value
(no ref keyword). Make sure they are initialized to large enough
capacity to hold whatever amount of text you get back so you don't get
a buffer overrun.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button