471,059 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,059 software developers and data experts.

Calling unmanaged dll from VB.NET

Folks,
I'm trying to call an unmanaged function from VB.NET and
keep getting "Object reference not set to an instance of
an object" error.

The code that i wrote can be found at:
http://www.nomorepasting.com/paste.php?pasteID=5973

The dll (if some kind soul has the time to compile and run
the code) can be found at:
ftp://ftp.astro.com/pub/swisseph/sweph.zip
The original function definition in the dll is:
char *FAR PASCAL swe_get_planet_name(int ipl, char
*spname);
Any help is greatly appreciated.
Thanks,
Leftie
Nov 20 '05 #1
1 2890
Two problems:

First, you need to initialize the stringbuilder with enough buffer space for
the string the unmanaged function intends to fill.
Secondly, your function uses the PASCAL calling convention. This calling
convention is not directly supported by the framework. The calling
convention specifies two primary things - the order of the parameters on the
stack, and who cleans the stack frame (the caller, or the callee). I can't
recall the exact rules of the PASCAL calling convention off the top of my
head, but in *theory* you can experiment and you might still be able to get
it to work, especially since you only have two 32-bit parameters on the
stack in this case.

-Rob Teixeira [MVP]

"Leftie" <an*******@discussions.microsoft.com> wrote in message
news:13*****************************@phx.gbl...
Folks,
I'm trying to call an unmanaged function from VB.NET and
keep getting "Object reference not set to an instance of
an object" error.

The code that i wrote can be found at:
http://www.nomorepasting.com/paste.php?pasteID=5973

The dll (if some kind soul has the time to compile and run
the code) can be found at:
ftp://ftp.astro.com/pub/swisseph/sweph.zip
The original function definition in the dll is:
char *FAR PASCAL swe_get_planet_name(int ipl, char
*spname);
Any help is greatly appreciated.
Thanks,
Leftie

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jesse McGrew | last post: by
reply views Thread by monika.saxena | last post: by
1 post views Thread by MC-Advantica | last post: by
9 posts views Thread by Amit Dedhia | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.