Creating OLE in-process server COM DLL

I want to create a OLE in-process server COM DLL that communicate with Windows Shell Extentions and change the Icon of a textfile depending on it's size. I have used the IExtractIcon and the procedure seems to work but the icon won't change. I simplified the code and it still doesn't work.

This is the code:


function TIconHandler.GetIconLocation(uFlags: UINT; szIconFile:
PAnsiChar; cchMax: UINT; out piIndex: Integer; out pwFlags: UINT):
// ShowMessage('Hi'); When activated the messeage shows when icons
// are updated; To ensure that the procedure works

szIconFile := 'C:A.ico';
cchMax := 8;
piIndex := 0;
pwFlags := 0;

Result := S_OK;

function TIconHandler.Extract(pszFile: PAnsiChar; nIconIndex: UINT;
out phiconLarge, phiconSmall: HICON; nIconSize: UINT): HResult;
Result := S_FALSE;

What is wrong?

I also have a c++ code doing the same think that i need to convert to pascal, so i would be glad if you could help.

STDMETHODIMP CTxtIconShlExt::GetIconLocation (
UINT uFlags, LPTSTR szIconFile, UINT cchMax,
int* piIndex, UINT* pwFlags )
DWORD dwFileSizeLo, dwFileSizeHi;

// First, open the file and get its length.

hFile = CreateFile ( m_szFilename, GENERIC_READ, FILE_SHARE_READ, NULL,

return S_FALSE; // tell the shell to use a default icon

dwFileSizeLo = GetFileSize ( hFile, &dwFileSizeHi );

CloseHandle ( hFile );

// Check that GetFileSize() succeeded.

if ( (DWORD) -1 == dwFileSizeLo && GetLastError() != NO_ERROR )
return S_FALSE; // tell the shell to use a default icon

// The icons are all in this DLL, so get the full path to the DLL, which
// we'll return through the szIconFile parameter.

TCHAR szModulePath[MAX_PATH];

GetModuleFileName ( _Module.GetModuleInstance(), szModulePath, MAX_PATH );
lstrcpyn ( szIconFile, szModulePath, cchMax );

// Decide which icon to use based on the file size.

ldwSize = ((DWORDLONG) dwFileSizeHi)<<32 | dwFileSizeLo;

if ( 0 == ldwSize )
*piIndex = 0;
else if ( ldwSize < 4096 )
*piIndex = 1;
else if ( ldwSize < 8192 )
*piIndex = 2;
*piIndex = 3;

// pwFlags is set to zero to get the default behavior from Explorer. You
// can set it to GIL_SIMULATEDOC to have Explorer put the icon we return in
// a "dog-eared paper" icon, and use _that_ as the icon for the file.

//*pwFlags = 0;

return S_OK;

STDMETHODIMP CTxtIconShlExt::Extract (
LPCTSTR pszFile, UINT nIconIndex,
HICON* phiconLarge, HICON* phiconSmall,
UINT nIconSize )
return S_FALSE; // Tell the shell to do the extracting itself.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!