Passing byte array from C# to C++ COM interface 
Author Message
 Passing byte array from C# to C++ COM interface

Hi,

Have a little trouble passing a byte array in C# into a C++ implemented web
service, the C# code is:-

FileStream fs = new FileStream("c:\\work\\temp\\Waremouse.mp3",
FileMode.Open);

BinaryReader Reader = new BinaryReader(fs);
Reader.BaseStream.Seek(0, SeekOrigin.Begin);

long lLength = Reader.BaseStream.Length;
Int32 nLength = System.Convert.ToInt32(lLength);

byte[] bData = Reader.ReadBytes(nLength);
fs.Close();

//**********************************************
//C++ Web Service.......
m_FileServer.UploadFile("Waremouse.mp3", bData);
//**********************************************

The C++ is implement as COM interface, the interface definition is shown
below

__interface IFBFileServerService
{
//Uploads a file onto the web server....
[id(1)] HRESULT UploadFile([in] BSTR bstrFileName, [in] byte* bData);
//Downloads a file from the web server...
[id(2)] HRESULT DownloadFile([in] BSTR bstrFileName, [out, retval] byte**
bData);

Quote:
};

The problem is that an exception is thrown in the client application when  i
try a pass the byte array, i can pass a single byte perfectly fine.....

Cheers for any help



Sun, 31 Oct 2004 17:01:48 GMT  
 Passing byte array from C# to C++ COM interface

Quote:
> Hi,

> Have a little trouble passing a byte array in C# into a C++ implemented
web
> service, the C# code is:-

> FileStream fs = new FileStream("c:\\work\\temp\\Waremouse.mp3",
> FileMode.Open);

> BinaryReader Reader = new BinaryReader(fs);
> Reader.BaseStream.Seek(0, SeekOrigin.Begin);

> long lLength = Reader.BaseStream.Length;
> Int32 nLength = System.Convert.ToInt32(lLength);

> byte[] bData = Reader.ReadBytes(nLength);
> fs.Close();

> //**********************************************
> //C++ Web Service.......
> m_FileServer.UploadFile("Waremouse.mp3", bData);
> //**********************************************

> The C++ is implement as COM interface, the interface definition is shown
> below

> __interface IFBFileServerService
> {
> //Uploads a file onto the web server....
> [id(1)] HRESULT UploadFile([in] BSTR bstrFileName, [in] byte* bData);
> //Downloads a file from the web server...
> [id(2)] HRESULT DownloadFile([in] BSTR bstrFileName, [out, retval] byte**
> bData);

Use VARIANT and SAFEARRAY instead of BYTE*


Sun, 31 Oct 2004 17:46:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing byte array from C# to C++ COM interface

2. COM Interop - How to pass C# uint array to COM interface which takes UINT *pArray

3. Passing in/out,retval arrays from C# code to COM Component developed with C++

4. Passing large byte-array from C# to Delphi DLL

5. Passing an array through the COM interface in ATL

6. BUG in C++: array size passed to a C# code

7. COM/ATL novice:passing object pointers through methods on a COM interface

8. C# interfaces and COM interfaces?

9. How to pass an array of array into a COM object

10. Pass an array of array into a COM object

11. Passing C++ object/value from C++ ATL Interface

12. Passing an Excel COM object to a C++ COM Server

 

 
Powered by phpBB® Forum Software