[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

String conversion b/t C# and native C++

mtv

1/31/2007 8:40:00 PM

This question is probably already out there, but there's none I could find
for my scenario.

My C++ code has: CFunction(const char* data);
My C# code references C++ dll and needs to call this function. What data
type in C# is it for "data"? I think it will work w/ sbyte*, but then, how do
I create such datatype in C#?

Any working solutions are appreciated.

Thanks.



--
Your 2 cents are worth $milion$. Thanks.
1 Answer

mtv

1/31/2007 9:22:00 PM

0

Maybe it's worth to notice that I use IJW method to create a __gc C++ wrapper
around native C++ class. Then, I reference the C++ managed dll (wrapper) from
my C# project. So:

C# references and calls C++ wrapper (Managed) that in turns calls native C++
object (__nogc in the same dll w/ C++ wrapper class). In terms of calling
procedure:

__nogc C++ class has: public CallingFunction(char* data);
__gc C++ class has: (1) reference to __nogc class and (2) public
ManagedCallingFunction(char* data) { pUnmanaged->CallingFunction(data); }
C# class: MyManagedObj.ManagedCallingFunction(dataParam).

What data type of dataParam should it be? Compiler seems not to like string
and ask for sbyte*. How do I create sbyte* or anything compatible?

Thanks.


--Your 2 cents are worth $milion$. Thanks.


"mtv" wrote:

> This question is probably already out there, but there's none I could find
> for my scenario.
>
> My C++ code has: CFunction(const char* data);
> My C# code references C++ dll and needs to call this function. What data
> type in C# is it for "data"? I think it will work w/ sbyte*, but then, how do
> I create such datatype in C#?
>
> Any working solutions are appreciated.
>
> Thanks.
>
>
>
> --
> Your 2 cents are worth $milion$. Thanks.