469,142 Members | 1,162 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,142 developers. It's quick & easy.

Marshalling char** in p/invoke?

Howdy,

I have a legacy DLL for which I have a problem marshalling a parameter type
of char**.

The function header (C++) is as so;

extern "C" __declspec(dllexport) int __stdcall GetChildren(GetChildrenParm
*, Results *);

typedef struct _GetChildrenParm {
char *id_parent;
int num_results_max;
} GetChildrenParm;

typedef struct _Results {
char **id_object;
int num_results;
} Results;
My current C# code looks like;

[DllImport("objapi.dll")]
extern static int GetChildren (ref GetChildrenParm inParam, ref Results
outParam);

struct GetChildrenParm
{
string id_parent;
int num_results_max;

public ObjGetFolderChildrenParm(
string _id_parent,
int _num_results_max)
{
id_parent = _id_parent;
num_results_max = _num_results_max;
}
};
Marshalling the GetChildrenParm (inParam) is no problem, but marshalling the
Results (outParam) is giving me a headache due to the char** datatype within
the structure.

Any ideas how I can make this work? I can't find any examples anywhere of
Marshalling a char** type, let alone one within a struct.... ???

Feb 6 '06 #1
2 2242
I had the same problem. The advice given to me is to use unsafe code
and ptr or intptr but I haven't seen an example. If you get this
working then I'd like to see it.
Curtis
http://www.ghostclip.com
The Premier Help System For Developers

Feb 6 '06 #2
In the end, I've decided to use the Marshal class with IntPtr's to manually
translate the data. Since this is an out parameter, and the DLL I'm calling
into does the memory allocation, this works. My final solution involves
building a simple implementor for the ICustomMarshaler interface. It works
for now, so that'll do. :-P

I'm not sure it will be applicable for all cases though...

"Light" wrote:
I had the same problem. The advice given to me is to use unsafe code
and ptr or intptr but I haven't seen an example. If you get this
working then I'd like to see it.
Curtis
http://www.ghostclip.com
The Premier Help System For Developers

Feb 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by PHil Coveney | last post: by
3 posts views Thread by Jerry Houston | last post: by
2 posts views Thread by Peter Wone | last post: by
11 posts views Thread by Daniel Bass | last post: by
3 posts views Thread by Saad | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.