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

best way to pass block of data from C# to C++?

Hi. I'm new here and I don't think I'm in Kansas anymore...

What's the best / most efficient way to marshal a buffer of pixel
data from a C# COM object up to a C++ application? Anybody got a
"short but complete program" to illustrate it?
Nov 16 '05 #1
2 2306
Hey Doug,

1/ You can try to pin the memory. For instance if you have a byte[], you can
pin it so it doesn't get moved around in memory.

2/ Alternatively you can use the GCHandle class to pin the memory.

3/ You could use AllocCoTaskMem & FreeCoTaskMem methods in the Marshal class
(but I've never tried).

4/ Use another way to allocate memory than .NET memory manager. For
instance, link to VirtualAlloc and VirtualFree in kernel32.dll

5/ Have your C++ component give a pointer to a memory block which can be
filled by the C# component.

HTH,
Tom Tempelaere.

"Doug Taylor" wrote:
Hi. I'm new here and I don't think I'm in Kansas anymore...

What's the best / most efficient way to marshal a buffer of pixel
data from a C# COM object up to a C++ application? Anybody got a
"short but complete program" to illustrate it?

Nov 16 '05 #2
I forgot to mention that the app is VC6, and not VC++.NET.
Thus, is your suggestion #5 really possible?

The VC6 app will be allocating the buffer, then the C# object
will fill the buffer (or a copy of the buffer if that's the only
way),
and then return it back to the VC6 app.

Doug

"TT (Tom Tempelaere)" wrote:
1/ You can try to pin the memory. For instance if you
have a byte[], you can pin it so it doesn't get moved
around in memory.

2/ Alternatively you can use the GCHandle class to pin
the memory.

3/ You could use AllocCoTaskMem & FreeCoTaskMem methods
in the Marshal class (but I've never tried).

4/ Use another way to allocate memory than .NET memory
manager. For instance, link to VirtualAlloc and
VirtualFree in kernel32.dll

5/ Have your C++ component give a pointer to a memory
block which can be filled by the C# component.

HTH, Tom Tempelaere.

"Doug Taylor" wrote:
What's the best / most efficient way to marshal a buffer
of pixel data from a C# COM object up to a C++
application? Anybody got a "short but complete
program" to illustrate it?

Nov 16 '05 #3

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

Similar topics

5
by: Ant | last post by:
hi, I'm now using C#. Seeing as though you can declare & initialize or pass a value to a variable on the same line as the declaration, is it still best practice to group all the variables together...
4
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
11
by: Tom | last post by:
I am planning on adding a Preferences form to my application and using the Property Grid to display the preferences to the user. What do you think would be the best way to save these preferences...
2
by: dbuchanan | last post by:
Hello, Windows forms & database What are the considerations when choosing how to display reference information from the calling form? What is recommended? Table1 is the parent of Table2. ...
2
by: Anil Pundhir | last post by:
What is the best way to pass data to a web service. The client(to send data) has .net environment and also the server on which the web service is hosted also has the .net environment. Should I...
4
by: David Pinx | last post by:
Greetings, I will be developing an application that will have two versions, a web application to be deployed at the client side and a windows application. The question is, what would be the...
5
by: Dave A | last post by:
I have an application that does lots of socket communications all asynchronously via the TcpClient class. The code has been working 99.9999% of the time (yeah one of those bugs) but occasionally...
20
by: Joe | last post by:
Is any one charting packing considered to be the "best"? We've used ChartFX but wasn't too happy about the way data had to be populated along with some other issues which slip my mind right now and...
8
by: Edson Manoel | last post by:
I have some C++ unmanaged code that takes std::string& arguments (as reference), and fills them (possibly growing the string). I want to call this code through PInvoke (DllImport), possibly using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.