The MASM Forum

Projects => Poasm => Pelle's C compiler and tools => Topic started by: Vortex on May 11, 2013, 06:39:06 PM

Title: COM with Pelles C
Post by: Vortex on May 11, 2013, 06:39:06 PM
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;
}
Title: Re: COM with Pelles C
Post by: Vortex on May 11, 2013, 08:07:05 PM
Here is another example modifying the wallpaper.
Title: Re: COM with Pelles C
Post by: jj2007 on May 11, 2013, 08:25:55 PM
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".
Title: Re: COM with Pelles C
Post by: Gunther on May 11, 2013, 09:17:09 PM
Excellent work, Erol.  :t Go forward.

Gunther