473,722 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "GetCommandStri ng()"
implementation is as follows (nothing about encryption, as you can see):
void IContextMenu.Ge tCommandString( int idCmd, uint uFlags, int
pwReserved, StringBuilder commandString, int cchMax)
{
switch(uFlags)
{
case (uint)GCS.VERB:
commandString = new StringBuilder(" ...");
break;
case (uint)GCS.HELPT EXT:
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.Qu eryContextMenu( uint hMenu, uint iMenu, int
idCmdFirst, int idCmdLast, uint uFlags)
{

int id = 0;
if ( (uFlags & 0xf) == 0 || (uFlags & (uint)CMF.CMF_E XPLORE) != 0)
{
uint nselected = Helpers.DragQue ryFile(m_hDrop, 0xffffffff, null, 0);
if (nselected == 1)
{
StringBuilder sb = new StringBuilder(1 024);
Helpers.DragQue ryFile(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.STAT E;
mii.wID = idCmdFirst+id;
mii.fType = (uint)MF.STRING ;
mii.dwTypeData = "my context menu";
mii.fState = (uint)MF.ENABLE D;
Helpers.InsertM enuItem(hMenu, (uint)iMenu++, 1, ref mii);
}

return idCmdFirst+id+1 ;

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

try
{

Type typINVOKECOMMAN DINFO = Type.GetType("T agSet.INVOKECOM MANDINFO");
INVOKECOMMANDIN FO ici =
(INVOKECOMMANDI NFO)Marshal.Ptr ToStructure(pic i, typINVOKECOMMAN DINFO);

MessageBox.Show ("InvokeCommand ");

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

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.Ge tCommandString( int idCmd, uint uFlags, int
pwReserved, StringBuilder commandString, int cchMax)
{
switch(uFlags)
{
case (uint)GCS.VERB:
commandString = new StringBuilder(" ...");
break;
case (uint)GCS.HELPT EXT:
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 typINVOKECOMMAN DINFO = Type.GetType("T agSet.INVOKECOM MANDINFO");


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
1548
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 the Explorer Windows opens the context menu with the option "Use My App" and selecting this runs My App with the selected file name. Just as I wanted. The problem I now have is that double clicking a Visual Studio file (.sln) also starts My...
1
1157
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 the Explorer Windows opens the context menu with the option "Use My App" and selecting this runs My App with the selected file name. Just as I wanted. The problem I now have is that double clicking a Visual Studio file (.sln) also starts My...
1
257
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 the Explorer Windows opens the context menu with the option "Use My App" and selecting this runs My App with the selected file name. Just as I wanted. The problem I now have is that double clicking a Visual Studio file (.sln) also starts My...
5
2350
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 fine but passes an error that the file(s) are in use ny another user. This other user must be the windows explorer. Any workarounds to free the files from the windows explorer?
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.