473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pass a c# array to a c++ com lib (newB)

hey,

first thanks for looking. I think this should be easy. I have a com
DLL (in C++) that has this struct:
[export]
struct IdxTimestampedWord {
BSTR word;
__int64 timestamp;
};

and this function:

__interface ISFClass : IUnknown
{
[helpstring("method DoThing")]
HRESULT DoThing( [in, size_is(TranscriptArraySize)] IdxWord
TranscriptWord[], [out,
size_is(TranscriptArraySize)]IdxTimestampedWord AlignedTranscript[]);
};
I added a referance to the DLL in my c# project and I have this
code...

MyNameSpace.IdxTimestampedWord[] obSrc = null;
MyNameSpace.IdxTimestampedWord[] obDst = null;
// fill obSrc

// call the function

MyNameSpace.MyClass myC= new MyNameSpace.MyClass();

myC.doThing(ref obSrc, out obDst)
and I get:

cannot convert from 'ref MyNameSpace.IdxTimestampedWord[]' to 'ref
MyNameSpace.IdxTimestampedWord'

So my question is what to I need to do to send the array I made in C#
to the COM object?

thanks,
mike
Nov 15 '05 #1
3 1389
So my question is what to I need to do to send the array I made in C#
to the COM object?


See this page from the docs

http://msdn.microsoft.com/library/en...opassembly.asp

especially the section "Conformant C-Style Arrays".

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
Ok.

so this is what I did

i ran tlbimp, then ildasm like it told me too, and edited

this:
..method public hidebysig newslot virtual
instance void DoThing( [in] valuetype Alignment.IdxWord& TranscriptWord,
[out] valuetype Alignment.IdxTimestampedWord&
AlignedTranscript) runtime managed internalcall

to this:

..method public hidebysig newslot virtual
instance void DoThing([in] valuetype Alignment.IdxWord[] marshal([])
TranscriptWord,
[out] valuetype Alignment.IdxTimestampedWord[]
marshal ([]) AlignedTranscript
) runtime managed internalcall
** note when I ran with this DLL it failed to load my class, so I also edited
.method public hidebysig newslot virtual abstract to reflect the same as above.

then I ran ilsam with the /DLL option (not in doc) which made a new dll

I call the funciton from c# like this
Alignment.IdxTimestampedWord[] obIN = new Alignment.IdxTimestampedWord[10];
Alignment.IdxTimestampedWord[] obOut = new Alignment.IdxTimestampedWord[10];

DoThing(obIn,obOut);
And I get System.NullReferenceException. Did I do something wrong?
Nov 15 '05 #3
** note when I ran with this DLL it failed to load my class, so I also edited
.method public hidebysig newslot virtual abstract to reflect the same as above.
Yep, you have to change all occurances of the method.

And I get System.NullReferenceException. Did I do something wrong?


Not that I can see, it looks correct to me. Sorry, I'm not sure what
causes the exception. I'll do some testing and see if I can reproduce
it.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4

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

Similar topics

7
36898
by: Cory Toms | last post by:
Hey All, I have question about the best way to go about doint this: SqlDataReader _dr=components.getItems(); fooclass _myarray = new fooclass; //create new array of my class int i=0; ...
3
1524
by: HateSpam | last post by:
I am defining a class that has, as a member, an array of another user-defined class. private mBoard as CBoardPosition() The problem comes when I attempt to size the array, it should be an 8x8...
0
1378
by: gchandran | last post by:
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...
27
2269
by: pkirk25 | last post by:
Assume an array of structs that is having rows added at random. By the time it reaches your function, you have no idea if it has a few hundred over over 10000 rows. When your function recieves...
4
3431
by: De_Kabal | last post by:
I'm trying to bind a 12x16 array to a repeater to display the information in a table to have certain format. Right now all it does is display all the array elements on individual rows. Does anyone...
14
20368
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
3
2478
by: QQ | last post by:
I have one integer array int A; I need to pass this array into a function and evaluate this array in this function how should I pass? Is it fine? void test(int *a)
1
2427
by: megh55555 | last post by:
Hi , how can we pass arguments to a function located in xyz.py file using the DOS command Prompt. I know its very easy to pass using the python command line but m finding it impossible to do...
3
2255
by: The Midnighter | last post by:
Alright, so basically here's what's supposed to happen. It's an Airline reservation system, basically taking a row of 10 seats, 1 isle, 1 window. Yes, there's only one row. xD So 5 seats isle, 5...
0
7271
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,...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
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
5570
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,...
1
4998
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...
0
4666
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
1498
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 ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
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.