473,320 Members | 2,164 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,320 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 2456
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;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.