Can anyone help me with adding images to an ImageList control, using an InvokeHelper call?
This is the type information I pulled for the Add method of the ListImages interface:
[id(0x00000002), helpstring("Adds a ListImage object to a ListImages collection and returns a reference to the created object."), helpcontext(0x0003347a)]
IImage* Add(
[in, optional] VARIANT* Index,
[in, optional] VARIANT* Key,
[in, optional] VARIANT* Picture);
In my code, I have this:
COleDispatchDriver rootDisp[1];
VARIANT Index;
VARIANT Key;
VARIANT Picture;
LPDISPATCH NewPic;
static BYTE params[] = VTS_VARIANT VTS_VARIANT VTS_VARIANT;
HBITMAP hBmp;
CBitmap bm;
// Load the bitmap image from disk
hBmp = (HBITMAP)::LoadImage(NULL, "image1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
bm.Attach(hBmp);
// Add image to the list
VariantInit(&Index);
VariantInit(&Key);
VariantInit(&Picture);
Index.vt = VT_I2;
Index.iVal = 1;
Key.vt = VT_BSTR;
Key.bstrVal = "Image1".AllocSysString();
Picture.vt = VT_VARIANT | VT_BYREF;
Picture.pvarVal = (VARIANT*)&bm;
// (Note... rootDisp[curRootIndex] already has dispatch for ListItems property...)
rootDisp[curRootIndex].InvokeHelper(0x02, DISPATCH_METHOD,
VT_DISPATCH, (void*)&NewPic, params, &Index, &Key, &Picture);
I've confirmed that the bitmap is being loaded, and that I have a valid handle to the bitmap object. Also, I know that rootDisp[curRootIndex] has a valid dispatch pointer for the ListImages property, since I can successfully use it to show the image count or remove images.
I'm not sure if parameters should be passed in reverse order. I've tried both ways, and I always get a runtime error when the Add method is called.
I think the method is expecting a pointer to a variant for the Picture parameter. But I'm not sure what this variant should contain. I'm guessing it should be a pointer to the bitmap object.
Any help would be appreciated!
This is the type information I pulled for the Add method of the ListImages interface:
[id(0x00000002), helpstring("Adds a ListImage object to a ListImages collection and returns a reference to the created object."), helpcontext(0x0003347a)]
IImage* Add(
[in, optional] VARIANT* Index,
[in, optional] VARIANT* Key,
[in, optional] VARIANT* Picture);
In my code, I have this:
COleDispatchDriver rootDisp[1];
VARIANT Index;
VARIANT Key;
VARIANT Picture;
LPDISPATCH NewPic;
static BYTE params[] = VTS_VARIANT VTS_VARIANT VTS_VARIANT;
HBITMAP hBmp;
CBitmap bm;
// Load the bitmap image from disk
hBmp = (HBITMAP)::LoadImage(NULL, "image1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
bm.Attach(hBmp);
// Add image to the list
VariantInit(&Index);
VariantInit(&Key);
VariantInit(&Picture);
Index.vt = VT_I2;
Index.iVal = 1;
Key.vt = VT_BSTR;
Key.bstrVal = "Image1".AllocSysString();
Picture.vt = VT_VARIANT | VT_BYREF;
Picture.pvarVal = (VARIANT*)&bm;
// (Note... rootDisp[curRootIndex] already has dispatch for ListItems property...)
rootDisp[curRootIndex].InvokeHelper(0x02, DISPATCH_METHOD,
VT_DISPATCH, (void*)&NewPic, params, &Index, &Key, &Picture);
I've confirmed that the bitmap is being loaded, and that I have a valid handle to the bitmap object. Also, I know that rootDisp[curRootIndex] has a valid dispatch pointer for the ListImages property, since I can successfully use it to show the image count or remove images.
I'm not sure if parameters should be passed in reverse order. I've tried both ways, and I always get a runtime error when the Add method is called.
I think the method is expecting a pointer to a variant for the Picture parameter. But I'm not sure what this variant should contain. I'm guessing it should be a pointer to the bitmap object.
Any help would be appreciated!