Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / dlg / adodatalinks.cxx
blob989c877fba827b579f0c50e34aa014d2eafb8c46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #if defined(WNT)
32 #if defined _MSC_VER
33 #pragma warning(push, 1)
34 #pragma warning(disable: 4917)
35 #endif
36 #include "msdasc.h" // OLE DB Service Component header
37 #if defined _MSC_VER
38 #pragma warning(push, 1)
39 #endif
40 #include "stdio.h"
42 #include <initguid.h> // Include only once in your application
43 #include <adoid.h> // needed for CLSID_CADOConnection
44 #include <adoint.h> // needed for ADOConnection
46 #include "adodatalinks.hxx"
48 #ifdef __MINGW32__
49 const IID IID_IDataSourceLocator = { 0x2206CCB2, 0x19C1, 0x11D1, { 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29 } };
50 const CLSID CLSID_DataLinks = { 0x2206CDB2, 0x19C1, 0x11D1, { 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29 } };
51 #endif
54 BSTR PromptEdit(long hWnd,BSTR connstr);
55 BSTR PromptNew(long hWnd);
57 ::rtl::OUString getAdoDatalink(long hWnd,::rtl::OUString& oldLink)
59 ::rtl::OUString dataLink;
60 if (oldLink.getLength())
62 dataLink=reinterpret_cast<sal_Unicode *>(PromptEdit(hWnd,(BSTR)oldLink.getStr()));
64 else
65 dataLink=reinterpret_cast<sal_Unicode *>(PromptNew(hWnd));
66 return dataLink;
68 BSTR PromptNew(long hWnd)
70 BSTR connstr=NULL;
71 HRESULT hr;
72 IDataSourceLocator* dlPrompt = NULL;
73 ADOConnection* piTmpConnection = NULL;
74 BSTR _result=NULL;
76 // Initialize COM
77 ::CoInitialize( NULL );
79 // Instantiate DataLinks object.
80 hr = CoCreateInstance(
81 CLSID_DataLinks, //clsid -- Data Links UI
82 NULL, //pUnkOuter
83 CLSCTX_INPROC_SERVER, //dwClsContext
84 IID_IDataSourceLocator, //riid
85 (void**)&dlPrompt //ppvObj
87 if( FAILED( hr ) )
89 piTmpConnection->Release( );
90 dlPrompt->Release( );
91 return connstr;
94 dlPrompt->put_hWnd(hWnd);
95 if( FAILED( hr ) )
97 piTmpConnection->Release( );
98 dlPrompt->Release( );
99 return connstr;
102 // Prompt for connection information.
103 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection);
105 if( FAILED( hr ) || !piTmpConnection )
107 dlPrompt->Release( );
108 return connstr;
111 hr = piTmpConnection->get_ConnectionString(&_result);
112 if( FAILED( hr ) )
114 piTmpConnection->Release( );
115 dlPrompt->Release( );
116 return connstr;
119 piTmpConnection->Release( );
120 dlPrompt->Release( );
121 CoUninitialize();
122 return _result;
125 BSTR PromptEdit(long hWnd,BSTR connstr)
127 HRESULT hr;
128 IDataSourceLocator* dlPrompt = NULL;
129 ADOConnection* piTmpConnection = NULL;
130 BSTR _result=NULL;
132 // Initialize COM
133 ::CoInitialize( NULL );
135 hr = CoCreateInstance(CLSID_CADOConnection,
136 NULL,
137 CLSCTX_INPROC_SERVER,
138 IID_IADOConnection,
139 (LPVOID *)&piTmpConnection);
140 if( FAILED( hr ) )
142 piTmpConnection->Release( );
143 return connstr;
147 hr = piTmpConnection->put_ConnectionString(connstr);
148 if( FAILED( hr ) )
150 piTmpConnection->Release( );
151 return connstr;
154 // Instantiate DataLinks object.
155 hr = CoCreateInstance(
156 CLSID_DataLinks, //clsid -- Data Links UI
157 NULL, //pUnkOuter
158 CLSCTX_INPROC_SERVER, //dwClsContext
159 IID_IDataSourceLocator, //riid
160 (void**)&dlPrompt //ppvObj
162 if( FAILED( hr ) )
164 piTmpConnection->Release( );
165 dlPrompt->Release( );
166 return connstr;
169 dlPrompt->put_hWnd(hWnd);
170 if( FAILED( hr ) )
172 piTmpConnection->Release( );
173 dlPrompt->Release( );
174 return connstr;
177 VARIANT_BOOL pbSuccess;
179 // Prompt for connection information.
180 hr = dlPrompt->PromptEdit((IDispatch **)&piTmpConnection,&pbSuccess);
181 if( SUCCEEDED( hr ) && sal_False == pbSuccess ) //if user press cancel then sal_False == pbSuccess
183 piTmpConnection->Release( );
184 dlPrompt->Release( );
185 return connstr;
188 if( FAILED( hr ) )
190 // Prompt for new connection information.
191 piTmpConnection->Release( );
192 piTmpConnection = NULL;
193 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection);
194 if( FAILED( hr ) || !piTmpConnection )
196 dlPrompt->Release( );
197 return connstr;
201 hr = piTmpConnection->get_ConnectionString(&_result);
202 if( FAILED( hr ) )
204 piTmpConnection->Release( );
205 dlPrompt->Release( );
206 return connstr;
209 piTmpConnection->Release( );
210 dlPrompt->Release( );
211 CoUninitialize();
212 return _result;
214 #endif
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */