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 ************************************************************************/
31 #error Need C++ to compile
39 #pragma warning(push, 1)
40 #pragma warning(disable:4005)
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();
64 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
65 FORMAT_MESSAGE_FROM_SYSTEM
,
68 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
74 // Display the string.
75 MessageBox( NULL
, (LPCTSTR
)lpMsgBuf
, NULL
, MB_OK
| MB_ICONERROR
);
78 LocalFree( lpMsgBuf
);
83 /** registers the window class for our application's main window
85 BOOL
registerWindowClass( HINSTANCE _hAppInstance
)
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
126 // main window function
128 extern "C" int APIENTRY
WinMain( HINSTANCE _hAppInstance
, HINSTANCE
, LPSTR
, int )
130 extern "C" int APIENTRY
_tWinMain( HINSTANCE _hAppInstance
, HINSTANCE
, LPTSTR
, int )
133 if ( !registerWindowClass( _hAppInstance
) )
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
);
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */