bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / dlg / adodatalinks.cxx
bloba6dcb45b0f97bed43510cdbb4259dd59b8f17de4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #if defined(WNT)
23 #if defined _MSC_VER
24 #pragma warning(push, 1)
25 #pragma warning(disable: 4917)
26 #endif
27 // LO/windows.h conflict
28 #undef WB_LEFT
29 #undef WB_RIGHT
30 #include "msdasc.h" // OLE DB Service Component header
31 #if defined _MSC_VER
32 #pragma warning(push, 1)
33 #endif
34 #include "stdio.h"
36 #include <initguid.h> // Include only once in your application
37 #include <adoid.h> // needed for CLSID_CADOConnection
38 #include <adoint.h> // needed for ADOConnection
40 #include "adodatalinks.hxx"
42 #ifdef __MINGW32__
43 const IID IID_IDataSourceLocator = { 0x2206CCB2, 0x19C1, 0x11D1, { 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29 } };
44 const CLSID CLSID_DataLinks = { 0x2206CDB2, 0x19C1, 0x11D1, { 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29 } };
45 #endif
48 BSTR PromptEdit(long hWnd,BSTR connstr);
49 BSTR PromptNew(long hWnd);
51 OUString getAdoDatalink(long hWnd,OUString& oldLink)
53 OUString dataLink;
54 if (!oldLink.isEmpty())
56 dataLink=reinterpret_cast<sal_Unicode *>(PromptEdit(hWnd,(BSTR)oldLink.getStr()));
58 else
59 dataLink=reinterpret_cast<sal_Unicode *>(PromptNew(hWnd));
60 return dataLink;
62 BSTR PromptNew(long hWnd)
64 BSTR connstr=NULL;
65 HRESULT hr;
66 IDataSourceLocator* dlPrompt = NULL;
67 ADOConnection* piTmpConnection = NULL;
68 BSTR _result=NULL;
70 // Initialize COM
71 ::CoInitialize( NULL );
73 // Instantiate DataLinks object.
74 hr = CoCreateInstance(
75 CLSID_DataLinks, //clsid -- Data Links UI
76 NULL, //pUnkOuter
77 CLSCTX_INPROC_SERVER, //dwClsContext
78 IID_IDataSourceLocator, //riid
79 (void**)&dlPrompt //ppvObj
81 if( FAILED( hr ) )
83 piTmpConnection->Release( );
84 dlPrompt->Release( );
85 return connstr;
88 dlPrompt->put_hWnd(hWnd);
89 if( FAILED( hr ) )
91 piTmpConnection->Release( );
92 dlPrompt->Release( );
93 return connstr;
96 // Prompt for connection information.
97 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection);
99 if( FAILED( hr ) || !piTmpConnection )
101 dlPrompt->Release( );
102 return connstr;
105 hr = piTmpConnection->get_ConnectionString(&_result);
106 if( FAILED( hr ) )
108 piTmpConnection->Release( );
109 dlPrompt->Release( );
110 return connstr;
113 piTmpConnection->Release( );
114 dlPrompt->Release( );
115 CoUninitialize();
116 return _result;
119 BSTR PromptEdit(long hWnd,BSTR connstr)
121 HRESULT hr;
122 IDataSourceLocator* dlPrompt = NULL;
123 ADOConnection* piTmpConnection = NULL;
124 BSTR _result=NULL;
126 // Initialize COM
127 ::CoInitialize( NULL );
129 hr = CoCreateInstance(CLSID_CADOConnection,
130 NULL,
131 CLSCTX_INPROC_SERVER,
132 IID_IADOConnection,
133 (LPVOID *)&piTmpConnection);
134 if( FAILED( hr ) )
136 piTmpConnection->Release( );
137 return connstr;
141 hr = piTmpConnection->put_ConnectionString(connstr);
142 if( FAILED( hr ) )
144 piTmpConnection->Release( );
145 return connstr;
148 // Instantiate DataLinks object.
149 hr = CoCreateInstance(
150 CLSID_DataLinks, //clsid -- Data Links UI
151 NULL, //pUnkOuter
152 CLSCTX_INPROC_SERVER, //dwClsContext
153 IID_IDataSourceLocator, //riid
154 (void**)&dlPrompt //ppvObj
156 if( FAILED( hr ) )
158 piTmpConnection->Release( );
159 dlPrompt->Release( );
160 return connstr;
163 dlPrompt->put_hWnd(hWnd);
164 if( FAILED( hr ) )
166 piTmpConnection->Release( );
167 dlPrompt->Release( );
168 return connstr;
171 VARIANT_BOOL pbSuccess;
173 // Prompt for connection information.
174 hr = dlPrompt->PromptEdit((IDispatch **)&piTmpConnection,&pbSuccess);
175 if( SUCCEEDED( hr ) && sal_False == pbSuccess ) //if user press cancel then sal_False == pbSuccess
177 piTmpConnection->Release( );
178 dlPrompt->Release( );
179 return connstr;
182 if( FAILED( hr ) )
184 // Prompt for new connection information.
185 piTmpConnection->Release( );
186 piTmpConnection = NULL;
187 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection);
188 if( FAILED( hr ) || !piTmpConnection )
190 dlPrompt->Release( );
191 return connstr;
195 hr = piTmpConnection->get_ConnectionString(&_result);
196 if( FAILED( hr ) )
198 piTmpConnection->Release( );
199 dlPrompt->Release( );
200 return connstr;
203 piTmpConnection->Release( );
204 dlPrompt->Release( );
205 CoUninitialize();
206 return _result;
208 #endif
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */