I am trying to use a function in an unmanaged dll and I am getting a
System.NullReferenceException when called.
I do not have source code for the vendor dll.
>From the dll header file the declaration is:
WEBEXPORT char* function1;
vb.net
------
<DllImport("vendor.dll")> _
Public Shared Function function1() As <MarshalAs(UnmanagedType.LPStr)>
System.Text.StringBuilder
End Function
...
Dim sError As System.Text.StringBuilder
sError = waLastErrorStr()
I have tried calling by ordinal and several types for the return type
and nothing has worked so far. There are several other functions in
this dll that I have been able to get to work successfully. I have
also written some test code in c++ that also was able to successfully
call this function, but no luck so far in vb.net.
My guess so far is that the issue is because the function does not have
any parameters. In c++ I have to call without () on the function call.
Is there any way to do that in vb.net?
Any thoughts?
Justin
Mattias Sjögren - 21 Oct 2005 22:17 GMT
>>From the dll header file the declaration is:
>WEBEXPORT char* function1;
Is that really what the header file says? This declares a variable,
not a function.
>vb.net
>------
><DllImport("vendor.dll")> _
>Public Shared Function function1() As <MarshalAs(UnmanagedType.LPStr)>
>System.Text.StringBuilder
Try using IntPtr as the return type and use Marshal.PtrToStringAnsi to
retrieve the string. Also make sure the string is freed if needed.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.