473,480 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to pass an array of objects from C# to C++? (newB)

Hello,

I am developing a DLL using C# . I am using VS 2005 for this. The
component will expose few API's. One of the API performs certain
operations and needs to return an array of objects (class defined in
the C# dll). I have a C++ executable which instantiates the C# DLL and
invokes the API's.

I am using SAFEARRAY to pass the array of object from the DLL to C++
executable. I am able to successfuly successfully invoke the method and
get a filled array.

Problem:
Now I am not sure how to get the required object from the SAFEARRAY?

Source code snippet:

C# DLL:
------------------------------------------------------------------------------------------------------------------------------
public interface ICSharp2CPlus
{
void Interface_getResourceData(IdentificationSpecifier
ParentIdentificationSpecifier, SelectedMetadata
SelectedMetadata,[In,Out, MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType =
VarEnum.VT_USERDEFINED)] ref ResourceSpecifier[] res);

}

public class MyClass : ICSharp2CPlus
{
public ContentRepositoryService service;

public MyClass()
{
service = new ContentRepositoryService();
}

public void Interface_getResourceData(IdentificationSpecifier
ParentIdentificationSpecifier, SelectedMetadata
SelectedMetadata,[In,Out, MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType =
VarEnum.VT_USERDEFINED)] ref ResourceSpecifier[] res)
{
// service.getChildren successfully returns an array of
ResourceSpecifier
res = service.getChildren(ParentIdentificationSpecifier,
SelectedMetadata);
}

}

public partial class ResourceSpecifier
{
private Resource resourceField;

/// <remarks/>
public Resource Resource
{
get
{
return this.resourceField;
}
set
{
this.resourceField = value;
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------
C++ Invocation
// The Main Interface
ICSharp2CPlus* CSharpInterface = NULL;

// Initializes the COM library on the current thread and identifies
the
// concurrency model as single-thread apartment (STA).
CoInitialize(NULL);
//Instantiate the COM object in the appropriate ServiceObject
apartment
if
(FAILED(CoCreateInstance(CLSID_MyClass,NULL,CLSCTX _INPROC_SERVER,IID_ICSharp2CPlus,reinterpret_cast< void**>(&CSharpInterface))))
return 0;

// Create the pointer to the SAFEARRAY
SAFEARRAY *pSafeArray = NULL;

// Finally call the getchildren method to get the children
if(FAILED(CSharpInterface->Interface_getResourceData(IIDSpecifier,NULL,&pSaf eArray)))
return 0;
----------------------------------------------------------------------------------------------------------------------------------

Now how do I get ResourceSpecifier objects from the pSafeArray?

Please give me some pointers to resolve this!

Girish

Jun 2 '06 #1
0 1377

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

Similar topics

5
3110
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
3
1387
by: madmike | last post by:
hey, first thanks for looking. I think this should be easy. I have a com DLL (in C++) that has this struct: struct IdxTimestampedWord { BSTR word; __int64 timestamp;
1
2309
by: Williams.sam | last post by:
I am wondering if there is a way (maybe via Marshalling ) to pass an array of Objects of some C# defined class to VB. I am already launching a C# form from VB with simple call backs using a basic...
4
145841
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
1
1467
by: Carlos Villaseñor M. | last post by:
Hi everybody! I finally have success implementing my first DLL function, I have exported a C++ function with a DLL using the "Declare" statement in Basic, but now I have a doubt, how can I to...
2
2265
by: openuser | last post by:
Hi, I'm just wondering: when I have class A which owns a non-heap based vector which stores pointers to heap based object B (these objects are also owned by class A), and the object instance of the...
3
1273
by: weird0 | last post by:
i am trying to add nodes to a node dynamically ... and assign its proerties to a node objects stored inside the array.... when the ShapeAdded event is fired... ...inside the if block... ...
3
1834
by: nkyaelly | last post by:
Hi People, I am getting frustrated with the way Python handles its dictionary. I have a scenarion where a class A is stored in a dictionary. The class A contains a dictionary B as a field as...
0
7046
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
7048
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
7088
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
6956
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
5342
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
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.