Станционный диспетчер
Группа: Участник
Сообщений: 143
|
Вот рабочие файлы:
promptudl.cpp:
CODE |
#include "promptudl.h"
#include <msdasc.h>
/*
USING:
BSTR bNewStr=NULL;
prompt_OLEDBDS(<ваш Text>,<FormXX->Handle>,&bNewStr);
if(bNewStr)<Куда засунуть текст>=bNewStr;
if(bNewStr)::SysFreeString(bNewStr); // ну и желательно :) освободить
*/
HRESULT prompt_OLEDBDS(WideString wsInitString,HWND hWndParent,BSTR *bNewString)
{
IDBPromptInitialize *pIDBPromptInitialize=NULL;
IDBInitialize *pIDBInitialize =NULL;
IDataInitialize *pDataInitialize =NULL;
HRESULT hr =S_OK;
hr=CoCreateInstance(CLSID_DataLinks,NULL,CLSCTX_INPROC_SERVER,
IID_IDataInitialize,(void **)&pDataInitialize);
if(SUCCEEDED(hr)&&pDataInitialize)
{
hr=pDataInitialize->GetDataSource(NULL,CLSCTX_INPROC_SERVER,
wsInitString.c_bstr(),IID_IDBInitialize,(IUnknown **)&pIDBInitialize);
if(SUCCEEDED(hr))
hr=CoCreateInstance(CLSID_DataLinks,NULL,CLSCTX_INPROC_SERVER,
IID_IDBPromptInitialize,(void **)&pIDBPromptInitialize);
}
try
{
if(FAILED(hr))throw(1);
hr=pIDBPromptInitialize->PromptDataSource(NULL, hWndParent,
DBPROMPTOPTIONS_PROPERTYSHEET, 0, NULL, NULL, IID_IDBInitialize,
(IUnknown **)&pIDBInitialize);
if(SUCCEEDED(hr))
{
LPOLESTR wNewString;
hr=pDataInitialize->GetInitializationString((IUnknown *)pIDBInitialize,true,&wNewString);
if(SUCCEEDED(hr))
*bNewString=::SysAllocString(wNewString);
if(wNewString)CoTaskMemFree((void*)wNewString);
}
}__finally
{
if(pDataInitialize)pDataInitialize->Release();
if(pIDBInitialize)pIDBInitialize->Release();
if(pIDBPromptInitialize)pIDBPromptInitialize->Release();
}
return S_OK;
}
|
promptudl.h:
CODE |
#ifndef __PROMPTUDL_H__
#define __PROMPTUDL_H__
#include <vcl.h>
HRESULT prompt_OLEDBDS(WideString,HWND,BSTR *);
#endif
|
|