.NETGURU
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...
 
    
Dot Net Guruias 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().

Dot Net Guruias

--
Dot Net Guruias 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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification