473,770 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to pass binary data from C# stream to fcn in Managed C++

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 StringToHGlobal Ansi, then casting its ToPointer() to a char*, and finally doing a memcpy of the data from char* to the byte* buffer. I guess I was trying to go from a byte[] to a byte*

If someone can point me in the right direction please, or even be so kind as to explain what I need to do? I've been spending so much time researching these newsgroups but I'm just learning bits and pieces here and there. Thanks in advance!!!
Nov 17 '05 #1
1 3847
> 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 StringToHGlobal Ansi, then casting its
ToPointer() to a char*, and finally doing a memcpy of the data from char* to
the byte* buffer. I guess I was trying to go from a byte[] to a byte*.
If someone can point me in the right direction please, or even be so kind

as to explain what I need to do? I've been spending so much time
researching these newsgroups but I'm just learning bits and pieces here and
there. Thanks in advance!!!
Pin the array. That would be the easies't way around it:

Byte buffer __gc[] = yourBufferFromC #Code;
Byte __pin* umBuffer = &buffer[0];

// now pass umBuffer to your unmananged function.

Now, you shouldn't normally do this if you expect the function you're
calling to keep the array for later use or anything, because as soon as the
__pin pointer goes out of scope, the memory will be released, and the next
GC cycle might just move the memory around, causing eventually an access
violation.

If this is your case, then I suggest using Marshal::Copy() to create a copy
of the array into an unmanaged memory buffer.
--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2

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

Similar topics

14
7903
by: Steven T. Hatton | last post by:
I'm trying to write a program like hexel. I guess I could fish out the source for hexel and look at that, but for now I'm trying to figure out how I can do with with std::stringstream and std::string. I had something working with std::string. I simply treated it as an STL container, and iterated over its elements. The results were a bit confusing to me. Some of the stuff was printing out as 1 or 2 characters hex numbers, as I...
1
2428
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...
2
1375
by: Peter Steele | last post by:
I have a managed C++ project that contains a simple structure: struct { <multiple members> } mydata; I want to write the contents of this structure out to disk retaining the exactly binary data without any additional header information, and of course be able to later read it back in. What's the best way to accomplish this?
2
1410
by: Feng | last post by:
Hi, I need a VB.Net function that reads in a stream of binary data coming in from a legacy data source. The data are actually hex numbers in binary format but the problem is that I don't know how handle it in my VB program. All I need is to be able to transform those bytes into hex, such as 'oxF9', but right now all I can see are un-readable binary data. What is the best way to do this kind of work? Thanks
6
2731
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios, every now and then the client would timeout and have to re-initiate the request... TIA!
4
8323
by: dirtside | last post by:
I've search far and wide for an answer, so forgive me if this is a stupid question. (Well, it probably is.) Consider the following JavaScript: var foo = new Image(); foo.src = "http://some.server.com/some_filename.gif"; Now, the browser will retrieve 'some_filename.gif' from some.server.com and put it into the object foo. What I want to do is then subsequently
2
1770
by: Michael Kolias | last post by:
Hello everyone and happy holidays! I have a situation where I want to parse on the fly a stream of binary data. I am developing an httpmodule for asp.net for file uploading. I do not whant to use the built-in control because it's inadequate. In theory I would use a que and feed data as it comes in and then have a parser that extracts the data from the que, parse them and do whatever.
0
1185
by: Gargi K | last post by:
I want to create a new xml document of the type Msxml.DOMDocument.4.0 Actaully In have to transfer some binary data in xml which requires to specify the dataType member of the xml node( which is not present in simple xml document). I am new to xml. Kindly help.
3
5404
by: Willy Stevens | last post by:
Hello, In my application I have to read sometimes quite big chunk of binary data. I have a buffer which default size is 32000 bytes. But how could I read binary data that exceeds 32000 bytes? Is allocating more size to buffer and copy data that exceeds 32000 bytes at tail the only way or are there any other possibilities?
20
9449
by: tomPee | last post by:
Hi, I've bumbed into a slight problem now, and I just don't seem to know how to fix it. What I want to do is the following: Send over a socket: 1. Number of files to be send (not as an integer, just as a string) then for each file to be send: 2. Length of Filename (again as a string) 3. Filename 4. File as binary data.
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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
10101
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...
0
9906
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
8933
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
5354
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.