I've seen many questions on the newsgroup asking for a simple, clear, and concise, 
sample of a 
"Hello World" application for windows that uses XPCom in a stand-alone mode (without 
the 
browser). I'm quite surprised that I've never seen any of the Mozilla crew actually 
answer this.

Yes, Virginia, there is such an app. In your "dist\WIN32_D.OBJ\bin" directory there 
are two 
applications called "TestCOM.exe" and "TestHelloXPLoop.exe". Their source files are in 
"xpcom\tests\windows". The executables are made along with everything else during a 
"build_all" 
or "pull_and_build_all".

The source files are
    TestCOM.cpp
    TestHelloXPLoop.cpp

They are linked with
    rpcrt4.lib                // MS COM RPC stuff
    uuid.lib                  // MS uuid stuff
    $(DIST)\lib\xpcom.lib     // The xpcom dll import library
    $(LIBNSPR)                // The three nspr dll import libraries
                              //   nspr4.lib
                              //   plds4.lib
                              //   plc4.lib

You can make these with "nmake -f makefile.win" from that directory. Of course you 
must have the 
same environment setup as you would for a normal Mozilla build.

--------------------
TestCOM.exe
This is a console mode program that creates an instance of an nsTestCom component 
defined in the 
same source file. It uses the COM IUnknown to get to the nsITestCom interface. Not 
sure why or 
how to do it with nsISupports instead.
    1. Create an instance of the nsTestComFactory object and get the nsIFactory 
interface.
    2. Lock the iFactory server.
    3. Call the iFactory CreateInstance function to get an IUnknown interface to the 
new object.
    4. Query the new object for the nsITestCom interface.
    5. Call the Test() method on the new object.
    6. Release the three interfaces.
    7. Exit the application
The application will display the following:
    nsTestComFactory: Locking server
    nsTestCom: Adding ref = 1
    nsTestComFactory: successfully created nsTestCom instance
    nsTestComFactory: Unlocking server
    nsTestCom: Adding ref = 2
    Accessed nsITestCom::Test() from COM
    nsTestCom: Releasing = 1
    nsTestCom: Releasing = 0
    nsTestCom instance successfully deleted

--------------------
TestHelloXPLoop.exe
This is a Windows mode program that runs an xpcom event loop.
    1. Initialize access to xpcom and the nsComponentManager.
    2. Register and create a main window which displays "Hello, XP Event Loop!"
    3. Create a reference to an instance of nsIEventLoop and run it.
    ... Wait for the main window procedure destroy event to exit the nsIEventLoop ...
    4. Display some exit message boxes and shut down xpcom.
    5. Exit.

--------------------
No, I did not learn of these through any Mozilla web page or documentation. I found 
them quite 
by accident as I was randomly browsing the xpcom makefiles. I hope y'all find them of 
some help. 
I found them quite enlightening.

I have seen the "Standalone XPCOM v0.5" web page from the XPCOM project page. It is 
stamped "NEW 
May 15, 2000". This is apparently some different form of "new" with which I am not 
familiar as 
it is December 27, 2000 in my current reality. The standalone page says that the 
standalone 
xpcom is different from the Mozilla browser version, yet the standalone samples 
currently built 
are using the same libraries as the browser. I have no idea how the versions quoted on 
that page 
(0.5 and 1.0) relate to the current builds or if the version built with the browser 
has other 
problems when run standalone that are not addressed by the samples. It sure would be 
nice to 
know. Maybe more random browsing of the xpcom makefiles will tell. Though a five 
minute typing 
session by one of these "experienced" folk would save us all a lot of wasted man-hours.

-- 
The Snake Pit - Development     www.TheSnakePitDev.com
Curtis Clauson                  [EMAIL PROTECTED]
Proprietor
      (Please respond to the newsgroup. To email me, use the above address.)


Reply via email to