Passing Safearray from unmanaged C++ to C#

R

Roland Moschel

Hi there !

I have some Problems to get a SafeArray out of a COM Server written in
(Unmanaged) C++.

From (unmanaged) Visual Basic , everything is ok , but unfortunately
in C# I get an exception.

Can anybody help me ?

Thanks a lot !!

Roland




----------------C++ (unmanaged) COM Server Method--------------------


[id(1206), helpstring("method GetData")] HRESULT GetImageData(
[in,out]SAFEARRAY(int) *ppsa);



//
***********************************************************************
STDMETHODIMP GetImageData(SAFEARRAY** ppsa)
//
***********************************************************************

{
// prepare 2 dimensional safearray
SAFEARRAYBOUND rgsabound[2];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = 512;
rgsabound[1].lLbound = 0;
rgsabound[1].cElements = 512;
*ppsa = SafeArrayCreate(VT_I4, 2, rgsabound);
....
...Filling the SafeArray with the desired Image Data....
}

/**************************************************************************************************************





-----------(Managed) C# Client ---------------------------------------

private void GetImageData()
{
int[] lengthsArray = new int[2] { 512,512 };
int[] boundsArray = new int[2] { 0 ,0};

Array data = Array.CreateInstance( typeof(int), lengthsArray,
boundsArray );

//----------------------------COM Call //

m_theComServer.GetImageData(ref imagedata);

//Here I get an exception!!!!!!!!!!!!!!!!!!!!!!!!//
}
 
N

Nicholas Paldino [.NET/C# MVP]

Roland,

How are you accessing the unmanaged code? Can you provide a sample?
 
R

Roland Moschel

Sorry, but I had a little Bug in my Posting...


-----------(Managed) C# Client ---------------------------------------

private void GetImageData()
{
...

m_theComServer.GetImageData(ref data ); <-----------

...
}
 
N

Nicholas Paldino [.NET/C# MVP]

Roland,

Are you using VS.NET to create the .NET wrapper? Or are you using
TLBIMP, or are you coding the interface by hand?
 
R

Roland Moschel

Hi Nicholas,

I tried both, using the VS.NET and tlbimp with and without /sysarray
But everything didn´t work.


Roland
 

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