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

Passing a byte[] into a COM function that expects a ref byte

Hi.

I am trying to pass in a byte array of characters into a COM function. The
3rd party has already supplied the proper RCW but I cannot seem to cast my
data type into something that will work with their function. Here is the
code.

string xml = GetXML(path);
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bxml = encoding.GetBytes(xml);

IMemoryBlobStream memblobstream = new MemoryBlobStreamClass();
memblobstream.ImportFromMemory(ref bxml, bxml.Length);

The ImportFromMemory function signature is

ImportFromMemory(ref byte, uint)

How might I create the proper datatype contain my xml (string) to the ref
byte that the function requires?

Thanks.
Nov 17 '05 #1
2 4324
Hi Ryan,

"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hi.

I am trying to pass in a byte array of characters into a COM function. The
3rd party has already supplied the proper RCW but I cannot seem to cast my
data type into something that will work with their function. Here is the
code.

string xml = GetXML(path);
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bxml = encoding.GetBytes(xml);

IMemoryBlobStream memblobstream = new MemoryBlobStreamClass();
memblobstream.ImportFromMemory(ref bxml, bxml.Length);

The ImportFromMemory function signature is

ImportFromMemory(ref byte, uint)

How might I create the proper datatype contain my xml (string) to the ref
byte that the function requires?


Suggest passing a reference to the first byte in the array (in essence, the
memory address of the start of the array):

memblobstream.ImportFromMemory(ref bxml[0], bxml.Length);

Regards,
Daniel
Nov 17 '05 #2
Thank you for the quick reply. That did seem to work, but I ran into other
type conversion problems down the road. I was able to take a completely
different track using MS IPersistStream and some 3rd party objects that
implemented IPersistStream.

"Daniel Pratt" <ko******************@hotmail.com> wrote in message
news:uu**************@TK2MSFTNGP14.phx.gbl...
Hi Ryan,

"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hi.

I am trying to pass in a byte array of characters into a COM function. The 3rd party has already supplied the proper RCW but I cannot seem to cast my data type into something that will work with their function. Here is the
code.

string xml = GetXML(path);
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bxml = encoding.GetBytes(xml);

IMemoryBlobStream memblobstream = new MemoryBlobStreamClass();
memblobstream.ImportFromMemory(ref bxml, bxml.Length);

The ImportFromMemory function signature is

ImportFromMemory(ref byte, uint)

How might I create the proper datatype contain my xml (string) to the ref byte that the function requires?
Suggest passing a reference to the first byte in the array (in essence,

the memory address of the start of the array):

memblobstream.ImportFromMemory(ref bxml[0], bxml.Length);

Regards,
Daniel

Nov 17 '05 #3

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

Similar topics

0
by: BB | last post by:
I am calling my C++ function (in a DLL) from a python script as follows: _dllcall('add','ll','l',(var1,var2)) This works fine if the 2 parameters accepted by the function are normal "long"...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
2
by: Jeff Stewart | last post by:
I wrote the following function to accomodate a legacy driver function that only accepted VB6-style strings. The driver expects a string that represents an array of binary data to be sent over USB....
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...
7
by: =?Utf-8?B?YmVyaWNr?= | last post by:
New to this, I used to pass an array like this function BytesToString(byref myarray() as byte, somethingelse as long) as long and m = BytesToString(fooBar(), bluenose) This would send...
11
by: Bob Yang | last post by:
Hi, I have this in C++ and I like to call it from c# to get the value but I fail. it will be good if you can give me some information. I tried it in VB.net it works but I use almost the same way as...
8
by: cpptutor2000 | last post by:
Could some C guru please help me? I have a function that takes as an argument a pointer to an array of unsigned chars (basically a hex representation of a dotted decimal IP address). When I print...
13
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the...
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: 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: 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
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,...
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...
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...

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.