PC Review


Reply
Thread Tools Rate Thread

Calling unmanaged dll from VB.NET

 
 
Leftie
Guest
Posts: n/a
 
      21st Feb 2004
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
 
Reply With Quote
 
 
 
 
Rob Teixeira [MVP]
Guest
Posts: n/a
 
      22nd Feb 2004
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" <(E-Mail Removed)> wrote in message
news:1389c01c3f899$59bc8e40$(E-Mail Removed)...
> 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



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling unmanaged C++ dll from C# app =?Utf-8?B?Q2hyaXM=?= Microsoft C# .NET 8 25th Jan 2005 03:01 AM
Calling C# from unmanaged C++ Fernando Cacciola Microsoft C# .NET 6 6th Jan 2005 12:09 AM
Re: Calling unmanaged dll from C# Nicholas Paldino [.NET/C# MVP] Microsoft C# .NET 0 31st Aug 2004 03:24 PM
calling unmanaged c++ Jacob Gladish Microsoft C# .NET 6 3rd Nov 2003 03:02 PM
Calling .Net from C++ (unmanaged) Paul Microsoft Dot NET Framework 1 30th Oct 2003 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:41 PM.