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

R

Ryan Taylor

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.
 
D

Daniel Pratt

Hi Ryan,

Ryan Taylor said:
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
 
R

Ryan Taylor

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 said:
Hi Ryan,

Ryan Taylor said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top