Click here to Skip to main content
15,879,184 members
Articles / Desktop Programming / ATL
Article

Extending property set control with common OLE DB dialogs for connection string property creation

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Oct 20011 min read 55.6K   419   29   1
extending existing property browser with OLE DB common dialogs

Sample Image - oledbdialog.jpg

Introduction

Once I had a project where it was necessary to store and retrieve properties with little effort. I found the article “Setting Properties with OLE Automation” by Konstantin Boukreev very useful for this purpose. He wrote the ActiveX control which gave an opportunity to manipulate properties in VB IDE property browser through IDispatch interface.

How it works

So I decided to create one COM object for the program for properties manipulation and to edit it via previously described ActiveX control. The first thing necessary to be mentioned is the following macros in my Properties COM object:

DECLARE_CLASSFACTORY_SINGLETON (CObserverDS)

This was made to make my Properties COM object unique per process. The next problem I met was that there was connection string among my properties. It was not a good style to edit it as a string. For example if you work with OLE DB or ADO you know common dialog for data link properties selection.

ole db providers - img1.jpg

Sorry for Russian captions :) Couldn’t find non Russian operation system.

Fortunately Konstantin Boukreev provides easy way to add you own types to his property browser. You have just to write you own class for data field click implementation. I did it as follows for connection string property:

#include "oledb.h"      
#include "msdasc.h"      

class kPropertyDataSource : public kPropertyCustom
{
public:
  kPropertyDataSource(kObserver* pObserver) : kPropertyCustom(pObserver) {}
protected:  
   bool OnClickImpl()
   {
      USES_CONVERSION;
      CComBSTR bstr;
      GetText(bstr);
      IUnknown *  pUnkDataSource = NULL;
      IDataInitialize *  pIDataInitialize = NULL;
      IDBPromptInitialize *  pIDBPromptInitialize = NULL;
      CoCreateInstance( CLSID_DataLinks,
                      NULL,
                      CLSCTX_INPROC_SERVER,
                      IID_IDataInitialize,
                      (void**)&pIDataInitialize
                      );
      try
      {
            pIDataInitialize->GetDataSource( NULL, 
                                  CLSCTX_INPROC_SERVER,
                                  bstr, 
                                  IID_IUnknown, 
                                  (IUnknown**)&pUnkDataSource  
                                  );
      }
      catch(...)
      {
      }
      CoCreateInstance( CLSID_DataLinks,
                NULL,
                CLSCTX_INPROC_SERVER,
                IID_IDBPromptInitialize,
                 (void**)&pIDBPromptInitialize
                );
      pIDBPromptInitialize->PromptDataSource( NULL,
                                              GetDesktopWindow(),
                                              DBPROMPTOPTIONS_PROPERTYSHEET,
                                              0,
                                              NULL,
                                              NULL,
                                              IID_IUnknown,
                                              (IUnknown**)&pUnkDataSource
                                              );
      pIDataInitialize->GetInitializationString(pUnkDataSource,false,&bstr);
      if (pIDBPromptInitialize)
            pIDBPromptInitialize->Release();
      if (pIDataInitialize)
            pIDataInitialize->Release();
      if (pUnkDataSource) 
            pUnkDataSource->Release();
      return SetText(bstr) == S_OK;
   };
};

This code must be added in kProperty.h file. You have also to modify kObserver2.cpp file by adding:

else if(InlineIsEqualGUID(pta->guid, GUID_DATASOURCE))
{
   pprop = new kPropertyDataSource(this);  
   hr = S_OK;
}

and to add GUID_DATASOURCE definition to propguids.h file.

// {9C49625B-D1F9-44c8-84F7-C15936864B6A}
DEFINE_GUID(GUID_DATASOURCE, 0x9c49625b, 0xd1f9, 0x44c8, 0x84, 0xf7, 
    0xc1, 0x59, 0x36, 0x86, 0x4b, 0x6a);

I put all changed files in ModifiedFiles folder. I wrote test Properties COM objects with only one property - connectionString. But notice that it’s type is defined in idl file with it’s own guid as follows:

[uuid(9c49625b-d1f9-44c8-84f7-c15936864b6a), version(1.0)]
typedef BSTR DATASOURCEBSTR;

And I also wrote simple VB sample:

vb sample - img2.jpg

only for editing the connectionString property of my COM object.

connection string - img3.jpg

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
currently working as a software development engineer in Schlumberger Oilfield Services (Research and Development department) in Moscow

Comments and Discussions

 
GeneralThanks Pin
Konstantin Boukreev9-Oct-01 15:52
Konstantin Boukreev9-Oct-01 15:52 
Thanks for evolution of idea. Nice job Wink | ;)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.