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.
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.
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:
only for editing the connectionString
property of my COM object.