473,387 Members | 1,611 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,387 software developers and data experts.

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

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
Oct 26 '06 #1
4 2709
>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
Oct 26 '06 #2
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
Oct 26 '06 #3
>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
Oct 26 '06 #4
Hello,

Please check if the post at:
http://blogs.msdn.com/gpalem/archive...-c-to-net.aspx
is useful.

P.Gopalakrishna.
http://www.geocities.com/krishnapg/

"Notre Poubelle" wrote:
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
Jun 18 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wbaccay | last post by:
I have a byte of binary data received from a NetworkStream (C# code) that I need to pass to the IWMWriter object in a DLL written in Managed extensions for C++ (since the Windows Media SDK is not...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
7
by: Klaus Bonadt | last post by:
I have an existing VC6 application using the MFC. I am able to pass CString and other parameters from such a VC6 dll to an unmanaged MFC dll (compiled in Visual Studio .NET). Now I want to use...
0
by: Tony | last post by:
I have a managed C++ Console Application, and C++ Windows Forms application where I am trying to use an unmanaged header/lib file combo that exposes a class for functionality... The trouble I run...
3
by: Fireangel | last post by:
I want to cast a class into a byte array. I've seen some examples of this floating around, but they all have simple data members. What happens if I cast something that has a ArrayList or an...
5
by: Robin Tucker | last post by:
I need to marshal an IntPtr (which I've got from GlobalLock of an HGLOBAL) into a byte array. I know the size of the array required and I've got a pointer to the blob, but I can't see how to copy...
1
by: Scott McFadden | last post by:
What is the proper way to pass pointers by reference from managed c++ calls to native c++ calls? In managed C++, I have a pointer to an array of structures, that I pass to a native c++ method by...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: eitanyan | last post by:
I am trying to create a Java to .Net interop and the way I am doing it is by creating a C# com object and a native unmanaged c++ dll that uses JNIEnv of java. the java is loading the native c++ dll...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.