1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10*96de5490SAndrew Rist * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*96de5490SAndrew Rist * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19*96de5490SAndrew Rist * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir #if defined(WNT) 29cdf0e10cSrcweir #if defined _MSC_VER 30cdf0e10cSrcweir #pragma warning(push, 1) 31cdf0e10cSrcweir #pragma warning(disable: 4917) 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #include "msdasc.h" // OLE DB Service Component header 34cdf0e10cSrcweir #if defined _MSC_VER 35cdf0e10cSrcweir #pragma warning(push, 1) 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #include "stdio.h" 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <initguid.h> // Include only once in your application 40cdf0e10cSrcweir #include <adoid.h> // needed for CLSID_CADOConnection 41cdf0e10cSrcweir #include <adoint.h> // needed for ADOConnection 42cdf0e10cSrcweir 43cdf0e10cSrcweir #ifndef _DBAUI_ADO_DATALINK_HXX_ 44cdf0e10cSrcweir #include "adodatalinks.hxx" 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir 47cdf0e10cSrcweir BSTR PromptEdit(long hWnd,BSTR connstr); 48cdf0e10cSrcweir BSTR PromptNew(long hWnd); 49cdf0e10cSrcweir 50cdf0e10cSrcweir ::rtl::OUString getAdoDatalink(long hWnd,::rtl::OUString& oldLink) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir ::rtl::OUString dataLink; 53cdf0e10cSrcweir if (oldLink.getLength()) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir dataLink=reinterpret_cast<sal_Unicode *>(PromptEdit(hWnd,(BSTR)oldLink.getStr())); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir else 58cdf0e10cSrcweir dataLink=reinterpret_cast<sal_Unicode *>(PromptNew(hWnd)); 59cdf0e10cSrcweir return dataLink; 60cdf0e10cSrcweir } 61cdf0e10cSrcweir BSTR PromptNew(long hWnd) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir BSTR connstr=NULL; 64cdf0e10cSrcweir HRESULT hr; 65cdf0e10cSrcweir IDataSourceLocator* dlPrompt = NULL; 66cdf0e10cSrcweir ADOConnection* piTmpConnection = NULL; 67cdf0e10cSrcweir BSTR _result=NULL; 68cdf0e10cSrcweir 69cdf0e10cSrcweir // Initialize COM 70cdf0e10cSrcweir ::CoInitialize( NULL ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir // Instantiate DataLinks object. 73cdf0e10cSrcweir hr = CoCreateInstance( 74cdf0e10cSrcweir CLSID_DataLinks, //clsid -- Data Links UI 75cdf0e10cSrcweir NULL, //pUnkOuter 76cdf0e10cSrcweir CLSCTX_INPROC_SERVER, //dwClsContext 77cdf0e10cSrcweir IID_IDataSourceLocator, //riid 78cdf0e10cSrcweir (void**)&dlPrompt //ppvObj 79cdf0e10cSrcweir ); 80cdf0e10cSrcweir if( FAILED( hr ) ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir piTmpConnection->Release( ); 83cdf0e10cSrcweir dlPrompt->Release( ); 84cdf0e10cSrcweir return connstr; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir dlPrompt->put_hWnd(hWnd); 88cdf0e10cSrcweir if( FAILED( hr ) ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir piTmpConnection->Release( ); 91cdf0e10cSrcweir dlPrompt->Release( ); 92cdf0e10cSrcweir return connstr; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir // Prompt for connection information. 96cdf0e10cSrcweir hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection); 97cdf0e10cSrcweir 98cdf0e10cSrcweir if( FAILED( hr ) || !piTmpConnection ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir dlPrompt->Release( ); 101cdf0e10cSrcweir return connstr; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir hr = piTmpConnection->get_ConnectionString(&_result); 105cdf0e10cSrcweir if( FAILED( hr ) ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir piTmpConnection->Release( ); 108cdf0e10cSrcweir dlPrompt->Release( ); 109cdf0e10cSrcweir return connstr; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir piTmpConnection->Release( ); 113cdf0e10cSrcweir dlPrompt->Release( ); 114cdf0e10cSrcweir CoUninitialize(); 115cdf0e10cSrcweir return _result; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir BSTR PromptEdit(long hWnd,BSTR connstr) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir HRESULT hr; 121cdf0e10cSrcweir IDataSourceLocator* dlPrompt = NULL; 122cdf0e10cSrcweir ADOConnection* piTmpConnection = NULL; 123cdf0e10cSrcweir BSTR _result=NULL; 124cdf0e10cSrcweir 125cdf0e10cSrcweir // Initialize COM 126cdf0e10cSrcweir ::CoInitialize( NULL ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir hr = CoCreateInstance(CLSID_CADOConnection, 129cdf0e10cSrcweir NULL, 130cdf0e10cSrcweir CLSCTX_INPROC_SERVER, 131cdf0e10cSrcweir IID_IADOConnection, 132cdf0e10cSrcweir (LPVOID *)&piTmpConnection); 133cdf0e10cSrcweir if( FAILED( hr ) ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir piTmpConnection->Release( ); 136cdf0e10cSrcweir return connstr; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir 140cdf0e10cSrcweir hr = piTmpConnection->put_ConnectionString(connstr); 141cdf0e10cSrcweir if( FAILED( hr ) ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir piTmpConnection->Release( ); 144cdf0e10cSrcweir return connstr; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir // Instantiate DataLinks object. 148cdf0e10cSrcweir hr = CoCreateInstance( 149cdf0e10cSrcweir CLSID_DataLinks, //clsid -- Data Links UI 150cdf0e10cSrcweir NULL, //pUnkOuter 151cdf0e10cSrcweir CLSCTX_INPROC_SERVER, //dwClsContext 152cdf0e10cSrcweir IID_IDataSourceLocator, //riid 153cdf0e10cSrcweir (void**)&dlPrompt //ppvObj 154cdf0e10cSrcweir ); 155cdf0e10cSrcweir if( FAILED( hr ) ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir piTmpConnection->Release( ); 158cdf0e10cSrcweir dlPrompt->Release( ); 159cdf0e10cSrcweir return connstr; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir dlPrompt->put_hWnd(hWnd); 163cdf0e10cSrcweir if( FAILED( hr ) ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir piTmpConnection->Release( ); 166cdf0e10cSrcweir dlPrompt->Release( ); 167cdf0e10cSrcweir return connstr; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir VARIANT_BOOL pbSuccess; 171cdf0e10cSrcweir 172cdf0e10cSrcweir // Prompt for connection information. 173cdf0e10cSrcweir hr = dlPrompt->PromptEdit((IDispatch **)&piTmpConnection,&pbSuccess); 174cdf0e10cSrcweir if( SUCCEEDED( hr ) && sal_False == pbSuccess ) //if user press cancel then sal_False == pbSuccess 175cdf0e10cSrcweir { 176cdf0e10cSrcweir piTmpConnection->Release( ); 177cdf0e10cSrcweir dlPrompt->Release( ); 178cdf0e10cSrcweir return connstr; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir if( FAILED( hr ) ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir // Prompt for new connection information. 184cdf0e10cSrcweir piTmpConnection->Release( ); 185cdf0e10cSrcweir piTmpConnection = NULL; 186cdf0e10cSrcweir hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection); 187cdf0e10cSrcweir if( FAILED( hr ) || !piTmpConnection ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir dlPrompt->Release( ); 190cdf0e10cSrcweir return connstr; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir hr = piTmpConnection->get_ConnectionString(&_result); 195cdf0e10cSrcweir if( FAILED( hr ) ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir piTmpConnection->Release( ); 198cdf0e10cSrcweir dlPrompt->Release( ); 199cdf0e10cSrcweir return connstr; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir piTmpConnection->Release( ); 203cdf0e10cSrcweir dlPrompt->Release( ); 204cdf0e10cSrcweir CoUninitialize(); 205cdf0e10cSrcweir return _result; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir #endif 208