Calling unmanaged dll from VB.NET

L

Leftie

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
 
R

Rob Teixeira [MVP]

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top