main.cpp

00001 
00002 #include "main.h"
00003 #include <QApplication>
00004 #include <QTextEdit>
00005 #include <QSettings>
00006 #include <QUuid>
00007 #include <ClassFactory.h>
00008 
00009 //
00010 // This is a simple and generic sub-routine for getting a simple COM server
00011 //  registered in the registry.  This can be used on lots of different
00012 //  COM servers, it's reasonably generic.
00013 //
00014 void RegisterComServer
00015 (
00016   const QString & progid,      // the Name value we want to fetch by.  Like, "SimpleCOM.EXE"
00017   const QUuid & clsid,         // the CLSID value for our app
00018   const QString & description, // a useful description
00019   const QString & serverType,  // the type of server
00020   const QString & serverPath   // where to find the server
00021 )
00022 {
00023   //
00024   // Open the registry root
00025   //
00026   QSettings registry( "HKEY_CLASSES_ROOT", QSettings::NativeFormat );
00027 
00028   //
00029   // Set the PROGID registry value for this entry, and set the description also
00030   //
00031   //
00032   registry.setValue( progid + "/Default",       description      );
00033   registry.setValue( progid + "/CLSID/Default", clsid.toString() );
00034 
00035   //
00036   // Establish a path to the CLSID root.
00037   //
00038   QString clsroot = "CLSID/" + clsid.toString() + "/";
00039 
00040   //
00041   // Set the Description, Server type, and path to the server plus the ProgID, which is a
00042   //  bit redundant but we're doing it anyway.
00043   //
00044   registry.setValue( clsroot + "Default",                description );
00045   registry.setValue( clsroot +  serverType + "/Default", serverPath  );
00046   registry.setValue( clsroot + "ProgID/Default",         progid      );
00047 
00048 }
00049 
00050 
00051 void UnregisterComServer
00052 (
00053   const QString & progid // the Name value we want to fetch by.  Like, "SimpleCOM.EXE"
00054 )
00055 {
00056   QSettings registry( "HKEY_CLASSES_ROOT", QSettings::NativeFormat );
00057 
00058   //
00059   // Get the clsid associated with this progid so we can delete it also.
00060   //
00061   QUuid clsid = registry.value( progid + "/CLSID/Default" ).toString();
00062 
00063   registry.remove( "CLSID/" + clsid.toString() );
00064   registry.remove( progid );
00065 
00066 }
00067 
00068 /*
00069 ** Define these as static constant globals.  We refer to them in 
00070 **  multiple locations and its best to have them constantified
00071 **
00072 */
00073 #define SIMPLECOM_CLSID  "{420a352c-429b-4512-a926-3e2b77aa33fe}"
00074 #define SIMPLECOM_PROGID "SimpleCOM.EXE"
00075 
00076 int main( int argc, char ** argv )
00077 {
00078   QApplication app(argc,argv);
00079 
00080   if( app.arguments().contains("/register") )
00081   {
00082     RegisterComServer
00083     (
00084       SIMPLECOM_PROGID,                           // progid
00085       SIMPLECOM_CLSID,                            // clsid
00086       "This is a SimpleCOM server demonstration", // description
00087       "LocalServer",                              // serverType
00088       app.applicationFilePath()                   // serverPath
00089     );
00090     exit(0);
00091   }
00092 
00093   if( app.arguments().contains("/unregister") )
00094   {
00095     UnregisterComServer( SIMPLECOM_PROGID );
00096     exit(0);
00097   }
00098 
00099   ClassFactory factory( SIMPLECOM_CLSID );
00100 
00101   QTextEdit message;
00102   message.append( "Hello World!" );
00103   message.show();
00104 
00105   return( app.exec() );
00106 }
00107 




~ ~ ~ ~ ~ ~
Don't create Texas sized problems...
Comment your Code!
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC