Here is a Pelles C example with COM. The application extracts the icon of another executable.
#include <windows.h>
#include <olectl.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
PICTDESC pd;
HICON hIcon;
HMODULE hModule;
IPicture *pBitmap;
IStream *pStream;
LONG pcbSize;
HGLOBAL hGlobal;
LPVOID IconAddr;
HANDLE hFile;
DWORD bWritten;
// load the test executable and the associated icon
hModule = LoadLibrary("Test.exe");
hIcon = LoadIcon(hModule,MAKEINTRESOURCE(100));
// initialize the PICTDESC structure
pd.cbSizeofstruct = sizeof(PICTDESC);
pd.picType = PICTYPE_ICON;
pd.icon.hicon = hIcon;
// create the OLE image
OleCreatePictureIndirect(&pd,&IID_IPicture,TRUE,(void **)&pBitmap);
// create the destination stream to save the icon
CreateStreamOnHGlobal(NULL,TRUE,(LPSTREAM *)&pStream);
// save the icon to the stream
pBitmap->lpVtbl->SaveAsFile(pBitmap,(LPSTREAM)pStream,TRUE,&pcbSize);
// get the address pointing the icon in memory
GetHGlobalFromStream(pStream,&hGlobal);
IconAddr = GlobalLock(hGlobal);
// write the icon to disc
hFile= CreateFile("Smiley.ico",GENERIC_WRITE,0,0,
CREATE_ALWAYS,0,0);
WriteFile(hFile,IconAddr,pcbSize,&bWritten,0);
CloseHandle(hFile);
// release the pointers
pBitmap->lpVtbl->Release(pBitmap);
pStream->lpVtbl->Release(pStream);
return 0;
}
Here is another example modifying the wallpaper.
Great examples, Erol :t
One thing I like about Pelles C is that it just works. No desperate search for the "right" version of header file xyz, no fighting with obscure error messages, just click the *.ppj, press Control B and voilĂ , "Build OK".
Excellent work, Erol. :t Go forward.
Gunther