
Passing a 2d array from .NET to COM
Hello Anton,
I suggest you have a look at the following articles:
Troubleshooting .NET Interoperability
http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbtchTroubl...
ngNETInteroperability.asp
The section "Multidimensional C-Style Arrays" describes this topic in
detailed. Basically, you should use the ILDASM.exe tool to change the IL
code from:
method public hidebysig newslot virtual
instance void TwoDimArray([in] int32 cDim,
[in] native int aMatrix) runtime managed internalcall
to:
method public hidebysig newslot virtual
instance void TwoDimArray([in] int32 cDim,
[in] int32[,] marshal([+0]) aMatrix) runtime managed internalcall
You may refer the article to get more detailed information.
I hope this is helpful.
Best regards,
Lion Shi, MCSE, MCSD
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
Subject: Passing a 2d array from .NET to COM
Date: Tue, 23 Jul 2002 10:27:44 +0100
Lines: 34
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Newsgroups: microsoft.public.dotnet.languages.vc
NNTP-Posting-Host: 212.21.103.10
Path: cpmsftngxa07!tkmsftngp01!tkmsftngp12
Xref: cpmsftngxa07 microsoft.public.dotnet.languages.vc:12257
X-Tomcat-NG: microsoft.public.dotnet.languages.vc
Hi,
I am trying to pass a 2d array called DataArray into an ATL COM
component
from my C++ Managed Class Library.
int ChannelArray __gc[] = new int __gc[lNumChans];
short DataArray __gc[,] = new short __gc[lNumChans, lNumPoints];
int k,j;
for (k=0; k<lNumChans; k++)
{
ChannelArray[k] = k+1;
}
pTHDC->ReadData(&ChannelArray,lStartPoint, lNumPoints, &DataArray);
The ATL COM component method looks like this
HRESULT ReadData([in] SAFEARRAY (long) *psaChannelArray, [in] long
lStartPoint, [in] long lNumPoints, [in, out] SAFEARRAY (short)
*psaDataArray);
When I try to compile I get the error
c:\1\DAQ_Test_VC_NET\DAQ_Test\DAQ_Test.cpp(64): error C2664:
'QXTHDCLib::THDITClass::ReadData' : cannot convert parameter 4 from
'short
(*) __gc[,]' to 'short (__gc *) __gc[]'
What do I need to change ??
Cheers