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 .
22 // LO/windows.h conflict
27 #include <comphelper/scopeguard.hxx>
28 #include <o3tl/char16_t2wchar_t.hxx>
29 #include <systools/win32/comtools.hxx>
30 #include <systools/win32/oleauto.hxx>
36 #include "adodatalinks.hxx"
40 OUString
PromptNew(sal_IntPtr hWnd
)
45 sal::systools::CoInitializeGuard
aGuard(COINIT_APARTMENTTHREADED
);
47 // Instantiate DataLinks object.
48 sal::systools::COMReference
<IDataSourceLocator
> dlPrompt
;
49 dlPrompt
.CoCreateInstance(CLSID_DataLinks
, //clsid -- Data Links UI
51 CLSCTX_INPROC_SERVER
); //dwClsContext
53 sal::systools::ThrowIfFailed(dlPrompt
->put_hWnd(hWnd
), "put_hWnd failed");
55 // Prompt for connection information.
56 sal::systools::COMReference
<IDispatch
> piDispatch
;
57 sal::systools::ThrowIfFailed(dlPrompt
->PromptNew(&piDispatch
), "PromptNew failed");
58 sal::systools::COMReference
<ADOConnection
> piTmpConnection(piDispatch
,
59 sal::systools::COM_QUERY_THROW
);
61 sal::systools::BStr _result
;
62 sal::systools::ThrowIfFailed(piTmpConnection
->get_ConnectionString(&_result
),
63 "get_ConnectionString failed");
65 return OUString(_result
);
67 catch (const sal::systools::ComError
&)
73 OUString
PromptEdit(sal_IntPtr hWnd
, OUString
const & connstr
)
78 sal::systools::CoInitializeGuard
aGuard(COINIT_APARTMENTTHREADED
);
80 sal::systools::COMReference
<ADOConnection
> piTmpConnection
;
81 piTmpConnection
.CoCreateInstance(CLSID_CADOConnection
, nullptr, CLSCTX_INPROC_SERVER
);
83 sal::systools::ThrowIfFailed(
84 piTmpConnection
->put_ConnectionString(sal::systools::BStr(connstr
)),
85 "put_ConnectionString failed");
87 // Instantiate DataLinks object.
88 sal::systools::COMReference
<IDataSourceLocator
> dlPrompt
;
89 dlPrompt
.CoCreateInstance(CLSID_DataLinks
, //clsid -- Data Links UI
91 CLSCTX_INPROC_SERVER
); //dwClsContext
93 sal::systools::ThrowIfFailed(dlPrompt
->put_hWnd(hWnd
), "put_hWnd failed");
97 // Prompt for connection information.
98 IDispatch
* piDispatch
= piTmpConnection
.get();
99 VARIANT_BOOL pbSuccess
;
100 sal::systools::ThrowIfFailed(dlPrompt
->PromptEdit(&piDispatch
, &pbSuccess
),
101 "PromptEdit failed");
102 if (!pbSuccess
) //if user press cancel then sal_False == pbSuccess
105 catch (const sal::systools::ComError
&)
107 // Prompt for new connection information.
108 sal::systools::COMReference
<IDispatch
> piDispatch
;
109 sal::systools::ThrowIfFailed(dlPrompt
->PromptNew(&piDispatch
), "PromptNew failed");
110 piTmpConnection
.set(piDispatch
, sal::systools::COM_QUERY_THROW
);
113 sal::systools::BStr _result
;
114 sal::systools::ThrowIfFailed(piTmpConnection
->get_ConnectionString(&_result
),
115 "get_ConnectionString failed");
117 return OUString(_result
);
119 catch (const sal::systools::ComError
&)
127 OUString
getAdoDatalink(sal_IntPtr hWnd
,OUString
const & oldLink
)
130 if (!oldLink
.isEmpty())
132 dataLink
=PromptEdit(hWnd
,oldLink
);
135 dataLink
=PromptNew(hWnd
);
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */