The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: jdoe on March 02, 2006, 06:28:32 AM

Title: Context menu DLL question
Post by: jdoe on March 02, 2006, 06:28:32 AM
Hi,

I'm writing a context menu handler and I finally, after 2 month of reading and trying and coding, I'm finally close to a functional DLL.
But now that I can get the list of user selected files, using DragQueryFile within IShelExtInit::Initialize, I'm stuck with the folders selection. All I've found is for files selection but how can I get the folders selected.

Thanks
Title: Re: Context menu DLL question
Post by: jdoe on March 02, 2006, 08:28:03 AM
I posted this question 2 hours before I get my answer so forget about it.

2 registry entries were missing in my DllRegisterServer function...

Directory\shellex\ContextMenuHandlers\ProgName / My CLSID
Folder\shellex\ContextMenuHandlers\ProgName / My CLSID

Now it work and I'm so happy.  :dance:

I can go to sleep. It is 3h30 and I go to work in 4 hours.  :dazzled:



Title: Re: Context menu DLL question
Post by: jdoe on March 05, 2006, 02:41:12 AM
Hi,

My new problem with context menu is a lock on my DLL when I want to delete it after unregistering it.

I made test to be sure the refence count is zero so DllCanUnloadNow won't supposed to prevent the DLL from unloading.
After a user logoff and logon, the file can be deleted but if I want to make my program to be removed via uninstaller it can be a problem.

What could be the cause of my DLL file lock or there is a workaround for this problem?

Thanks
Title: Re: Context menu DLL question
Post by: purpleendurer on March 28, 2006, 05:32:32 PM
Hi, jdoe

Do you try command: regsrv32 /u yourdll.dll at first, then delete yourdll.dll?
Title: Re: Context menu DLL question
Post by: P1 on March 28, 2006, 06:45:40 PM
Quote from: jdoe on March 05, 2006, 02:41:12 AMWhat could be the cause of my DLL file lock or there is a workaround for this problem?
Explorer.exe does, as it's a shell program.  1. ReBoot or End Explorer and open a new one.

Regards,  P1  :8)
Title: Re: Context menu DLL question
Post by: jdoe on March 29, 2006, 02:59:04 AM
Sorry guys, I forgot I post this question. I should have replied I had my answer already.

Yes unregistering was done before trying to delete my dll and sure restarting Windows or killing explorer give me delete access to my dll but what I've found after many test is that...

I'm using Ernest Murphy COM macros/prototypes/structures (but not CoLib library) and it seem that using a static Class Factory make, in some circumstance, the dll reference count inacurate when context menus are invoked in many explorer window before the dll got unloaded. And more, I experienced explorer crash problems using my dll and two other one I've found on the web (based on E. Murphy code).
I have solved the problem by coding the Class Factory on a heap (CoTaskMemAlloc) and coding a constructor/destructor based on the very good COM server tutorial of Michael Dunn (http://www.codeproject.com/com/comintro2.asp). Now the reference counter never fail even if I load context menus over and over on multiple explorer window.

For the dll delete problem, it's still there but in fact it's not a problem. When context menu is invoke in an explorer window, it is a child of this window and it is unloaded only the window is closed but when context menu is invoke on the desktop, it stays loaded much longer.
What I've found for this particular behavior is to write an uninstaller and using MoveFileEx API with MOVEFILE_DELAY_UNTIL_REBOOT flag. Et voilà.

If there is some interest on it, I will post the MASM COM implementation for context menu when fully done.


Title: Re: Context menu DLL question
Post by: akane on March 29, 2006, 09:44:56 AM
try void CoFreeUnusedLibraries() api, it internally calls DllCanUnloadNow for DLLs that implement and export that function