1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adodatalinks.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
35 #if defined(WIN) || defined(WNT)
37 #pragma warning(push, 1)
38 #pragma warning(disable: 4917)
40 #include "msdasc.h" // OLE DB Service Component header
42 #pragma warning(push, 1)
46 #include <initguid.h> // Include only once in your application
47 #include <adoid.h> // needed for CLSID_CADOConnection
48 #include <adoint.h> // needed for ADOConnection
50 #ifndef _DBAUI_ADO_DATALINK_HXX_
51 #include "adodatalinks.hxx"
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
) && FALSE
== pbSuccess
) //if user press cancel then 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( );