PC Review


Reply
Thread Tools Rate Thread

How to declare a pointer to array return type for external function?

 
 
constructor
Guest
Posts: n/a
 
      16th Oct 2008
Hello NG,

I'm having to use a function in an external library that returns a pointer
to an array of structs.
The function declaration according to library vendor is:
device** getList( int &count)
The returned structs:

typedef struct tag_dev
{
int nr;
char* name;
} device;

I tried coding this:
[DllImport("myDll.dll")]
private static extern device** getList(int* count);
...
...
unsafe static void getDeviceList()
{
int count;
int* p = &count;
device** devices = getList(p);
..
..
}

This compiles without errors (unsafe flag set) and there are no runtime
errors.
But the result is nonsense. There is always just one entrance in the list,
18 are expected,
the nr member of the struct is always zero and the name pointer points to
nothing meaningful.

I think, my declaration for the return value is wrong, isn't it? Do I have
to use unsafe code at all
to invoke the external function or are there other ways to do this?

Thanks for any ideas,

regards Uwe



 
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
How do you declare this C DLL function in VB? - uses a long pointer Angus Microsoft VB .NET 1 4th Oct 2007 04:44 PM
Declare and array in a function =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Programming 3 30th Sep 2006 03:41 AM
How do I declare a function whose output is an array? Schizoid Man Microsoft Excel Discussion 1 24th May 2006 10:26 PM
How do I declare a function whose output is an array? Schizoid Man Microsoft Excel Programming 5 24th May 2006 09:23 PM
How to declare DefaultValue(type, string) for an Empty Array[0] Mike Microsoft C# .NET 0 29th Jun 2004 07:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:33 PM.