The COM factory
---------------
In "shelloverlay.h", we will declare this class:
Q_OBJECT
public:
ShellOverlayBinder
(QObject *parent
= 0);
};
Add a dllmain.cpp file to the project, which will contain:
#include <qt_windows.h>
#include <ActiveQt>
#include <QAxFactory>
#include "shelloverlay.h"
QT_USE_NAMESPACE
QAXFACTORY_DEFAULT(ShellOverlayBinder,
"{60c580d2-41f2-43ed-b5d1-b435d74d1999}", /* Class ID (CLSID) */
"{21a9e71b-9ae4-4887-8ada-720442394493}", /* Interface ID (IID) */
"{8c996c29-eafa-46ac-a6f9-901951e765b5}", /* event interface ID */
"{a6b1968a-4bbc-4420-9a55-5ce3579f795a}", /* Type Library ID (TLB) */
"{4f7d37e8-b9cb-4e66-a725-f043753b755c}" /* Application ID (AppID) */
)
Every UUID in this file has to be generated. The ones were used on the author's machine and are fine for this tutorial, but if you want to make your own shell extension, you will have to generate new ones yourself.
- http://doc.trolltech.com/4.6/qaxfactory.html
Additional files, embedding the icon
------------------------------------
We will need a .def file, which will declare the exported symbols. The file from <qt>\src\activeqt\control\qaxserver.def will be enough, we can use it verbatim.
We will also need a .rc file, containing this:
1 TYPELIB "qaxserver.rc"
1 ICON DISCARDABLE "qtoverlay.ico"
We will ultimately need an icon file. We will for example use Qt's favicon, modified so it only covers a quarter of the file.
% wget http://qt.nokia.com/favicon.ico
% convert favicon.ico -alpha on -background none -gravity southeast -extent 32x32 qtoverlay.ico
We will put these 3 files at the root of our project dir. You can add also add them to the project in QtCreator.
Build
-----
QMake configuration
+++++++++++++++++++
The qmake .pro file will need some modifications.
Add this:
CONFIG += dll qaxserver qt
qaxserver is used to include some default implementations (for the symbols from the .def file we previously included) ActiveQt provides and which suit our needs.
LIBS += -luser32 -lole32 -loleaut32 -lgdi32 -luuid
DEF_FILE = qaxserver.def
RC_FILE = qaxserver.rc
- http://doc.trolltech.com/4.6/qmake-manual.html
Include VisualStudioExpress tools path
++++++++++++++++++++++++++++++++++++++
TODO this section needs work
Open a "cmd" prompt, exec vcvars32.bat in it, and run qtcreator from there.
Build
+++++
The project should now build fine.
Run
---
Installation
++++++++++++
TODO this section needs work, the registry part should be in DllInstall perhaps in the future
A key with any name must be created in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers, and its default value should be the bracketed (with '{' and '}' around it) ClassID of our extension (the class id can be found in dllmain.cpp).
Registration and dependencies
+++++++++++++++++++++++++++++
TODO this section needs work
Unfortunately, the DLL has dependencies to other DLL files, that have to be copied in the same directory as our DLL, these are:
- mingwm10.dll (found in <qt>\bin)
- libgcc_s_dw2-1.dll (found in <qt>\bin)
- QtCore4.dll (or QtCored4.dll if the extension is built in "debug")
- QtGui4.dll (or QtGuid4.dll if debug) (TODO this should not be needed)
The extension can now be registered, by typing "regsvr32 shellext_overlay.dll".
If regsvr32 says "the specified module could not be found", it may have some other dependencies. The "Dependency Walker" tool can be used to find them.
- http://www.dependencywalker.com/
Test
++++
Now, we can start notepad (or any app with a file selection dialog), select "open..." and watch our shell extension at work!
The COM factory
---------------
In "shelloverlay.h", we will declare this class:
class ShellOverlayBinder : public QObject, public QAxBindable {
Q_OBJECT
public:
ShellOverlayBinder(QObject *parent = 0);
QAxAggregated *createAggregate();
};
Add a dllmain.cpp file to the project, which will contain:
#include <qt_windows.h>
#include <ActiveQt>
#include <QAxFactory>
#include "shelloverlay.h"
QT_USE_NAMESPACE
QAXFACTORY_DEFAULT(ShellOverlayBinder,
"{60c580d2-41f2-43ed-b5d1-b435d74d1999}", /* Class ID (CLSID) */
"{21a9e71b-9ae4-4887-8ada-720442394493}", /* Interface ID (IID) */
"{8c996c29-eafa-46ac-a6f9-901951e765b5}", /* event interface ID */
"{a6b1968a-4bbc-4420-9a55-5ce3579f795a}", /* Type Library ID (TLB) */
"{4f7d37e8-b9cb-4e66-a725-f043753b755c}" /* Application ID (AppID) */
)
Every UUID in this file has to be generated. The ones were used on the author's machine and are fine for this tutorial, but if you want to make your own shell extension, you will have to generate new ones yourself.
- http://doc.trolltech.com/4.6/qaxfactory.html
Additional files, embedding the icon
------------------------------------
We will need a .def file, which will declare the exported symbols. The file from <qt>\src\activeqt\control\qaxserver.def will be enough, we can use it verbatim.
We will also need a .rc file, containing this:
1 TYPELIB "qaxserver.rc"
1 ICON DISCARDABLE "qtoverlay.ico"
We will ultimately need an icon file. We will for example use Qt's favicon, modified so it only covers a quarter of the file.
% wget http://qt.nokia.com/favicon.ico
% convert favicon.ico -alpha on -background none -gravity southeast -extent 32x32 qtoverlay.ico
We will put these 3 files at the root of our project dir. You can add also add them to the project in QtCreator.
Build
-----
QMake configuration
+++++++++++++++++++
The qmake .pro file will need some modifications.
Add this:
CONFIG += dll qaxserver qt
qaxserver is used to include some default implementations (for the symbols from the .def file we previously included) ActiveQt provides and which suit our needs.
LIBS += -luser32 -lole32 -loleaut32 -lgdi32 -luuid
DEF_FILE = qaxserver.def
RC_FILE = qaxserver.rc
- http://doc.trolltech.com/4.6/qmake-manual.html
Include VisualStudioExpress tools path
++++++++++++++++++++++++++++++++++++++
TODO this section needs work
Open a "cmd" prompt, exec vcvars32.bat in it, and run qtcreator from there.
Build
+++++
The project should now build fine.
Run
---
Installation
++++++++++++
TODO this section needs work, the registry part should be in DllInstall perhaps in the future
A key with any name must be created in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers, and its default value should be the bracketed (with '{' and '}' around it) ClassID of our extension (the class id can be found in dllmain.cpp).
Registration and dependencies
+++++++++++++++++++++++++++++
TODO this section needs work
Unfortunately, the DLL has dependencies to other DLL files, that have to be copied in the same directory as our DLL, these are:
- mingwm10.dll (found in <qt>\bin)
- libgcc_s_dw2-1.dll (found in <qt>\bin)
- QtCore4.dll (or QtCored4.dll if the extension is built in "debug")
- QtGui4.dll (or QtGuid4.dll if debug) (TODO this should not be needed)
The extension can now be registered, by typing "regsvr32 shellext_overlay.dll".
If regsvr32 says "the specified module could not be found", it may have some other dependencies. The "Dependency Walker" tool can be used to find them.
- http://www.dependencywalker.com/
Test
++++
Now, we can start notepad (or any app with a file selection dialog), select "open..." and watch our shell extension at work!
To copy to clipboard, switch view to plain text mode
Bookmarks