473,226 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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 2450
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PHil Coveney | last post by:
Hello, I am having difficulty marshalling structures when calling DeviceIoControl. I am importing this Win32 function as static extern int DeviceIoControl (int hDevice, int...
3
by: Jerry Houston | last post by:
In a winform application, I use worker threads to perform asynchronous tasks (e.g., mail merge with Word). The thread procs need to gather some user options from controls in the UI, and I know...
1
by: Reynardine | last post by:
I am calling a C/C++ DLL from C# and I am marshalling the parameters to the API call by doing a type conversion for each parameter. For example, here is my C++ API method : short int XENO_API...
1
by: | last post by:
Hi, Is there any good links for datatype interop? I need to pass some structure pointers into an unmanaged method and return char* etc but having some problems in my C++/CLI proxy class. I...
2
by: Peter Wone | last post by:
I've written a class which does some long running background processing and returns multiple results via events. The class has an Execute() method which creates a thread and runs an internal method...
10
by: Bryce Calhoun | last post by:
Hello, First of all, this is a .NET 1.1 component I'm creating. SUMMARY ----------------------- This component that I'm creating is, for all intents and purposes, a document parser (I'm...
11
by: Daniel Bass | last post by:
Greetings! I'm trying to call this method in a c# app... SNAPIDLL_API int __stdcall SNAPI_SetCapabilitiesBuffer(HANDLE DeviceHandle, unsigned char *pData, long max_length); So far I've got...
2
by: calenlas | last post by:
Hi all, I'm taking my first steps into C# <--C++ DLL Interop and unfortunately I've run into (what seems to be) a very complicated case as my first task. Perhaps someone here can help me. I...
3
by: Saad | last post by:
Hi, I have a struct as follows: public __gc struct STTemp { public: int someint; System::Collections::ArrayList* arrTemp;
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.