By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,170 Members | 1,406 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,170 IT Pros & Developers. It's quick & easy.

Mapping char *str[]

P: n/a
Hello

I am wrapping a C DLL into C# project.

Being a newbie in C#, I wonder how one can map the following:

struct X
{
char *str[];
int count;
};

and the following callback:

typedef void (__stdcall *cb)(int a, int b, char *s[]);

Which is used as a param in another C function to be mapped:

void register_cb(char *description, cb c);

Thanks,
Elias
May 15 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Elias,

In this case, you would have to map str to an IntPtr, it's essentially a
double pointer to a character, an array of arrays, it would seem (or at
least a reference to an array).

You would have to handle the marshaling of this structure yourself.

As for cb, is it a structure? If so, you will have to return an IntPtr,
and then marshal that back to managed code manually. Also, you have to
figure out how to release the memory that is allocated to return the
structure (since you are returning a pointer to it, one assumes you
allocated memory for it).

Once you have that in place, passing the structure to your other
function should be easy.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"lallous" <la*****@lgwm.org> wrote in message
news:Oj**************@TK2MSFTNGP03.phx.gbl...
Hello

I am wrapping a C DLL into C# project.

Being a newbie in C#, I wonder how one can map the following:

struct X
{
char *str[];
int count;
};

and the following callback:

typedef void (__stdcall *cb)(int a, int b, char *s[]);

Which is used as a param in another C function to be mapped:

void register_cb(char *description, cb c);

Thanks,
Elias

May 15 '06 #2

P: n/a
Hello, Nicholas!

NPN> As for cb, is it a structure? If so, you will have to return an
NPN> IntPtr, and then marshal that back to managed code manually.

It is function pointer ( typedef void (__stdcall *cb)(int a, int b, char *s[]); )
So it can be a delegate param in the void register_cb(char *description, cb c); function

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 15 '06 #3

P: n/a
Vadym,

Oops, sorry, duh on my part.

In the case of the function pointer, you will need to create a delegate:

public delegate void MyCallback(int a, int b, IntPtr s);

You would have to marshal the array manually again.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:el**************@TK2MSFTNGP03.phx.gbl...
Hello, Nicholas!

NPN> As for cb, is it a structure? If so, you will have to return an
NPN> IntPtr, and then marshal that back to managed code manually.

It is function pointer ( typedef void (__stdcall *cb)(int a, int b, char
*s[]); )
So it can be a delegate param in the void register_cb(char *description,
cb c); function

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

May 15 '06 #4

P: n/a
Hello Nicholas and Vadym,

I wish you can elaborate more on how to (exactly):

In this case, you would have to map str to an IntPtr, it's essentially
a double pointer to a character, an array of arrays, it would seem (or at
least a reference to an array).

You would have to handle the marshaling of this structure yourself.


I want to easily be able to access the 2d string array from C# w/o a hassle,
so mapping to IntPtr helps?
AFAIK, a char * is mapped to "string" what if char** is mapped to array of
string?

--
Elias
May 16 '06 #5

P: n/a
Hello, lallous!

l> I wish you can elaborate more on how to (exactly):
Info about marshalling char**

( http://groups.google.com.ua/group/mi...e5f398f3bf55b9 )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.