Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

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

here is the c++ declaration :
C++
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
Updated 19-May-12 21:21pm
v3
Comments
OriginalGriff 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 20-May-12 11:50am    
I didn't bump my question, I just edited to add more description. Sorry.

1 solution

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

C#
[DllImport("**YOURDLL**"]
private static extern int VDGetPluginInfo();

[StructLayout(LayoutKind.Sequential)]
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:

C#
VDXPluginInfo GetMe = (VDXPluginInfo)Marshal.PtrToStructure(List[0], typeof(VDXPluginInfo)); //etc etc
 
Share this answer
 
v2
Comments
Kitarolivier 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.

Regards,

Olivier.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900