Pass CString and byte array from native C++ to managed C++

G

Guest

Hello,

I have a scenario where my CPP project is not compiled with CLR support,
but some of the CPP files have the /clr option set. In file1.cpp, the /clr
switch is not set. In file2.cpp, the /clr switch is set. file2.h is the
header for file2.cpp, and this header is included in file1.cpp. file2.h
contains method signatures containing only native types, including some
funtions which take a CString parameter or a const pointer to char, e.g.

void MyFunc (const char* param);

Methods in file1.cpp calls the functions declared in file2.h (and
implemented in file2.cpp), including the two with a CString and const pointer
to char parameters. My question is, should I be doing any marshalling of
data at this point (presumably in file1.cpp) when moving from native to
managed code? If so, what type of marshalling should I do and how?

Thank you,
Notre
 
D

David Lowndes

My question is, should I be doing any marshalling of
data at this point (presumably in file1.cpp) when moving from native to
managed code?

No, it should just work seamlessly.

Are you having a problem?

Dave
 
G

Guest

Hi David,

No, I'm not seeing any problem. I just thought that when passing
non-primitive values from native to managed code I would need to do some type
of marshalling.

The compiler does complain when trying to use native & managed types that
don't match. However, the compiler doesn't catch the case where native code
holds a reference to a managed object, which can be garbage collected if not
pinned. I thought there might be something I need to do in the scenario I
described earlier as well (but don't know what)...

Notre
 
D

David Lowndes

Hi David,
No, I'm not seeing any problem.

That's always reassuring :)
I just thought that when passing
non-primitive values from native to managed code I would need to do some type
of marshalling.

I won't pretend to know what goes on since I've not yet needed to
know, but one of the essential points of the C++ compiler was that it
should just work (the old IJW "It Just Works" TLA) with /clr.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top