1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_dbaccess.hxx" 30 31 32 #if defined(WNT) 33 #if defined _MSC_VER 34 #pragma warning(push, 1) 35 #pragma warning(disable: 4917) 36 #endif 37 #include "msdasc.h" // OLE DB Service Component header 38 #if defined _MSC_VER 39 #pragma warning(push, 1) 40 #endif 41 #include "stdio.h" 42 43 #include <initguid.h> // Include only once in your application 44 #include <adoid.h> // needed for CLSID_CADOConnection 45 #include <adoint.h> // needed for ADOConnection 46 47 #ifndef _DBAUI_ADO_DATALINK_HXX_ 48 #include "adodatalinks.hxx" 49 #endif 50 51 BSTR PromptEdit(long hWnd,BSTR connstr); 52 BSTR PromptNew(long hWnd); 53 54 ::rtl::OUString getAdoDatalink(long hWnd,::rtl::OUString& oldLink) 55 { 56 ::rtl::OUString dataLink; 57 if (oldLink.getLength()) 58 { 59 dataLink=reinterpret_cast<sal_Unicode *>(PromptEdit(hWnd,(BSTR)oldLink.getStr())); 60 } 61 else 62 dataLink=reinterpret_cast<sal_Unicode *>(PromptNew(hWnd)); 63 return dataLink; 64 } 65 BSTR PromptNew(long hWnd) 66 { 67 BSTR connstr=NULL; 68 HRESULT hr; 69 IDataSourceLocator* dlPrompt = NULL; 70 ADOConnection* piTmpConnection = NULL; 71 BSTR _result=NULL; 72 73 // Initialize COM 74 ::CoInitialize( NULL ); 75 76 // Instantiate DataLinks object. 77 hr = CoCreateInstance( 78 CLSID_DataLinks, //clsid -- Data Links UI 79 NULL, //pUnkOuter 80 CLSCTX_INPROC_SERVER, //dwClsContext 81 IID_IDataSourceLocator, //riid 82 (void**)&dlPrompt //ppvObj 83 ); 84 if( FAILED( hr ) ) 85 { 86 piTmpConnection->Release( ); 87 dlPrompt->Release( ); 88 return connstr; 89 } 90 91 dlPrompt->put_hWnd(hWnd); 92 if( FAILED( hr ) ) 93 { 94 piTmpConnection->Release( ); 95 dlPrompt->Release( ); 96 return connstr; 97 } 98 99 // Prompt for connection information. 100 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection); 101 102 if( FAILED( hr ) || !piTmpConnection ) 103 { 104 dlPrompt->Release( ); 105 return connstr; 106 } 107 108 hr = piTmpConnection->get_ConnectionString(&_result); 109 if( FAILED( hr ) ) 110 { 111 piTmpConnection->Release( ); 112 dlPrompt->Release( ); 113 return connstr; 114 } 115 116 piTmpConnection->Release( ); 117 dlPrompt->Release( ); 118 CoUninitialize(); 119 return _result; 120 } 121 122 BSTR PromptEdit(long hWnd,BSTR connstr) 123 { 124 HRESULT hr; 125 IDataSourceLocator* dlPrompt = NULL; 126 ADOConnection* piTmpConnection = NULL; 127 BSTR _result=NULL; 128 129 // Initialize COM 130 ::CoInitialize( NULL ); 131 132 hr = CoCreateInstance(CLSID_CADOConnection, 133 NULL, 134 CLSCTX_INPROC_SERVER, 135 IID_IADOConnection, 136 (LPVOID *)&piTmpConnection); 137 if( FAILED( hr ) ) 138 { 139 piTmpConnection->Release( ); 140 return connstr; 141 } 142 143 144 hr = piTmpConnection->put_ConnectionString(connstr); 145 if( FAILED( hr ) ) 146 { 147 piTmpConnection->Release( ); 148 return connstr; 149 } 150 151 // Instantiate DataLinks object. 152 hr = CoCreateInstance( 153 CLSID_DataLinks, //clsid -- Data Links UI 154 NULL, //pUnkOuter 155 CLSCTX_INPROC_SERVER, //dwClsContext 156 IID_IDataSourceLocator, //riid 157 (void**)&dlPrompt //ppvObj 158 ); 159 if( FAILED( hr ) ) 160 { 161 piTmpConnection->Release( ); 162 dlPrompt->Release( ); 163 return connstr; 164 } 165 166 dlPrompt->put_hWnd(hWnd); 167 if( FAILED( hr ) ) 168 { 169 piTmpConnection->Release( ); 170 dlPrompt->Release( ); 171 return connstr; 172 } 173 174 VARIANT_BOOL pbSuccess; 175 176 // Prompt for connection information. 177 hr = dlPrompt->PromptEdit((IDispatch **)&piTmpConnection,&pbSuccess); 178 if( SUCCEEDED( hr ) && sal_False == pbSuccess ) //if user press cancel then sal_False == pbSuccess 179 { 180 piTmpConnection->Release( ); 181 dlPrompt->Release( ); 182 return connstr; 183 } 184 185 if( FAILED( hr ) ) 186 { 187 // Prompt for new connection information. 188 piTmpConnection->Release( ); 189 piTmpConnection = NULL; 190 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection); 191 if( FAILED( hr ) || !piTmpConnection ) 192 { 193 dlPrompt->Release( ); 194 return connstr; 195 } 196 } 197 198 hr = piTmpConnection->get_ConnectionString(&_result); 199 if( FAILED( hr ) ) 200 { 201 piTmpConnection->Release( ); 202 dlPrompt->Release( ); 203 return connstr; 204 } 205 206 piTmpConnection->Release( ); 207 dlPrompt->Release( ); 208 CoUninitialize(); 209 return _result; 210 } 211 #endif 212