Howdy, Stranger!

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

Categories

Creating OLE in-process server COM DLL

arash82arash82 Member Posts: 106
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:
[code]

...

function TIconHandler.GetIconLocation(uFlags: UINT; szIconFile:
PAnsiChar; cchMax: UINT; out piIndex: Integer; out pwFlags: UINT):
HResult;
begin
// 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;
end;

function TIconHandler.Extract(pszFile: PAnsiChar; nIconIndex: UINT;
out phiconLarge, phiconSmall: HICON; nIconSize: UINT): HResult;
begin
Result := S_FALSE;
end;[/code]

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.

[code]
STDMETHODIMP CTxtIconShlExt::GetIconLocation (
UINT uFlags, LPTSTR szIconFile, UINT cchMax,
int* piIndex, UINT* pwFlags )
{
DWORD dwFileSizeLo, dwFileSizeHi;
DWORDLONG ldwSize;
HANDLE hFile;

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

hFile = CreateFile ( m_szFilename, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );

if ( INVALID_HANDLE_VALUE == hFile )
{
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;
else
*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 = GIL_SIMULATEDOC;
//*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.
}[/code]

Comments

  • Justin BibJustin Bib USAMember Posts: 0

    ________ { http://forcoder.org } free video tutorials and ebooks about < Visual Basic .NET C Java R JavaScript Visual Basic Go Swift PL/SQL Perl Delphi Objective-C Ruby Scratch C# PHP C++ Python MATLAB Assembly F# D ML Crystal Erlang Bash Transact-SQL Hack LabVIEW VBScript Clojure Alice Ada Fortran Scheme Rust COBOL ABAP Kotlin Julia Prolog Scala Awk Lua SAS Apex Lisp FoxPro Logo Dart /> ____________

Sign In or Register to comment.