473,399 Members | 3,603 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,399 software developers and data experts.

Passing Safearray from unmanaged C++ to C#

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!!!!!!!!!!!!!!!!!!!!!!!!//
}
Nov 15 '05 #1
4 10290
Roland,

How are you accessing the unmanaged code? Can you provide a sample?
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Roland Moschel" <mo**@gmx.de> wrote in message
news:rh********************************@4ax.com...
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!!!!!!!!!!!!!!!!!!!!!!!!//
}

Nov 15 '05 #2
Sorry, but I had a little Bug in my Posting...
-----------(Managed) C# Client ---------------------------------------

private void GetImageData()
{
...

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

...
}
Nov 15 '05 #3
Roland,

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

--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Roland Moschel" <mo**@gmx.de> wrote in message
news:lq********************************@4ax.com...
Sorry, but I had a little Bug in my Posting...
-----------(Managed) C# Client ---------------------------------------

private void GetImageData()
{
...

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

...
}

Nov 15 '05 #4
Hi Nicholas,

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

On Tue, 7 Oct 2003 12:24:00 -0400, "Nicholas Paldino [.NET/C# MVP]"
<ni**************@exisconsulting.com> wrote:
Roland,

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


Nov 15 '05 #5

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

Similar topics

5
by: GeRmIc | last post by:
Hi, I am doing an interop from unmanaged code to C#. How do i pass an ArrayList pointer from an unmanaged code, (structres are easily passed by between C# and C). //This is the C code ...
2
by: Niklas | last post by:
Hi I'm creating a .NET dll, which I will use in VB 6. I have no problem declaring methods, which will take a single Object, String, Integer and so on as a parameter. I manage even to transfer...
7
by: Tim | last post by:
When there is a need to pass some dynamic information between 2 managed assemblies, the "Dictionary object" in Generic form can be used as a method parameter to pass the information. The...
5
by: Maxim | last post by:
Hi all, I'm calling a COM Interface method that returnes SafeArray wrapped into variant. Is it possible to convert it to managed array? Because working with SAFEARRAY directly is a bit...
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...
1
by: Christian Schmidt | last post by:
Hi all, I need to implement an unmanaged function that gets a SafeArray and hands it over to a managed function having the managed array-type. Using MarshalAs I can call unmanaged functions having...
3
by: cskarp | last post by:
I have create a .Net component which exposes an interface with two methods. The first method takes an array of structs as a parameter the other method returns an array of (the same tyoes of) structs....
0
by: eitanyan | last post by:
I am trying to create a Java to .Net interop and the way I am doing it is by creating a C# com object and a native unmanaged c++ dll that uses JNIEnv of java. the java is loading the native c++ dll...
0
skeptics
by: skeptics | last post by:
Trying to pass a SafeArray that i get form Request.BinaryRead Method in classic asp to a c# com interop component. In this thread i found a solution to pass and cast a normal asp safearray in to a c#...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.