Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2005

Tip: Looking for answers? Try searching our database.

Interop error in vb.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
justin.hayworth@gmail.com - 21 Oct 2005 18:43 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.