C++ "string" and .NET's String are two very different beasts. While, in the
sense of P/Invoke, you can declare arguments as System.String for all
flavours of char*, TCHAR*, TSTR and so on, this trick won't work for the C++
"string" class because it is not a mere pointer to a sequence of characters
in memory.
You can do a trick by declaring a managed structure having the same layout
in memory as the C++ string class, but still it can cause many troubles
related to marshalling string data. If you have at least slim chance to
alter the unmanaged DLL function to return some API-compatible string type
like TCHAR, use it!
One more thing - the unmanaged function is declared as "__stdcall". I am not
sure this is the same that the "WINAPI" convention expected by the .NET's
P/Invoke by default.
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Krzysztof" <kk******@poczta.onet.pl> wrote in message
news:bq**********@news.onet.pl...
I must use methods from standard dll im my C#code. In dll declaration of
method is like this:
typedef (__stdcall *ExecuteTaskFromXML)( const string& input, string&
output, DWORD& dwSize, LPVOID& pCtx );
How can I import (and use of course) this method? I try:
[DllImport("ExportDll.dll")]
public static extern void ExecuteTaskFromXML(String input, ref String
output, int dwSize, int pCtx);
but I've got error: System.NullReferenceException. (on String output)
What I must do? Some sample, docs or "entry point in codeproject" ;)) will
be best for me...
Please help
Regards
Krzysztof