View Single Post
Old 07-20-2006, 03:29 PM   #1
god_of_cpu
Raw Wave
 
god_of_cpu's Avatar
 
Join Date: Jan 2004
Location: SilverSpring Maryland
Posts: 2,957
How to create a C++ COM object for StreetDeck

The StreetDeck development enviornment will let you load any standard COM object into it using VB Scripts CreateObject function.

Alternatively, you may prefer to create a COM addin that StreetDeck can use directly and does not require you to use the scripting engine at all. See Building a .Net Addin for StreetDeck for more information.

This tutorial will show you how to use Microsoft Visual Studio 2003 to create a COM object that can be loaded by the StreetDeck scripting engine.

Once created and registered, you can simply load the COM object in StreetDeck by calling CreateObject with the registered name of the object you created and immediatly call methods in it.

For this tutorial, we will be writing the object in C++ using ATL. You can write this object using a variety of different methods, but for the purposes of this tutorial, we will only be using ATL which greatly simplfies reference counting and other mundane tasks required without it.

Creating a New Project
1. Create a new ATL Project in Visual Studio
Name:  NewProject.JPG
Views: 1545
Size:  40.8 KB



2. Specify the application settings for the project
Name:  ApplicationSettings.JPG
Views: 1527
Size:  34.8 KB



3. Switch to the class view, then right click on "SDCOMObject" and select Add->Class, then select ATL COM+ 1.0 Component.
Name:  COM+.JPG
Views: 1533
Size:  37.4 KB



4. Call the object "ExampleObject"
Name:  ExampleObject.JPG
Views: 1527
Size:  45.0 KB



5. Click finish and the class will be generate for you.


6. Make sure you can see the class view then, then...
  • Right click on your IExampleObject interface.
  • Choose Add->Add Method...
  • Call the method "MsgBox"
  • Add a BSTR input parameter called "Description"
  • Add a second BSTR input parameter called "Caption"
  • Click Finish to have the wizard generate the function stub for you
Name:  AddMethod.JPG
Views: 1541
Size:  36.4 KB



7. Implement the MsgBox method in ExampleObject.cpp by adding the following code which will show a windows message box (BTW, this is a bad example since you should NEVER show a windows dialog in a real project made for use with StreetDeck Its only being used here for ease of understanding)
Code:
STDMETHODIMP CExampleObject::MsgBox(BSTR Description, BSTR Caption) { MessageBox(NULL, CString(Description), CString(Caption), MB_OK); return S_OK; }


8. Notice the use of CString in the previous code, to use this class, we should include #include <atlstr.h> in our stdafx.h file.



9. Your object is now complete and ready for testing, compile the project.


10. Before starting up StreetDeck, we should first get the ProgId of our function that will be used in the CreateObject function called from the development enviornment. To find this id, look in the ExampleObject.rgs file for a line called VersionIndependantProgID, it should look something like this:
Code:
VersionIndependentProgID = s 'SDCOMObject.ExampleObject'

SDCOMObject.ExampleObject is the ProgId to use in the call to CreateObject
__________________
StreetDeck.com Developer (I am Chuck)
Get StreetDeck at http://www.streetdeck.com
The Official StreetDeck Forums have moved, please visit us at http://www.streetdeck.com/forum for official support for Streetdeck.

Last edited by god_of_cpu; 12-14-2006 at 02:30 PM.
god_of_cpu is offline   Reply With Quote
Advertisement
 
Advertisement
Sponsored links