1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 #pragma warning(push, 1)
25 #pragma warning(disable: 4917)
27 // LO/windows.h conflict
32 #pragma warning(push, 1)
39 #include "adodatalinks.hxx"
42 const IID IID_IDataSourceLocator
= { 0x2206CCB2, 0x19C1, 0x11D1, { 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29 } };
43 const CLSID CLSID_DataLinks
= { 0x2206CDB2, 0x19C1, 0x11D1, { 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29 } };
47 BSTR
PromptEdit(long hWnd
,BSTR connstr
);
48 BSTR
PromptNew(long hWnd
);
50 OUString
getAdoDatalink(long hWnd
,OUString
& oldLink
)
53 if (!oldLink
.isEmpty())
55 dataLink
=reinterpret_cast<sal_Unicode
*>(PromptEdit(hWnd
,(BSTR
)oldLink
.getStr()));
58 dataLink
=reinterpret_cast<sal_Unicode
*>(PromptNew(hWnd
));
62 BSTR
PromptNew(long hWnd
)
66 IDataSourceLocator
* dlPrompt
= NULL
;
67 ADOConnection
* piTmpConnection
= NULL
;
71 ::CoInitialize( NULL
);
73 // Instantiate DataLinks object.
74 hr
= CoCreateInstance(
75 CLSID_DataLinks
, //clsid -- Data Links UI
77 CLSCTX_INPROC_SERVER
, //dwClsContext
78 IID_IDataSourceLocator
, //riid
79 (void**)&dlPrompt
//ppvObj
86 dlPrompt
->put_hWnd(hWnd
);
93 // Prompt for connection information.
94 hr
= dlPrompt
->PromptNew((IDispatch
**)&piTmpConnection
);
96 if( FAILED( hr
) || !piTmpConnection
)
102 hr
= piTmpConnection
->get_ConnectionString(&_result
);
105 piTmpConnection
->Release( );
106 dlPrompt
->Release( );
110 piTmpConnection
->Release( );
111 dlPrompt
->Release( );
116 BSTR
PromptEdit(long hWnd
,BSTR connstr
)
119 IDataSourceLocator
* dlPrompt
= NULL
;
120 ADOConnection
* piTmpConnection
= NULL
;
124 ::CoInitialize( NULL
);
126 hr
= CoCreateInstance(CLSID_CADOConnection
,
128 CLSCTX_INPROC_SERVER
,
130 (LPVOID
*)&piTmpConnection
);
133 piTmpConnection
->Release( );
138 hr
= piTmpConnection
->put_ConnectionString(connstr
);
141 piTmpConnection
->Release( );
145 // Instantiate DataLinks object.
146 hr
= CoCreateInstance(
147 CLSID_DataLinks
, //clsid -- Data Links UI
149 CLSCTX_INPROC_SERVER
, //dwClsContext
150 IID_IDataSourceLocator
, //riid
151 (void**)&dlPrompt
//ppvObj
155 piTmpConnection
->Release( );
156 dlPrompt
->Release( );
160 dlPrompt
->put_hWnd(hWnd
);
163 piTmpConnection
->Release( );
164 dlPrompt
->Release( );
168 VARIANT_BOOL pbSuccess
;
170 // Prompt for connection information.
171 hr
= dlPrompt
->PromptEdit((IDispatch
**)&piTmpConnection
,&pbSuccess
);
172 if( SUCCEEDED( hr
) && sal_False
== pbSuccess
) //if user press cancel then sal_False == pbSuccess
174 piTmpConnection
->Release( );
175 dlPrompt
->Release( );
181 // Prompt for new connection information.
182 piTmpConnection
->Release( );
183 piTmpConnection
= NULL
;
184 hr
= dlPrompt
->PromptNew((IDispatch
**)&piTmpConnection
);
185 if( FAILED( hr
) || !piTmpConnection
)
187 dlPrompt
->Release( );
192 hr
= piTmpConnection
->get_ConnectionString(&_result
);
195 piTmpConnection
->Release( );
196 dlPrompt
->Release( );
200 piTmpConnection
->Release( );
201 dlPrompt
->Release( );
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */