Codwiz51's Wiki

Example C++/CLI mixed mode applied to RAPI

Modified: 2008/07/08 11:19 by codewiz51 - Categorized as: CLI
Updated: Proposed changes to dccole.h and dccole2.h to make IDccMan and IDccManSink easier to use with C++/CLI.

While working with RAPI, I've come across a couple of changes to the dccole.h and dccole2.h files that eases the task of creating these objects using com::ptr.

Changes to dcole.h and dcole2.h only affect the interface definitions. A GUID definition is added to the three files. This does not seem to affect activation or addressing of the components.

// DECLARE_INTERFACE_ (IDccManSink,  IUnknown)
interface __declspec(novtable, uuid("A7B88840-A812-11CF-8011-00A0C90A8F78")) IDccManSink : public IUnknown

// DECLARE_INTERFACE_ (IDccMan,  IUnknown)
interface __declspec(novtable, uuid("A7B88841-A812-11CF-8011-00A0C90A8F78")) IDccMan : public IUnknown

// DECLARE_INTERFACE_ (IDccManSink2,  IDccManSink)
interface __declspec(novtable, uuid("1317003A-9A62-4040-98F1-9CE9EFD8298B")) IDccManSink2 : public IDccManSink

Using these updated definitions, you can now do things like:

// Declaration of managed COM pointer
msclr::com::ptr<::IDccMan> m_ptrIDccMan;
...
// Simple implementation
m_ptrIDccMan.CreateInstance(CLSID_DccMan, NULL, CLSCTX_SERVER);
HRESULT hr = m_ptrIDccMan->ShowCommSettings();

Using the non-updated headers causes an error, because the interfaces do not have a GUID defined in the definition. I am looking at how to define different interfaces with the correct GUID so that the original MS headers do not need to be changed. codewiz51, 2008/07/08 11:13

This is a culmination of five previous CLI articles on mixing native structs and API calls with managed code:


Here's a reference on Void Nish demonstrating managed C++/CLI code and arrays.

In order to use the example project you will need the following:

  • Visual Studio 2005
  • Windows Mobile 6 Professional SDK (Earlier versions will probably work fine for this example.)
  • Add %ProgramFiles%\Windows Mobile 6 SDK\Activesync\inc to the VC ++ Include directory list
  • Add %ProgramFiles%\Windows Mobile 6 SDK\Activesync\Lib to the VC ++ Lib directory list
  • A portable hand held device connected to your laptop/desktop via COM1-4 or USB with a Windows OS compliant with ActiveSync.

This code was tested with an HP iPAQ connected via a USB connection to an HP desktop computer. I have not tested this code with VS 2008. If it doesn't compile with VS 2008, don't ask me for help.

Update: I've expanded the example code to include several more examples of using the Embedded template. codewiz51, 2008/07/03 15:01

Here is the download link: pin_ptrTest.zip

The source code makes use of the Embedded template introduced by Brandon Bray. The native struct CE_FIND_DATA is declared in the class FileInformation using the Embedded template. Various properties are used to access the native struct. The actual example usage occurs in the method EnumFiles declared in the class FileList.

Drop me a line if you have any questions. codewiz51, 2008/07/03 05:10


ScrewTurn Wiki version 2.0.36. Some of the icons created by FamFamFam.