Passing Safearray from unmanaged C++ to C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roland Moschel

    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("met hod GetData")] HRESULT GetImageData(
    [in,out]SAFEARRAY(int) *ppsa);



    //
    *************** *************** *************** *************** ***********
    STDMETHODIMP GetImageData(SA FEARRAY** 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.CreateIns tance( typeof(int), lengthsArray,
    boundsArray );

    //----------------------------COM Call //

    m_theComServer. GetImageData(re f imagedata);

    //Here I get an exception!!!!!! !!!!!!!!!!!!!!! !!!//
    }


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Passing Safearray from unmanaged C++ to C#

    Roland,

    How are you accessing the unmanaged code? Can you provide a sample?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nick(dot)paldin o=at=exisconsul ting<dot>com

    "Roland Moschel" <momu@gmx.de> wrote in message
    news:rho5ovgvq4 39ch0br6uaekh2p 44tmro1le@4ax.c om...[color=blue]
    > 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("met hod GetData")] HRESULT GetImageData(
    > [in,out]SAFEARRAY(int) *ppsa);
    >
    >
    >
    > //
    > *************** *************** *************** *************** ***********
    > STDMETHODIMP GetImageData(SA FEARRAY** 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....
    > }
    >
    >[/color]
    /*************** *************** *************** *************** ***************
    *************** *************** *****[color=blue]
    >
    >
    >
    >
    >
    > -----------(Managed) C# Client ---------------------------------------
    >
    > private void GetImageData()
    > {
    > int[] lengthsArray = new int[2] { 512,512 };
    > int[] boundsArray = new int[2] { 0 ,0};
    >
    > Array data = Array.CreateIns tance( typeof(int), lengthsArray,
    > boundsArray );
    >
    > //----------------------------COM Call //
    >
    > m_theComServer. GetImageData(re f imagedata);
    >
    > //Here I get an exception!!!!!! !!!!!!!!!!!!!!! !!!//
    > }
    >
    >[/color]


    Comment

    • Roland Moschel

      #3
      Re: Passing Safearray from unmanaged C++ to C#

      Sorry, but I had a little Bug in my Posting...


      -----------(Managed) C# Client ---------------------------------------

      private void GetImageData()
      {
      ...

      m_theComServer. GetImageData(re f data ); <-----------

      ...
      }

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Passing Safearray from unmanaged C++ to C#

        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)paldin o=at=exisconsul ting<dot>com

        "Roland Moschel" <momu@gmx.de> wrote in message
        news:lqo5ovc0oh i5130h9t4hc18ga h3p2p9sta@4ax.c om...[color=blue]
        > Sorry, but I had a little Bug in my Posting...
        >
        >
        > -----------(Managed) C# Client ---------------------------------------
        >
        > private void GetImageData()
        > {
        > ...
        >
        > m_theComServer. GetImageData(re f data ); <-----------
        >
        > ...
        > }[/color]


        Comment

        • Roland Moschel

          #5
          Re: Passing Safearray from unmanaged C++ to C#

          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]"
          <nicholas.paldi no@exisconsulti ng.com> wrote:
          [color=blue]
          >Roland,
          >
          > Are you using VS.NET to create the .NET wrapper? Or are you using
          >TLBIMP, or are you coding the interface by hand?[/color]

          Comment

          Working...