How to marshal list of structures

C

Charlie

Hello everybody, I have a C++ function that returns a dynamical list of
structures.
....
typedef struct tagFOLDERITEM {
CString strFolderName;
HICON hIconSmall;
HICON hIconLarge;
} FOLDERITEM;
....
typedef CList<FOLDERITEM, FOLDERITEM> FolderItemList;
....
const FolderItemList *GetRecycleBinItems ();
....
I do not need these icons, only the name. Thats why I tryed:
....
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct FolderItem
{
[MarshalAs(UnmanagedType.LPTStr)]
public string name;
[MarshalAs(UnmanagedType.AsAny)]
public object ic1;
[MarshalAs(UnmanagedType.AsAny)]
public object ic2;
}
....
[DllImport("RecycleBinDemo.dll", EntryPoint="GetRecycleBinItems",
SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern FolderItem[] GetRecycleBinItems();
....
I have no idea how to marshal CList and I can't find any suggestion on
the web. Any ideas or solutions? Thanks in advance.
Charlie
 
M

Mattias Sjögren

I have no idea how to marshal CList and I can't find any suggestion on
the web. Any ideas or solutions? Thanks in advance.

The short answer is that you don't. Write a C++ wrapper that returns
the list in a well-defined format instead (such as a flat array).



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top