Update ooo320-m1
[ooovba.git] / dbaccess / win32 / source / odbcconfig / odbcconfig.cxx
blobb6da54bf942c18589c6c8258adc97588c78b0e6c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: odbcconfig.cxx,v $
10 * $Revision: 1.4 $
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"
34 #ifndef __cplusplus
35 #error Need C++ to compile
36 #endif
38 #define UNICODE
39 #define _UNICODE
40 #include <tchar.h>
42 #ifdef _MSC_VER
43 #pragma warning(push, 1)
44 #pragma warning(disable:4005)
45 #endif
47 #include <windows.h>
48 #include <shellapi.h>
49 #include <sqlext.h>
51 #ifdef _MSC_VER
52 #pragma warning(pop)
53 #endif
55 // the name of the library which contains the SQLManageDataSources function
56 #define ODBC_UI_LIB_NAME L"ODBCCP32.DLL"
58 // the signature of the SQLManageDataSources function
59 typedef SQLRETURN (SQL_API* TSQLManageDataSource) (SQLHWND hwndParent);
61 // displays the error text for the last error (GetLastError), and returns this error value
62 int displayLastError()
64 DWORD dwError = GetLastError();
66 LPVOID lpMsgBuf;
67 FormatMessage(
68 FORMAT_MESSAGE_ALLOCATE_BUFFER |
69 FORMAT_MESSAGE_FROM_SYSTEM,
70 NULL,
71 dwError,
72 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
73 (LPTSTR)&lpMsgBuf,
75 NULL
78 // Display the string.
79 MessageBox( NULL, (LPCTSTR)lpMsgBuf, NULL, MB_OK | MB_ICONERROR );
81 // Free the buffer.
82 LocalFree( lpMsgBuf );
84 return dwError;
87 /** registers the window class for our application's main window
89 BOOL registerWindowClass( HINSTANCE _hAppInstance )
91 WNDCLASSEX wcx;
93 wcx.cbSize = sizeof(wcx); // size of structure
94 wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes
95 wcx.lpfnWndProc = DefWindowProc; // points to window procedure
96 wcx.cbClsExtra = 0; // no extra class memory
97 wcx.cbWndExtra = 0; // no extra window memory
98 wcx.hInstance = _hAppInstance; // handle to instance
99 wcx.hIcon = NULL; // predefined app. icon
100 wcx.hCursor = NULL; // predefined arrow
101 wcx.hbrBackground = NULL; // no background brush
102 wcx.lpszMenuName = NULL; // name of menu resource
103 wcx.lpszClassName = L"ODBCConfigMainClass"; // name of window class
104 wcx.hIconSm = NULL; // small class icon
106 return ( NULL != RegisterClassEx( &wcx ) );
109 /// initializes the application instances
110 HWND initInstance( HINSTANCE _hAppInstance )
112 HWND hWindow = CreateWindow(
113 L"ODBCConfigMainClass", // name of window class
114 L"ODBC Config Wrapper", // title-bar string
115 WS_OVERLAPPEDWINDOW, // top-level window
116 CW_USEDEFAULT, // default horizontal position
117 CW_USEDEFAULT, // default vertical position
118 CW_USEDEFAULT, // default width
119 CW_USEDEFAULT, // default height
120 (HWND) NULL, // no owner window
121 (HMENU) NULL, // use class menu
122 _hAppInstance, // handle to application instance
123 (LPVOID) NULL); // no window-creation data
125 // don't show the window, we only need it as parent handle for the
126 // SQLManageDataSources function
127 return hWindow;
130 // main window function
131 #ifdef __MINGW32__
132 extern "C" int APIENTRY WinMain( HINSTANCE _hAppInstance, HINSTANCE, LPSTR, int )
133 #else
134 extern "C" int APIENTRY _tWinMain( HINSTANCE _hAppInstance, HINSTANCE, LPTSTR, int )
135 #endif
137 if ( !registerWindowClass( _hAppInstance ) )
138 return FALSE;
140 HWND hAppWindow = initInstance( _hAppInstance );
141 if ( !IsWindow( hAppWindow ) )
142 return displayLastError();
144 HMODULE hModule = LoadLibraryW( ODBC_UI_LIB_NAME );
145 if ( hModule == NULL )
146 hModule = LoadLibraryExW( ODBC_UI_LIB_NAME, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
147 if ( hModule == NULL )
148 return displayLastError();
150 FARPROC pManageDSProc = GetProcAddress( hModule, "SQLManageDataSources" );
151 if ( pManageDSProc == NULL )
152 return displayLastError();
154 TSQLManageDataSource pManageDS = (TSQLManageDataSource)pManageDSProc;
155 if ( !( (*pManageDS)( hAppWindow ) ) )
156 return displayLastError();
158 FreeLibrary( hModule );
160 return 0;