473,796 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to import COM interface - IPersistFile?

Hi ,
I need to change the ToolTip in Windows explorer that is shown when the
cursor is over a file. Here is how it should work: you create a class that
imports IPersistFile and IQueryInfo. After adding some registry values when
you move the cursor over some file in Win Explorer, the shell will create
object from your class and will call IPersistFile::L oad. Well here is the
problem - in my situation it is not called. The only method that is called
from IPersistFile interface is IPersistFile::I sDirty(). Then when IQueryInfo::
GetInfoTip is called I don't have the name of the file that is currently
under the cursor. Here is the code that I use to test. I bound it to txt
files only.
Do I import the IPersistFile interface properly?

namespace ShellExt
{
[ComImport(), ComVisible(true ), InterfaceType(C omInterfaceType .
InterfaceIsIUnk nown), GuidAttribute(" 0000010b-0000-0000-C000-000000000046")]
public interface IPersistFile
{
[PreserveSig()]
void Load(string pszFileName, int dwMode);

[PreserveSig()]
void GetClassID(out Guid pClassID);

[PreserveSig()]
void IsDirty();

[PreserveSig()]
void Save(String pszFileName, bool fRemember);

[PreserveSig()]
void SaveCompleted(S tring pszFileName);

[PreserveSig()]
void GetCurFile(out String ppszFileName);
}

[ComImport(), ComVisible(true ), InterfaceType(C omInterfaceType .
InterfaceIsIUnk nown), GuidAttribute(" 00021500-0000-0000-c000-000000000046")]
public interface IQueryInfo
{
[PreserveSig()]
void GetInfoTip(int flags, ref String toolTip);

[PreserveSig()]
void GetInfoFlags(re f long flags);
}
}

