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 .
21 #include <sal/config.h>
23 #include <systools/win32/odbccp32.hxx>
25 // displays the error text for the last error (GetLastError), and returns this error value
26 static int displayLastError()
28 DWORD dwError
= GetLastError();
30 LPVOID lpMsgBuf
= nullptr;
32 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
,
35 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
36 reinterpret_cast<LPWSTR
>(&lpMsgBuf
),
41 // Display the string.
42 MessageBoxW( nullptr, static_cast<LPCWSTR
>(lpMsgBuf
), nullptr, MB_OK
| MB_ICONERROR
);
45 HeapFree( GetProcessHeap(), 0, lpMsgBuf
);
50 /** registers the window class for our application's main window
52 static bool registerWindowClass( HINSTANCE _hAppInstance
)
56 wcx
.cbSize
= sizeof(wcx
); // size of structure
57 wcx
.style
= CS_HREDRAW
| CS_VREDRAW
; // redraw if size changes
58 wcx
.lpfnWndProc
= DefWindowProcW
; // points to window procedure
59 wcx
.cbClsExtra
= 0; // no extra class memory
60 wcx
.cbWndExtra
= 0; // no extra window memory
61 wcx
.hInstance
= _hAppInstance
; // handle to instance
62 wcx
.hIcon
= nullptr; // predefined app. icon
63 wcx
.hCursor
= nullptr; // predefined arrow
64 wcx
.hbrBackground
= nullptr; // no background brush
65 wcx
.lpszMenuName
= nullptr; // name of menu resource
66 wcx
.lpszClassName
= L
"ODBCConfigMainClass"; // name of window class
67 wcx
.hIconSm
= nullptr; // small class icon
69 return ( !!RegisterClassExW( &wcx
) );
72 /// initializes the application instances
73 static HWND
initInstance( HINSTANCE _hAppInstance
)
75 HWND hWindow
= CreateWindowW(
76 L
"ODBCConfigMainClass", // name of window class
77 L
"ODBC Config Wrapper", // title-bar string
78 WS_OVERLAPPEDWINDOW
, // top-level window
79 CW_USEDEFAULT
, // default horizontal position
80 CW_USEDEFAULT
, // default vertical position
81 CW_USEDEFAULT
, // default width
82 CW_USEDEFAULT
, // default height
83 nullptr, // no owner window
84 nullptr, // use class menu
85 _hAppInstance
, // handle to application instance
86 nullptr); // no window-creation data
88 // don't show the window, we only need it as parent handle for the
89 // SQLManageDataSources function
93 // main window function
94 extern "C" int APIENTRY
wWinMain( HINSTANCE _hAppInstance
, HINSTANCE
, LPWSTR
, int )
96 if ( !registerWindowClass( _hAppInstance
) )
99 HWND hAppWindow
= initInstance( _hAppInstance
);
100 if ( !IsWindow( hAppWindow
) )
101 return displayLastError();
103 // Have a odbccp32 variable, to not call FreeLibrary before displayLastError
104 sal::systools::odbccp32 odbccp32
;
105 if (!odbccp32
.SQLManageDataSources(hAppWindow
))
106 return displayLastError();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */