By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

Calling unmanaged dll from VB.NET

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.