Search:
Namespaces
Discussions
.NET v1.1
Feedback
Problem with Shell interop
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.framework.interop
.
Post a new message to this list...
FramMla
Thanks if you can bring me some answer elements or a link to an answer
I searched the web for 48h without result.
Those remarks are directly based on the example given with the VS (2003)
that you can find localy at:
C:\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\Samples\Technologies\Interop\Applications\ShellCmd
1-Interactions with the keyboard accelerator Windows+E
-----------------------------------------------------------------
When the menu is loaded, the keyboard accelerator Windows+E, that run
Explorer, doesn't work.
But, the probleme get worst if you add some code: interaction with Windows+E
can acts on your menu, showing your winforms or making explorer using lot
and lot of memory.
Question: how to trap the keyboard accelerator Windows+E to make it work
correctly or inactivate it instead of making your application bug ?
2-How to bug the example
------------------------------
Just change the IContextMenu interface implementation (ShellExtLib.cs, at
the end):
replace:
[PreserveSig()]
int QueryContextMenu(uint hmenu, uint iMenu, int idCmdFirst, int
idCmdLast, uint uFlags);
[PreserveSig()]
void InvokeCommand (
IntPtr
pici);
[PreserveSig()]
void GetCommandString(int idcmd, uint uflags, int reserved,
StringBuilder
commandstring, int cch);
by:
[PreserveSig()]
void GetCommandString(int idcmd, uint uflags, int reserved,
StringBuilder
commandstring, int cch);
[PreserveSig()]
void InvokeCommand (
IntPtr
pici);
[PreserveSig()]
int QueryContextMenu(uint hmenu, uint iMenu, int idCmdFirst, int
idCmdLast, uint uFlags);
By this way, the menu will never appear.
Question: the order of the functions (interface signature) is it so
important ?
3-Go farther
--------------
How implement the interfaces IContextMenu2 and IContextMenu3 without bugging
explorer ?
In my case, i iterate the IContextMenu implementation by a:
[ComImport(),
InterfaceType(
ComInterfaceType
.InterfaceIsIUnknown),
GuidAttribute
("000214f4-0000-0000-c000-000000000046")]
public interface IContextMenu2
{
// IContextMenu2 method
[PreserveSig()]
int HandleMenuMsg(
uint uMsg, //UINT
IntPtr
wParam, //WPARAM
IntPtr
lParam //LPARAM
);
}
[ComImport(),
InterfaceType(
ComInterfaceType
.InterfaceIsIUnknown),
GuidAttribute
("bcfce0a0-ec17-11d0-8d10-00a0c90f2719")]
public interface IContextMenu3
{
// IContextMenu3 method
[PreserveSig()]
int HandleMenuMsg2(
uint uMsg, //UINT
IntPtr
wParam, //WPARAM
IntPtr
lParam, //LPARAM
IntPtr
plResult //LRESULT *
);
}
I get the GUIDS on a example. But, the IContextMenu3 GUID let me perplex...
Who knows exactly the ShellGUIDS ?
4-Bonus
----------
To show the descriptive message in the status bar, wich is invoked by the
IContextMenu.GetCommandString, the
StringBuilder
DOES NOT WORK (i tried
longly)
So i used two functions (one for ASCII, the other for UNICODE):
private void pokeAnsiString(
IntPtr
memPtr, string theString, int sizeMax)
{
int i;
for(i=0; i<theString.Length; i++)
{
if(i==sizeMax-1)
break;
Marshal
.WriteByte(memPtr, i, (byte)theString[i]);
}
Marshal
.WriteByte(memPtr, i, 0); //terminal 0
}
private void pokeUnicodeString(
IntPtr
memPtr, string theString, int sizeMax)
{
byte[] bytes;
int i;
bytes=System.Text.
Encoding
.Unicode.GetBytes(theString);
for(i=0; i<bytes.Length; i++)
{
if(i==sizeMax-2)
break;
Marshal
.WriteByte(memPtr, i, bytes[i]);
}
Marshal
.WriteByte(memPtr, i, 0); //terminal 0 (unicode)
Marshal
.WriteByte(memPtr, i+1, 0); //terminal 0(unicode)
}
that give the waited results.
Thanks for answers.
Sincerely
Francis MOREL.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com
).
Version: 6.0.755 / Virus Database: 505 - Release Date: 08/09/2004
Reply to this message...
Mattias Sjögren
[Original message clipped]
Yes, it's essential.
[Original message clipped]
They must redeclare all methods in their base interfaces. So you have
to copy all methods from IContextMenu to IContextMenu2 and so on.
[Original message clipped]
Not sure what you're asking here. Your IContextMenu3 IID is correct.
[Original message clipped]
This code is very inefficient. You can write all characters in one
call with
Marshal
.Copy().
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
|
http://www.dotnetinterop.com
Please reply only to the newsgroup.
Reply to this message...
System.IntPtr
System.Runtime.InteropServices.ComInterfaceType
System.Runtime.InteropServices.GuidAttribute
System.Runtime.InteropServices.Marshal
System.Text.Encoding
System.Text.StringBuilder
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com