Hello Everybody,

I have a big problem.
I job with image processing in C++, and now i need transfer image array VB
to DLL VC++.

My Dll use others Dlls. This Dlls util VARIANT type to transfer image array.

In Microsoft site help, have one example to transfer bytes array ( VB to
ActiveX do in VC++)

Code example to transform bytes array in VARIANT type:

The problem is :
        - in VB we create bytes array (512 bytes)
        - in VC++ the bytes array is larger then 512 bytes.

Please help me.

   void CDllDermalogMidApp::VBtoVCtoVB(const VARIANT FAR& Buffer)
   {
      // Verify the Variant contains SafeArray of Bytes
      if (Buffer.vt == (VT_ARRAY | VT_UI1)) {
         long Dims = SafeArrayGetDim(Buffer.parray);
         long UpperBounds;
         long LowerBounds;

         if (Dims == 1) {
            SafeArrayGetLBound(Buffer.parray, 1, &LowerBounds);
            SafeArrayGetUBound(Buffer.parray, 1, &UpperBounds);

            // Use LowerBounds and UpperBounds to force a specific
            // Array size as shown here or they can be used to
            // dynamically create the buffer.
            if ((LowerBounds == 0) && (UpperBounds == 512)) {
               // Reference pointer for accessing the SafeArray
               unsigned char* buff;
               // Variable to store the data from the SafeArray
               // could be a global variable or member of CBinDataCtrl
               // Shown as a local variable for demonstration purpose only
               unsigned char m_abBinaryData[512];
               SafeArrayAccessData (Buffer.parray, (void**)&buff);
               for (int i = 0; i < 512; i++) {
                  // Handle the binary data in the buffers
                  // Copying the data passed from VB to VC.
                  m_abBinaryData[i] = buff[i];

                  // Modifying the data to be passed back to VB
                  buff[i] = 0;
               }
               SafeArrayUnaccessData (Buffer.parray);
               return;
            }
         }
      }
      AfxMessageBox ("Invalid parameter passed in VBtoVC method.\n The array
may only have a single dimension.\n The array must contain 512 bytes.");
   }


Luciano Lucas de Oliveira Junior
Analista de Sistemas - Detran / Montreal Informática
Desenvolvimento - (21) 3399-1645 Ramal 35
Celular : (21) 9526-3979

Reply via email to