Click here to Skip to main content
11,804,574 members (74,901 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Managed

I need to call a function which returns an array of pointer to structures :

here is the c++ declaration :
const VDXPluginInfo *const *VDXAPIENTRY VDGetPluginInfo();

it returns an array of pointers to a VDXAPIENTRY, which is terminated by a pointer to zero

How can I translate this to call it from c# ?

Of course, I searched the web, and found many things about pointer arrays in arguments, but never returned from function.

Thank you.
Posted 19-May-12 10:18am
Edited 19-May-12 21:21pm
OriginalGriff at 20-May-12 3:29am
Don't bump your question - it's rude. Especially when it was only half way down the unanswered page...
Kitarolivier at 20-May-12 11:50am
I didn't bump my question, I just edited to add more description. Sorry.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I Guess i would try something as the next, couldn't check if it worked though, i've nothin' alike.

private static extern int VDGetPluginInfo();
private struct VDPointer
    public int VDXPlugin;
public List<intptr> GetPointers()
   VDPointer Result = new VDPointer();
   Result.VDXPlugin = -1; //we want our first run to go
   List<intptr> ToFill = new List<intptr>();
   int Retrieve = VDGetPluginInfo; //We should have gotten start adres of the array on our int
   while (Result. VDXPlugin != 0)
      Result = (VDPointer)Marshal.PtrToStructure(new IntPtr(Retrieve), typeof(VDPointer));
      if (Result.VDXPlugin != 0)
          Retrieve += 4; //Let's step to next pointer entry, assuming pointer is 32 bit int
          ToFill.Add(new IntPtr(Result.VDXPlugin));
   return ToFill;
I think this should do the trick, and from there u could retrieve the contents of the pointers the same:

VDXPluginInfo GetMe = (VDXPluginInfo)Marshal.PtrToStructure(List[0], typeof(VDXPluginInfo)); //etc etc
Kitarolivier at 29-May-12 11:12am
Thank you for your answer.

I've accepted the solution (this may help other people), although I din't test it for two reason : 1.I've moved the project to c++ 2. In the kind of plugin I want to use, this function is not used.

Anyway, let me thank you again for the effort you take to provide me a solution.



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 3,205
1 Maciej Los 1,950
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100