Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Managed
Hello,
 
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 11:18am
Edited 19-May-12 22:21pm
v3
Comments
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
good
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.
 
[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:
 
VDXPluginInfo GetMe = (VDXPluginInfo)Marshal.PtrToStructure(List[0], typeof(VDXPluginInfo)); //etc etc
  Permalink  
v2
Comments
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.
 
Regards,
 
Olivier.

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2014
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