473,732 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2719
>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
2427
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 usable in C#) whose WriteSample function takes a byte* parameter Do I need to marshal data? I thought I did, so I ran into alot of issues with converting the byte to a string and then, in the MC++ DLL, marshalling that to an IntPtr via...
16
14134
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 byteArray and afterwards see the changes in C#. (if you wanna know more details: the goal is to write the content of an existing char-array in c++ precisely into the passed byteArray, so that after the function has proceded the content of the...
7
8230
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 .Net functionality, i.e. calling methods in managed code. How do I pass CString variables for input and output usage, i.e. providing and retrieving char arrays? Regards, Klaus
0
1660
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 into seems trivial enough, but a solution I've yet to find. I get the following errors when trying to compile may application... error LNK2001: unresolved external symbol "public: virtual class ATL::CStringT<char,class...
3
1549
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 Array?? Does it loop through the array and cast them all and I end up with a big array (This is what I hope will happen)? Or does it simple cast the pointer address and I end up with a small array?? Related question: How do I make sure everything...
5
9837
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 the memory across. Using Marshal.PtrStructure doesn't work - it says my byte() array is not blittable! (byte is a blittable type however). Cannot use Marshal.Copy, because that works the other way around (for mashalling to COM, not from it). ...
1
2553
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 reference: //Managed c++ QueryResult* qr = NULL; ExecuteQuery(1, "abc", qr); //invoke native c++ method passing qr by reference
17
7253
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 to show the array data to the end user. Can I do that? How?
0
2898
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 and invokes a method in it which invokes a method on The command passed from java to .Net is a byte array and the response passed back is also a byte array the C# managed COM object which finally invokes a method on a regular C# managed dll....
0
8773
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.