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 ************************************************************************/
33 #pragma warning(push, 1)
34 #pragma warning(disable: 4917)
36 #include "msdasc.h" // OLE DB Service Component header
38 #pragma warning(push, 1)
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"
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 } };
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()));
65 dataLink
=reinterpret_cast<sal_Unicode
*>(PromptNew(hWnd
));
68 BSTR
PromptNew(long hWnd
)
72 IDataSourceLocator
* dlPrompt
= NULL
;
73 ADOConnection
* piTmpConnection
= NULL
;
77 ::CoInitialize( NULL
);
79 // Instantiate DataLinks object.
80 hr
= CoCreateInstance(
81 CLSID_DataLinks
, //clsid -- Data Links UI
83 CLSCTX_INPROC_SERVER
, //dwClsContext
84 IID_IDataSourceLocator
, //riid
85 (void**)&dlPrompt
//ppvObj
89 piTmpConnection
->Release( );
94 dlPrompt
->put_hWnd(hWnd
);
97 piTmpConnection
->Release( );
102 // Prompt for connection information.
103 hr
= dlPrompt
->PromptNew((IDispatch
**)&piTmpConnection
);
105 if( FAILED( hr
) || !piTmpConnection
)
107 dlPrompt
->Release( );
111 hr
= piTmpConnection
->get_ConnectionString(&_result
);
114 piTmpConnection
->Release( );
115 dlPrompt
->Release( );
119 piTmpConnection
->Release( );
120 dlPrompt
->Release( );
125 BSTR
PromptEdit(long hWnd
,BSTR connstr
)
128 IDataSourceLocator
* dlPrompt
= NULL
;
129 ADOConnection
* piTmpConnection
= NULL
;
133 ::CoInitialize( NULL
);
135 hr
= CoCreateInstance(CLSID_CADOConnection
,
137 CLSCTX_INPROC_SERVER
,
139 (LPVOID
*)&piTmpConnection
);
142 piTmpConnection
->Release( );
147 hr
= piTmpConnection
->put_ConnectionString(connstr
);
150 piTmpConnection
->Release( );
154 // Instantiate DataLinks object.
155 hr
= CoCreateInstance(
156 CLSID_DataLinks
, //clsid -- Data Links UI
158 CLSCTX_INPROC_SERVER
, //dwClsContext
159 IID_IDataSourceLocator
, //riid
160 (void**)&dlPrompt
//ppvObj
164 piTmpConnection
->Release( );
165 dlPrompt
->Release( );
169 dlPrompt
->put_hWnd(hWnd
);
172 piTmpConnection
->Release( );
173 dlPrompt
->Release( );
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( );
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( );
201 hr
= piTmpConnection
->get_ConnectionString(&_result
);
204 piTmpConnection
->Release( );
205 dlPrompt
->Release( );
209 piTmpConnection
->Release( );
210 dlPrompt
->Release( );
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */