Bump for 3.6-28
[LibreOffice.git] / dbaccess / win32 / source / odbcconfig / odbcconfig.cxx
blob0c07fc444fb77f47d55dfd37c3ede20dfff42447
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 ************************************************************************/
30 #ifndef __cplusplus
31 #error Need C++ to compile
32 #endif
34 #define UNICODE
35 #define _UNICODE
36 #include <tchar.h>
38 #ifdef _MSC_VER
39 #pragma warning(push, 1)
40 #pragma warning(disable:4005)
41 #endif
43 #include <windows.h>
44 #include <shellapi.h>
45 #include <sqlext.h>
47 #ifdef _MSC_VER
48 #pragma warning(pop)
49 #endif
51 // the name of the library which contains the SQLManageDataSources function
52 #define ODBC_UI_LIB_NAME L"ODBCCP32.DLL"
54 // the signature of the SQLManageDataSources function
55 typedef SQLRETURN (SQL_API* TSQLManageDataSource) (SQLHWND hwndParent);
57 // displays the error text for the last error (GetLastError), and returns this error value
58 int displayLastError()
60 DWORD dwError = GetLastError();
62 LPVOID lpMsgBuf;
63 FormatMessage(
64 FORMAT_MESSAGE_ALLOCATE_BUFFER |
65 FORMAT_MESSAGE_FROM_SYSTEM,
66 NULL,
67 dwError,
68 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
69 (LPTSTR)&lpMsgBuf,
71 NULL
74 // Display the string.
75 MessageBox( NULL, (LPCTSTR)lpMsgBuf, NULL, MB_OK | MB_ICONERROR );
77 // Free the buffer.
78 LocalFree( lpMsgBuf );
80 return dwError;
83 /** registers the window class for our application's main window
85 BOOL registerWindowClass( HINSTANCE _hAppInstance )
87 WNDCLASSEX wcx;
89 wcx.cbSize = sizeof(wcx); // size of structure
90 wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes
91 wcx.lpfnWndProc = DefWindowProc; // points to window procedure
92 wcx.cbClsExtra = 0; // no extra class memory
93 wcx.cbWndExtra = 0; // no extra window memory
94 wcx.hInstance = _hAppInstance; // handle to instance
95 wcx.hIcon = NULL; // predefined app. icon
96 wcx.hCursor = NULL; // predefined arrow
97 wcx.hbrBackground = NULL; // no background brush
98 wcx.lpszMenuName = NULL; // name of menu resource
99 wcx.lpszClassName = L"ODBCConfigMainClass"; // name of window class
100 wcx.hIconSm = NULL; // small class icon
102 return ( NULL != RegisterClassEx( &wcx ) );
105 /// initializes the application instances
106 HWND initInstance( HINSTANCE _hAppInstance )
108 HWND hWindow = CreateWindow(
109 L"ODBCConfigMainClass", // name of window class
110 L"ODBC Config Wrapper", // title-bar string
111 WS_OVERLAPPEDWINDOW, // top-level window
112 CW_USEDEFAULT, // default horizontal position
113 CW_USEDEFAULT, // default vertical position
114 CW_USEDEFAULT, // default width
115 CW_USEDEFAULT, // default height
116 (HWND) NULL, // no owner window
117 (HMENU) NULL, // use class menu
118 _hAppInstance, // handle to application instance
119 (LPVOID) NULL); // no window-creation data
121 // don't show the window, we only need it as parent handle for the
122 // SQLManageDataSources function
123 return hWindow;
126 // main window function
127 #ifdef __MINGW32__
128 extern "C" int APIENTRY WinMain( HINSTANCE _hAppInstance, HINSTANCE, LPSTR, int )
129 #else
130 extern "C" int APIENTRY _tWinMain( HINSTANCE _hAppInstance, HINSTANCE, LPTSTR, int )
131 #endif
133 if ( !registerWindowClass( _hAppInstance ) )
134 return FALSE;
136 HWND hAppWindow = initInstance( _hAppInstance );
137 if ( !IsWindow( hAppWindow ) )
138 return displayLastError();
140 HMODULE hModule = LoadLibraryW( ODBC_UI_LIB_NAME );
141 if ( hModule == NULL )
142 hModule = LoadLibraryExW( ODBC_UI_LIB_NAME, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
143 if ( hModule == NULL )
144 return displayLastError();
146 FARPROC pManageDSProc = GetProcAddress( hModule, "SQLManageDataSources" );
147 if ( pManageDSProc == NULL )
148 return displayLastError();
150 TSQLManageDataSource pManageDS = (TSQLManageDataSource)pManageDSProc;
151 if ( !( (*pManageDS)( hAppWindow ) ) )
152 return displayLastError();
154 FreeLibrary( hModule );
156 return 0;
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */