Passing a 2d array from .NET to COM 
Author Message
 Passing a 2d array from .NET to COM

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



Sat, 08 Jan 2005 17:27:44 GMT  
 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



Tue, 11 Jan 2005 11:24:45 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How To pass 2D String array to VB from VC++ Using Safe array

2. Which 2D array of 2D array addressing method?

3. 2D array of pointers to 2D arrays

4. Passing a 2D SafeArray from VB client to ATL COM component

5. Passing 2D arrays to functions with const.

6. passing 2d arrays by reference

7. Passing 2D arrays to function

8. Passing 2D Arrays to functions

9. 2d array passing

10. Passing 2D Array from Fortran 90 to C

11. pass 2d array to function ?

12. Passing 2D arrays to functions with const.

 

 
Powered by phpBB® Forum Software