namespace ShellExt
{
/// <summary>
/// Summary description for ToolTipExtensio n.
/// </summary>
///
[Guid("6156C6FC-4DD9-4f82-8200-0446DABB7F35"), ComVisible(true )]
public class ToolTipExtensio n : IPersistFile, IQueryInfo
{
const string guid = "{6156C6FC-4DD9-4f82-8200-0446DABB7F35}";
const int E_NOTIMPL = unchecked((int) 0x80004001);

public IPersistFile persistFile = null;
string fileName = string.Empty;

[PreserveSig()]
void IQueryInfo.GetI nfoTip(int flags, ref string toolTip)
{
if (fileName == String.Empty)
toolTip = "Not working properly!";
else
toolTip = fileName;
}

[PreserveSig()]
void IQueryInfo.GetI nfoFlags(ref long flags)
{
}

#region IPersistFile Members

[PreserveSig()]
void IPersistFile.Lo ad(string pszFileName, int dwMode)
{
this.fileName = pszFileName.ToS tring();
}

[PreserveSig()]
void IPersistFile.Ge tClassID(out Guid pClassID)
{
pClassID = new Guid("6156C6FC-4DD9-4f82-8200-0446DABB7F35");
}

[PreserveSig()]
void IPersistFile.Is Dirty()
{
}

[PreserveSig()]
void IPersistFile.Sa ve(string pszFileName, bool fRemember)
{
}

[PreserveSig()]
void IPersistFile.Sa veCompleted(str ing pszFileName)
{
}

[PreserveSig()]
void IPersistFile.Ge tCurFile(out string ppszFileName)
{
ppszFileName = null;
}

#endregion

#region Registration
[System.Runtime. InteropServices .ComRegisterFun ctionAttribute( )]
static void RegisterServer( String str1)
{
try
{
RegistryKey root;
RegistryKey rk;

root = Registry.Curren tUser;
rk = root.OpenSubKey ("Software\\Mic rosoft\\Windows \\CurrentVersio n\\
Explorer", true);
rk.SetValue("De sktopProcess", 1);
rk.Close();

// For Winnt set me as an approved shellex
root = Registry.LocalM achine;
rk = root.OpenSubKey ("Software\\Mic rosoft\\Windows \\CurrentVersio n\\Shell
Extensions\\App roved", true);
rk.SetValue(gui d, "ShellToolT ip shell extension");
rk.Close();

// Set "Folder\\shelle x\\ContextMenuH andlers\\ShellC md" regkey to my guid
root = Registry.Classe sRoot;
rk = root.CreateSubK ey(".txt\\shell ex\\{00021500-0000-0000-C000-
000000000046}") ;
rk.SetValue("", guid);
rk.Close();
}
catch (Exception e)
{
System.Console. WriteLine(e.ToS tring());
}
}

[System.Runtime. InteropServices .ComUnregisterF unctionAttribut e()]
static void UnregisterServe r(String str1)
{
try
{
RegistryKey root;
RegistryKey rk;

// Remove ShellExtenstion s registration
root = Registry.LocalM achine;
rk = root.OpenSubKey ("Software\\Mic rosoft\\Windows \\CurrentVersio n\\Shell
Extensions\\App roved", true);
rk.DeleteValue( guid);
rk.Close();

// Delete ShellCmd regkey
root = Registry.Classe sRoot;
root.DeleteSubK ey(".txt\\shell ex\\{00021500-0000-0000-C000-000000000046}")
;
}
catch (Exception e)
{
System.Console. WriteLine(e.ToS tring());
}
}
#endregion
}
}
Apr 10 '06 #1
1 7399
Use www.pinvoke.net to check params of export interfaces

and look there
http://groups.google.com/group/micro...b8557330d81fc7

where some issue was described.
Hi ,
I need to change the ToolTip in Windows explorer that is shown when the
cursor is over a file. Here is how it should work: you create a class that
imports IPersistFile and IQueryInfo. After adding some registry values when
you move the cursor over some file in Win Explorer, the shell will create
object from your class and will call IPersistFile::L oad. Well here is the
problem - in my situation it is not called. The only method that is called
from IPersistFile interface is IPersistFile::I sDirty(). Then when IQueryInfo::
GetInfoTip is called I don't have the name of the file that is currently
under the cursor. Here is the code that I use to test. I bound it to txt
files only.
Do I import the IPersistFile interface properly?


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Apr 10 '06 #2

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

Similar topics

16
2757
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is evolving. This can be a problem when, ad example, a module change its interface or its implementation in a fundamental way (an example: wxPython). This, I think, can be resolved by allowing an user to explicitly say what version of a module it wants (sush as version numbers in Linux shared...
17
1890
by: Jacek Generowicz | last post by:
I have a module whose behaviour needs to be configurable. The module needs to decide, the first time it is imported, beteween alternative interfaces it presents. Currently, I set some environment variables which select the desired behaviour, and the module inspects those variables to determine the mode in which it should set itself up. I would prefer a pure Python solution, rather than one which depends on external state. Can you...
3
3824
by: George P | last post by:
I've run into a strange package related namespace problem. Follow these steps (on UNIX system) to illustrate: ------------------------- mkdir /tmp/mypkg cd /tmp/mypkg touch __init__.py echo 'import os\ndef test():\n print os.getcwd()' > os.py cd /tmp
0
2727
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the latter contains the line "import _SHIP". I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
11
4195
by: Robin Tucker | last post by:
I have a COM object, which implements straightforwardly the IDataObject interface. It seems this isn't the same IDataObject interface we now have with .NET. Basically, the COM object implements low level interfaces. It does not have a type library. We use it freely with our unmanaged C++ projects. What I would like to do is load or create one of these objects in VB.NET, but I cannot seem to do it. I've tried: Dim theObject As...
10
3777
by: Ben Finney | last post by:
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to be run as commands to a file with no extension. This allows other programs to use the command as an interface, and I can re-write the program in some other language
1
2163
by: NathanB | last post by:
Hi there, I have a text file (flat file) which I would like to import on a regular basis into Access. The text file contains 2 record types, header (prefixed with RHD) and detail (prefixed with RDT). Each recordtype has a unique structure. ------------------------------------------------------------------------------- For example line one might read: RHD123456ABCDEF
0
2091
by: Michael Boldin via alt email | last post by:
I installed python 2.5 and used the win package for installing MySQLdb. (Iam running Windows XP) Everything works as expected using python directly (Windows command shell) but using IDLE gives the import error below. Same error with PythonWin as my IDE and everything works using python 2.4-- with IDLE and without, mySQLdb is loaded with out error. Below is the IDLEscreen capture Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32...
3
12302
by: SMALLp | last post by:
Hy! I'm new in Linux, and i feel little less newer in python. I need advice and help. I'm making an application witch purpose is irrelevant. It has a lot of code for now and I've only made interface. So I've tried to split code into separate files and in windows as I remember worked file when i wrote eg. import myFile but now in Ubuntu it says Module not found. (I'm using Ubuntu and I've installed python 2.5 and wxPython 2.8.4, and I'm...
0
9685
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
9531
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
10459
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
10237
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
10018
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...
0
6795
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
5446
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
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2928
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.