Click to See Complete Forum and Search --> : transfer bitmap over dcom error 104


jeffisen
June 13th, 2001, 08:11 PM
I am having trouble transfering bitmap data via dcom. I keep getting run time error 104 array is fixed or temporarily locked. Any help is appreciated!!

The client is vb:

Dim bits As COMBITMAPTEST2Lib.BitmapFetch
Dim x() As Variant
Private Sub Command1_Click()
ReDim x(1) As Variant
bits.getFile "c:\\download\\test.bmp", x 'error happens here!!
End Sub

Private Sub Form_Load()
Set bits = New COMBITMAPTEST2Lib.BitmapFetch
End Sub

and server is in C++:

IDL part:
[id(1), helpstring("method getFile")] HRESULT getFile([in] BSTR* fileName,
[in,out] VARIANT* theFile);

Method:
STDMETHODIMP CBitmapFetch::getFile(BSTR *fileName, VARIANT *theFile)
{
USES_CONVERSION;//#include "atlconv.h"
char filename[64];
strncpy(filename,"0",sizeof(filename)-1);
strcpy(filename, W2A(*fileName));

BITMAP aBitmap;
HBITMAP aBitmapHandle = (HBITMAP) LoadImage(NULL, filename,IMAGE_BITMAP, 0,
0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
if ( !aBitmapHandle )
return S_FALSE;

::GetObject( aBitmapHandle, sizeof( BITMAP ), &aBitmap );
long bitMapSize = aBitmap.bmWidthBytes * aBitmap.bmHeight;

// create a buffer to hold the bitmap in
LPVOID anLPVoid = new char[bitMapSize];
if ( !anLPVoid )
return S_FALSE; // memory problem

// copy the bits
// the bitmap pointer is offset by the BITMAP
if ( ::GetBitmapBits( aBitmapHandle, bitMapSize, anLPVoid ) == 0 )
return S_FALSE;
aBitmap.bmBits = anLPVoid;

// aBitmap now holds the data
// delete our stuff
::DeleteObject( aBitmapHandle );
HRESULT fRetVal = S_FALSE;
VARIANT var;
VariantInit(&var); //Initialize our variant

//Set the type to an array of unsigned chars (OLE SAFEARRAY)
var.vt = VT_ARRAY | VT_UI1;

//Set up the bounds structure
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].cElements = bitMapSize;
rgsabound[0].lLbound = 0;

//Create an SAFEARRAY
var.parray = SafeArrayCreate(VT_UI1,1,rgsabound);
if(var.parray != NULL)
{
void * pArrayData = NULL;
//Get a safe pointer to the array
SafeArrayAccessData(var.parray,&pArrayData);

//Copy bitmap to it
memcpy(pArrayData, anLPVoid, bitMapSize);

//Unlock the variant data
SafeArrayUnaccessData(var.parray);

*theFile = var; // copy from our variant
VariantClear(&var);
fRetVal = S_OK;
}
delete[] anLPVoid;
return fRetVal;
}