1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifndef __cplusplus 32*cdf0e10cSrcweir #error Need C++ to compile 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #define UNICODE 36*cdf0e10cSrcweir #define _UNICODE 37*cdf0e10cSrcweir #include <tchar.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #ifdef _MSC_VER 40*cdf0e10cSrcweir #pragma warning(push, 1) 41*cdf0e10cSrcweir #pragma warning(disable:4005) 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <windows.h> 45*cdf0e10cSrcweir #include <shellapi.h> 46*cdf0e10cSrcweir #include <sqlext.h> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #ifdef _MSC_VER 49*cdf0e10cSrcweir #pragma warning(pop) 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // the name of the library which contains the SQLManageDataSources function 53*cdf0e10cSrcweir #define ODBC_UI_LIB_NAME L"ODBCCP32.DLL" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // the signature of the SQLManageDataSources function 56*cdf0e10cSrcweir typedef SQLRETURN (SQL_API* TSQLManageDataSource) (SQLHWND hwndParent); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // displays the error text for the last error (GetLastError), and returns this error value 59*cdf0e10cSrcweir int displayLastError() 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir DWORD dwError = GetLastError(); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir LPVOID lpMsgBuf; 64*cdf0e10cSrcweir FormatMessage( 65*cdf0e10cSrcweir FORMAT_MESSAGE_ALLOCATE_BUFFER | 66*cdf0e10cSrcweir FORMAT_MESSAGE_FROM_SYSTEM, 67*cdf0e10cSrcweir NULL, 68*cdf0e10cSrcweir dwError, 69*cdf0e10cSrcweir MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 70*cdf0e10cSrcweir (LPTSTR)&lpMsgBuf, 71*cdf0e10cSrcweir 0, 72*cdf0e10cSrcweir NULL 73*cdf0e10cSrcweir ); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // Display the string. 76*cdf0e10cSrcweir MessageBox( NULL, (LPCTSTR)lpMsgBuf, NULL, MB_OK | MB_ICONERROR ); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // Free the buffer. 79*cdf0e10cSrcweir LocalFree( lpMsgBuf ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir return dwError; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir /** registers the window class for our application's main window 85*cdf0e10cSrcweir */ 86*cdf0e10cSrcweir BOOL registerWindowClass( HINSTANCE _hAppInstance ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir WNDCLASSEX wcx; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir wcx.cbSize = sizeof(wcx); // size of structure 91*cdf0e10cSrcweir wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes 92*cdf0e10cSrcweir wcx.lpfnWndProc = DefWindowProc; // points to window procedure 93*cdf0e10cSrcweir wcx.cbClsExtra = 0; // no extra class memory 94*cdf0e10cSrcweir wcx.cbWndExtra = 0; // no extra window memory 95*cdf0e10cSrcweir wcx.hInstance = _hAppInstance; // handle to instance 96*cdf0e10cSrcweir wcx.hIcon = NULL; // predefined app. icon 97*cdf0e10cSrcweir wcx.hCursor = NULL; // predefined arrow 98*cdf0e10cSrcweir wcx.hbrBackground = NULL; // no background brush 99*cdf0e10cSrcweir wcx.lpszMenuName = NULL; // name of menu resource 100*cdf0e10cSrcweir wcx.lpszClassName = L"ODBCConfigMainClass"; // name of window class 101*cdf0e10cSrcweir wcx.hIconSm = NULL; // small class icon 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir return ( NULL != RegisterClassEx( &wcx ) ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /// initializes the application instances 107*cdf0e10cSrcweir HWND initInstance( HINSTANCE _hAppInstance ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir HWND hWindow = CreateWindow( 110*cdf0e10cSrcweir L"ODBCConfigMainClass", // name of window class 111*cdf0e10cSrcweir L"ODBC Config Wrapper", // title-bar string 112*cdf0e10cSrcweir WS_OVERLAPPEDWINDOW, // top-level window 113*cdf0e10cSrcweir CW_USEDEFAULT, // default horizontal position 114*cdf0e10cSrcweir CW_USEDEFAULT, // default vertical position 115*cdf0e10cSrcweir CW_USEDEFAULT, // default width 116*cdf0e10cSrcweir CW_USEDEFAULT, // default height 117*cdf0e10cSrcweir (HWND) NULL, // no owner window 118*cdf0e10cSrcweir (HMENU) NULL, // use class menu 119*cdf0e10cSrcweir _hAppInstance, // handle to application instance 120*cdf0e10cSrcweir (LPVOID) NULL); // no window-creation data 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // don't show the window, we only need it as parent handle for the 123*cdf0e10cSrcweir // SQLManageDataSources function 124*cdf0e10cSrcweir return hWindow; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // main window function 128*cdf0e10cSrcweir #ifdef __MINGW32__ 129*cdf0e10cSrcweir extern "C" int APIENTRY WinMain( HINSTANCE _hAppInstance, HINSTANCE, LPSTR, int ) 130*cdf0e10cSrcweir #else 131*cdf0e10cSrcweir extern "C" int APIENTRY _tWinMain( HINSTANCE _hAppInstance, HINSTANCE, LPTSTR, int ) 132*cdf0e10cSrcweir #endif 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir if ( !registerWindowClass( _hAppInstance ) ) 135*cdf0e10cSrcweir return FALSE; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir HWND hAppWindow = initInstance( _hAppInstance ); 138*cdf0e10cSrcweir if ( !IsWindow( hAppWindow ) ) 139*cdf0e10cSrcweir return displayLastError(); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir HMODULE hModule = LoadLibraryW( ODBC_UI_LIB_NAME ); 142*cdf0e10cSrcweir if ( hModule == NULL ) 143*cdf0e10cSrcweir hModule = LoadLibraryExW( ODBC_UI_LIB_NAME, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); 144*cdf0e10cSrcweir if ( hModule == NULL ) 145*cdf0e10cSrcweir return displayLastError(); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir FARPROC pManageDSProc = GetProcAddress( hModule, "SQLManageDataSources" ); 148*cdf0e10cSrcweir if ( pManageDSProc == NULL ) 149*cdf0e10cSrcweir return displayLastError(); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir TSQLManageDataSource pManageDS = (TSQLManageDataSource)pManageDSProc; 152*cdf0e10cSrcweir if ( !( (*pManageDS)( hAppWindow ) ) ) 153*cdf0e10cSrcweir return displayLastError(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir FreeLibrary( hModule ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir return 0; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160