473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Explorer context menu problem

Hi, I seem to be having a problem getting a context menu to work in
Explorer. The menu item installs fine, but when I click it a message box
should pop up indicating the command was received and handled.
Unfortunately, nothing occurs.

I suspect that I am doing something wrong with the command ID for the
menu item, but I can't figure out what. After registering my DLL, the
menu item "my context menu" appears if I right-click any file. If I
highlight the menu item with my mouse, the information on Explorer's
status bar reads "Encrypt the selected files". My "GetCommandString()"
implementation is as follows (nothing about encryption, as you can see):
void IContextMenu.GetCommandString(int idCmd, uint uFlags, int
pwReserved, StringBuilder commandString, int cchMax)
{
switch(uFlags)
{
case (uint)GCS.VERB:
commandString = new StringBuilder("...");
break;
case (uint)GCS.HELPTEXT:
commandString = new StringBuilder("...");
break;
}
}
This is obviously suspect. Then, if I click on the item, no message box
appears. I've included the relevant parts of my code below.

This is where I setup the menu, and return an incremented command ID:
int IContextMenu.QueryContextMenu(uint hMenu, uint iMenu, int
idCmdFirst, int idCmdLast, uint uFlags)
{

int id = 0;
if ( (uFlags & 0xf) == 0 || (uFlags & (uint)CMF.CMF_EXPLORE) != 0)
{
uint nselected = Helpers.DragQueryFile(m_hDrop, 0xffffffff, null, 0);
if (nselected == 1)
{
StringBuilder sb = new StringBuilder(1024);
Helpers.DragQueryFile(m_hDrop, 0, sb, sb.Capacity + 1);
m_fileName = sb.ToString();

}
MENUITEMINFO mii = new MENUITEMINFO();
mii.cbSize = 48;
mii.fMask = (uint)MIIM.ID | (uint)MIIM.TYPE | (uint)MIIM.STATE;
mii.wID = idCmdFirst+id;
mii.fType = (uint)MF.STRING;
mii.dwTypeData = "my context menu";
mii.fState = (uint)MF.ENABLED;
Helpers.InsertMenuItem(hMenu, (uint)iMenu++, 1, ref mii);
}

return idCmdFirst+id+1;

}
Here is my "InvokeCommand()" implementation, which should show a simple
message box.
void IContextMenu.InvokeCommand (IntPtr pici)
{

try
{

Type typINVOKECOMMANDINFO = Type.GetType("TagSet.INVOKECOMMANDINFO");
INVOKECOMMANDINFO ici =
(INVOKECOMMANDINFO)Marshal.PtrToStructure(pici, typINVOKECOMMANDINFO);

MessageBox.Show("InvokeCommand");

}
catch(Exception)
{
}
}
Any help would be appreciated. Thanks, JA
Feb 10 '06 #1
2 2731

First of all, you may want to think twice before writing a shell
extension in C# at all. There are good reasons why you shouldn't. See
http://blogs.msdn.com/junfeng/archiv...18/494572.aspx
It's hard to say exactly what's wrong without seeing your interface
and function declarations. But here are some general comments.
void IContextMenu.GetCommandString(int idCmd, uint uFlags, int
pwReserved, StringBuilder commandString, int cchMax)
{
switch(uFlags)
{
case (uint)GCS.VERB:
commandString = new StringBuilder("...");
break;
case (uint)GCS.HELPTEXT:
commandString = new StringBuilder("...");
break;
}
}
The value you assign to commandString here will not be seen by the
caller since it's passed by value.

Type typINVOKECOMMANDINFO = Type.GetType("TagSet.INVOKECOMMANDINFO");


You may want to consider using the typeof operator instead of
Type.GetType here.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 10 '06 #2
Mattias Sjögren wrote:
First of all, you may want to think twice before writing a shell
extension in C# at all. There are good reasons why you shouldn't. See
http://blogs.msdn.com/junfeng/archiv...18/494572.aspx


Thanks, Mattias, for the note. I'll probably switch gears now.

Also, I got it to work after restarting my computer. Explorer had to be
restarted, I think, to release module completely.

JA
Feb 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
5
by: =?Utf-8?B?SmFwZQ==?= | last post by:
im writing a c# console application that copies files chosen from the windows explorer. I chose the files i want to copy and then from the (right key) menu chose my program. the program starts...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.