473,651 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IContextMenu InvokeCommand

I have made a shell extension dll in c# to add a menuitem to the explorer context menu

I have implemented these method
IShellExtInit.I nitializ
IContextMenu.Qu eryContextMen
IContextMenu.Ge tCommandStrin
IContextMenu.In vokeComman

When I register the dll with regasm and gacutil a menuitem shows in the explorer contextmenu and
IShellExtInit.I nitialize and IContextMenu.Qu eryContextMenu gets called. But GetCommandStrin g and
InvokeCommand never gets called when I click the menu item

Can anyone explain whats going on

Thank
Lars
Nov 16 '05 #1
4 7876
Lars,
Can anyone explain whats going on?


It's hard to guess without seeing any code.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
a dll file consisting of the two files shellext.cs and ContextMenuHand ler.c
shellext.c

using System
using System.Runtime. InteropServices

namespace ShellEx

// IUnknow
[ComImport(), GuidAttribute(" 00000000-0000-0000-c000-000000000046")
InterfaceType(C omInterfaceType .InterfaceIsIUn known)
public interface IUnknow

// IClassFactor
[ComImport(), GuidAttribute(" 00000001-0000-0000-c000-000000000046")
InterfaceType(C omInterfaceType .InterfaceIsIUn known)
public interface IClassFactor

// IShellExtIni
[ComImport(), GuidAttribute(" 000214e8-0000-0000-c000-000000000046")
InterfaceType(C omInterfaceType .InterfaceIsIUn known)
public interface IShellExtIni

[PreserveSig()
int Initialize (IntPtr pidlFolder, IntPtr lpdobj, uint /*HKEY*/ hKeyProgID)
// IContextMen
[ComImport(), GuidAttribute(" 000214e4-0000-0000-c000-000000000046")
InterfaceType(C omInterfaceType .InterfaceIsIUn known)
public interface IContextMen

// IContextMenu method
[PreserveSig()
int QueryContextMen u(uint hmenu, uint iMenu, int idCmdFirst, int idCmdLast, uint uFlags)
[PreserveSig()
void InvokeCommand (IntPtr pici)
[PreserveSig()
void GetCommandStrin g(int idcmd, uint uflags, int reserved, string commandstring, int cch)

ContextMenuHand ler.c

using System
using System.Runtime. InteropServices
using Microsoft.Win32

using ShellExt

namespace ContextMenuHand le

[Guid("xxxxxxxx-xxxx-xxxx-xxxx-4F33EC089772"), ComVisible(true )
public class MyExtension : IShellExtInit, IContextMen

// *** Imports *************** *************** *************** *******

// MessageBo
[DllImport("user 32")
static extern int MessageBox(int hWnd, string text, string caption, int type)

[DllImport("user 32")
static extern bool InsertMenu( uint hMenu
uint uPosition
uint uFlags
int uIDNewItem
string lpNewIte
)

// *** Consts *************** *************** *************** ********

const string guid = @"{xxxxxxxx-xxxx-xxxx-xxxx-4F33EC089772}"
const string regHome1 = @"my_file\shell ex\ContextMenuH andlers"
const string regApproved = @"Software\Micr osoft\Windows\C urrentVersion\S hell Extensions\Appr oved"
const int I_OK = 0
const int I_FALSE = 1

// *** Functions *************** *************** *************** *****

// Initializ
int IShellExtInit.I nitialize (IntPtr /*LPCITEMIDLIST*/ pidlFolder, IntPtr /*LPDATAOBJECT*/ lpdobj, uint /*HKEY*/ hKeyProgID

MessageBox(0, "IShellExtInit. Initialize", "Informatio n", 0)
return I_OK
// QueryContextMen
int IContextMenu.Qu eryContextMenu( uint hMenu, uint iMenu, int idCmdFirst, int idCmdLast, uint uFlags

MessageBox(0, "IContextMenu.Q ueryContextMenu ", "Informatio n", 0)
// MessageBox(0, hMenu.ToString( )+" "+ iMenu.ToString( )+" "+ idCmdFirst.ToSt ring()+" "+ idCmdLast.ToStr ing()+" "+ uFlags.ToString (), "Informatio n", 0)
bool bResult = InsertMenu(hMen u, 0, 0, 1024, "Do &Stuff...")
// MessageBox(0, "Result = "+bResult.ToStr ing(), "Informatio n", 0)
return 1
// GetCommandStrin
void IContextMenu.Ge tCommandString( int idCmd, uint uFlags, int pwReserved, string commandString, int cchMax

MessageBox(0, "IContextMenu.G etCommandString ", "Informatio n", 0)
return
// InvokeComman
void IContextMenu.In vokeCommand(Int Ptr pici

MessageBox(0, "IContextMenu.I nvokeCommand", "Informatio n", 0)
return
// *** COM Register/Unregister functions *************** ***********

[ComRegisterFunc tion
public static void Register(System .Type t)

tr

RegistryKey regRoot = Registry.Classe sRoot
RegistryKey regKey

regRoot.CreateS ubKey(regHome1)

regKey = regRoot.CreateS ubKey(regHome1 + @"\MyCommandISE ")
regKey.SetValue (string.Empty, guid)

// Add to list of approved shellextension
regRoot = Registry.LocalM achine

regKey = regRoot.OpenSub Key(regApproved , true)
regKey.SetValue (guid, "ContextMen u Extension")

// CloseKey
regKey.Close()
regRoot.Close() ;
}
catch(Exception ex)
{
MessageBox(0, ex.Message, "Exception Occured", 0);
}
}

[ComUnregisterFu nction]
public static void UnRegister(Syst em.Type t)
{
try
{
RegistryKey regRoot = Registry.Classe sRoot;
RegistryKey regKey;

regRoot.DeleteS ubKeyTree(@"my_ file\shellex");

// Remove from list of approved shellextensions
regRoot = Registry.LocalM achine;

regKey = regRoot.OpenSub Key(regApproved , true);
regKey.DeleteVa lue(guid);

regKey.Close();
regRoot.Close() ;
}
catch(Exception ex)
{
MessageBox(0, ex.Message, "Exception Occured", 0);
}
}
} // ContextMenuExte nsion
} // Namespace

Nov 16 '05 #3
Lars,
bool bResult = InsertMenu(hMen u, 0, 0, 1024, "Do &Stuff...");
Where did you get 1024 from? I believe you're supposed to use
idCmdFirst there rather than picking your own arbitrary command ID.

void IContextMenu.Ge tCommandString( int idCmd, uint uFlags, int pwReserved, string commandString, int cchMax)


I'd make commandString an IntPtr or possibly a StringBuilder.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4
found the problem! ;
int IContextMenu.Qu eryContextMenu( uint hMenu, uint iMenu, int idCmdFirst, int idCmdLast, uint uFlags

int idCmd = idCmdFirst
bool bResult = InsertMenu(hMen u, iMenu++, 1024, idCmd++, "Do &Stuff...")
return 1
1024 is the value of MF_BYPOSITIO
Nov 16 '05 #5

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

Similar topics

0
1477
by: miles__ahead | last post by:
Hi. I like to create little utilities for Windows. It's nice to have Shell Integration, such as using the Context Menu. I've googled but haven't seen any Python example code for IContextMenu handlers. Anyone know where I can find some Python examples? Mainly I'm thinking of creating a Python DLL to send messages to running programs when the user selects a command from the Context Menu. TIA
4
347
by: Lars Nielsen | last post by:
I have made a shell extension dll in c# to add a menuitem to the explorer context menu I have implemented these method IShellExtInit.Initializ IContextMenu.QueryContextMen IContextMenu.GetCommandStrin IContextMenu.InvokeComman When I register the dll with regasm and gacutil a menuitem shows in the explorer contextmenu and IShellExtInit.Initialize and IContextMenu.QueryContextMenu gets called. But GetCommandString and
1
5480
by: shafeeque | last post by:
I am building a shell extn. project in .net ide which is converted from vC++ 6.00. During buid i am getting the following error "error C2787: 'IContextMenu' : no GUID has been associated with this object", The same project works fine in VC++6.0. I have included the following files also #include <shlguid.h> #include <shobjidl.h>
2
1246
by: Rajko | last post by:
HRESULT QueryContextMenu( HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags ); function gives me to small range of numbers !!! usually:
0
938
by: yxq | last post by:
Hello I have some code about shell extension, it works well, but when i choose more than a txt files and right-click, click open, system popup a dialog "InvokeCommand", system can not open the txt files, i do not know what reason. **************************************************************************** *************** ' Carries out the command associated with
2
2747
by: gilad | last post by:
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...
0
4080
by: lushdog | last post by:
Hi, i'm writing a shell extension in c# that will add two menu's to the right-click menu of explorer if any file is selected, i.e. it's registered in the * section of Classes in the registry. Here is the problem. If i select one file and use the standard OPEN context menu, for a .txt file let's say, all is well, but if i select two or more files and use the standard OPEN context menu it seems to want to run through the code snippet for...
0
3252
by: lushdog | last post by:
Hi, i'm having a little problem with my context menu handler. Basically if i select multiple files and right-click OPEN or EDIT, it uses my context menu to open it. It is because i am missing this line of code of C++ in my C# code. ------------------------- // If lpVerb really points to a string, ignore this function call and bail out. if ( 0 != HIWORD( pInfo->lpVerb )) return E_INVALIDARG;
3
5041
by: Poggs | last post by:
Hi everyone, I used the pattern for Shell Extensions for Context menu from Dino Esposito's article. However I implemented it in more than one application and it seems that those two right click functionalities cannot work together. void IContextMenu.InvokeCommand (IntPtr pici) I put more debugging information and I noticed that the two assemblies are using a common value. I haved changed their namespaces and guids to be different but...
0
8352
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
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
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
8697
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...
0
8579
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
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
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
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

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.