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
30 #include "msdasc.h" // OLE DB Service Component header
32 #pragma warning(push, 1)
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"
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 } };
48 BSTR
PromptEdit(long hWnd
,BSTR connstr
);
49 BSTR
PromptNew(long hWnd
);
51 OUString
getAdoDatalink(long hWnd
,OUString
& oldLink
)
54 if (!oldLink
.isEmpty())
56 dataLink
=reinterpret_cast<sal_Unicode
*>(PromptEdit(hWnd
,(BSTR
)oldLink
.getStr()));
59 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
83 piTmpConnection
->Release( );
88 dlPrompt
->put_hWnd(hWnd
);
91 piTmpConnection
->Release( );
96 // Prompt for connection information.
97 hr
= dlPrompt
->PromptNew((IDispatch
**)&piTmpConnection
);
99 if( FAILED( hr
) || !piTmpConnection
)
101 dlPrompt
->Release( );
105 hr
= piTmpConnection
->get_ConnectionString(&_result
);
108 piTmpConnection
->Release( );
109 dlPrompt
->Release( );
113 piTmpConnection
->Release( );
114 dlPrompt
->Release( );
119 BSTR
PromptEdit(long hWnd
,BSTR connstr
)
122 IDataSourceLocator
* dlPrompt
= NULL
;
123 ADOConnection
* piTmpConnection
= NULL
;
127 ::CoInitialize( NULL
);
129 hr
= CoCreateInstance(CLSID_CADOConnection
,
131 CLSCTX_INPROC_SERVER
,
133 (LPVOID
*)&piTmpConnection
);
136 piTmpConnection
->Release( );
141 hr
= piTmpConnection
->put_ConnectionString(connstr
);
144 piTmpConnection
->Release( );
148 // Instantiate DataLinks object.
149 hr
= CoCreateInstance(
150 CLSID_DataLinks
, //clsid -- Data Links UI
152 CLSCTX_INPROC_SERVER
, //dwClsContext
153 IID_IDataSourceLocator
, //riid
154 (void**)&dlPrompt
//ppvObj
158 piTmpConnection
->Release( );
159 dlPrompt
->Release( );
163 dlPrompt
->put_hWnd(hWnd
);
166 piTmpConnection
->Release( );
167 dlPrompt
->Release( );
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( );
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( );
195 hr
= piTmpConnection
->get_ConnectionString(&_result
);
198 piTmpConnection
->Release( );
199 dlPrompt
->Release( );
203 piTmpConnection
->Release( );
204 dlPrompt
->Release( );
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */