Converting byte [] to SAFEARRAY

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mannie
    New Member
    • Jul 2007
    • 7

    Converting byte [] to SAFEARRAY

    Hi!

    In my C++ application I need to use COM object (written in c#). The cooperation of COM and C++ application works fine, but I have a problem with calling one of C# methods.

    MyComObject::Co mClass InterfacePtr p (__uuidof(MyCom Object::ComClas s ));
    _com_ptr = p;
    _com_ptr->ProcessFile(_b str_t a_strNewFileNam e, SAFEARRAY * a_arrFileConten ts )

    the original C# method is defined as follows:
    public string ProcessFile(str ing a_strNewFileNam e, byte[] a_arrFileConten ts)

    the byte array represents the content of the file red from C++ level.

    I need a piece of code showing how to read a content of the file and save this in a SAFEARRAY object (so as to call the ProcessFile method)

    Would anyone help me to solve this problem,please? ?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    A SAFEARRAY is just a struct that contains your string. It also constains the number of dimensions and the sizes of thse dimensions.

    Generally, you use the VARTYPE of a VARIANT when you call CreateSafeArray Vector. This will create a SAFEARRAY and return a pointer to it.

    Comment

    • Mannie
      New Member
      • Jul 2007
      • 7

      #3
      Originally posted by weaknessforcats
      A SAFEARRAY is just a struct that contains your string. It also constains the number of dimensions and the sizes of thse dimensions.

      Generally, you use the VARTYPE of a VARIANT when you call CreateSafeArray Vector. This will create a SAFEARRAY and return a pointer to it.

      Thanks weaknessforcats , but because I'm not very skilled C++ programmer (as I've written I need to call COM method), please help me to write a piece of code, that would create an argument of SAFEARRAY * type (content of some file), which is essential to call the method:


      ProcessFile_2 ( _bstr_t a_strFileName, SAFEARRAY * a_arrFileConten ts )

      The definition of SAFEARRAY structure is as follows:

      typedef struct tagSAFEARRAY
      {
      USHORT cDims;
      USHORT fFeatures;
      ULONG cbElements;
      ULONG cLocks;
      PVOID pvData;
      SAFEARRAYBOUND rgsabound[ 1 ];
      } SAFEARRAY;

      Comment

      Working...