1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #error Need C++ to compile
30 #pragma warning(push, 1)
31 #pragma warning(disable:4005)
42 // the name of the library which contains the SQLManageDataSources function
43 #define ODBC_UI_LIB_NAME L"ODBCCP32.DLL"
45 // the signature of the SQLManageDataSources function
46 typedef SQLRETURN (SQL_API
* TSQLManageDataSource
) (SQLHWND hwndParent
);
48 // displays the error text for the last error (GetLastError), and returns this error value
49 int displayLastError()
51 DWORD dwError
= GetLastError();
55 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
56 FORMAT_MESSAGE_FROM_SYSTEM
,
59 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
65 // Display the string.
66 MessageBox( NULL
, (LPCTSTR
)lpMsgBuf
, NULL
, MB_OK
| MB_ICONERROR
);
69 LocalFree( lpMsgBuf
);
74 /** registers the window class for our application's main window
76 BOOL
registerWindowClass( HINSTANCE _hAppInstance
)
80 wcx
.cbSize
= sizeof(wcx
); // size of structure
81 wcx
.style
= CS_HREDRAW
| CS_VREDRAW
; // redraw if size changes
82 wcx
.lpfnWndProc
= DefWindowProc
; // points to window procedure
83 wcx
.cbClsExtra
= 0; // no extra class memory
84 wcx
.cbWndExtra
= 0; // no extra window memory
85 wcx
.hInstance
= _hAppInstance
; // handle to instance
86 wcx
.hIcon
= NULL
; // predefined app. icon
87 wcx
.hCursor
= NULL
; // predefined arrow
88 wcx
.hbrBackground
= NULL
; // no background brush
89 wcx
.lpszMenuName
= NULL
; // name of menu resource
90 wcx
.lpszClassName
= L
"ODBCConfigMainClass"; // name of window class
91 wcx
.hIconSm
= NULL
; // small class icon
93 return ( !!RegisterClassEx( &wcx
) );
96 /// initializes the application instances
97 HWND
initInstance( HINSTANCE _hAppInstance
)
99 HWND hWindow
= CreateWindow(
100 L
"ODBCConfigMainClass", // name of window class
101 L
"ODBC Config Wrapper", // title-bar string
102 WS_OVERLAPPEDWINDOW
, // top-level window
103 CW_USEDEFAULT
, // default horizontal position
104 CW_USEDEFAULT
, // default vertical position
105 CW_USEDEFAULT
, // default width
106 CW_USEDEFAULT
, // default height
107 (HWND
) NULL
, // no owner window
108 (HMENU
) NULL
, // use class menu
109 _hAppInstance
, // handle to application instance
110 (LPVOID
) NULL
); // no window-creation data
112 // don't show the window, we only need it as parent handle for the
113 // SQLManageDataSources function
117 // main window function
119 extern "C" int APIENTRY
WinMain( HINSTANCE _hAppInstance
, HINSTANCE
, LPSTR
, int )
121 extern "C" int APIENTRY
_tWinMain( HINSTANCE _hAppInstance
, HINSTANCE
, LPTSTR
, int )
124 if ( !registerWindowClass( _hAppInstance
) )
127 HWND hAppWindow
= initInstance( _hAppInstance
);
128 if ( !IsWindow( hAppWindow
) )
129 return displayLastError();
131 HMODULE hModule
= LoadLibraryW( ODBC_UI_LIB_NAME
);
132 if ( hModule
== NULL
)
133 hModule
= LoadLibraryExW( ODBC_UI_LIB_NAME
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
134 if ( hModule
== NULL
)
135 return displayLastError();
137 FARPROC pManageDSProc
= GetProcAddress( hModule
, "SQLManageDataSources" );
138 if ( pManageDSProc
== NULL
)
139 return displayLastError();
141 TSQLManageDataSource pManageDS
= (TSQLManageDataSource
)pManageDSProc
;
142 if ( !( (*pManageDS
)( hAppWindow
) ) )
143 return displayLastError();
145 FreeLibrary( hModule
);
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */