Platform: VB.Net 1.1
I am trying to pass a string in VB.Net to a C Dll method which accepts a
BSTR. I get a nullreference exception whenever I call the API.
The following VBA declaration works fine in my previous Application:
Dim ddl As String
...
set_DatafilePath (ddl)
...
Declare Sub set_DatafilePath Lib "mydll.dll" (ByVal datafilepath As String)
In VB.Net, I have tried following:
String path = "somepath"
set_DatafilePath (path)
a) Declare Sub set_DatafilePath Lib "mydll.dll" ( ByVal datafilepath As
String)
b) Declare Sub set_DatafilePath Lib "mydll.dll" (
<MarshalAs(UnmanagedType.BStr)> ByVal datafilepath As String)
c) <DllImport("mydll.dll", CharSet:=CharSet.Auto)> _ 'Have tried ANSI as
well as Unicode as well
Public Shared Sub set_DatafilePath(<MarshalAs(UnmanagedType.BStr)> ByVal
datafilepath As String)
End Sub
d) <DllImport("mydll.dll", CharSet:=CharSet.Auto)> _
Public Shared Sub set_DatafilePath( ByVal datafilepath As String)
End Sub
Any help would be appreciated.
Cheers,
Manish Jain
manish04@hotmail.com
Dmytro Lapshyn [MVP] - 11 Apr 2006 14:32 GMT
Hi!
Here's how Microsoft recommends such functions to be declared (taken from
MSDN):
Public Declare Auto Sub PassBStr Lib "StringLib.Dll" _
(<MarshalAs(UnmanagedType.BStr)> s As String)
> Platform: VB.Net 1.1
>
[quoted text clipped - 33 lines]
> Manish Jain
> manish04@hotmail.com