2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2007-07-24 11:11:10 +00:00
|
|
|
|
|
|
|
|
2017-09-18 17:34:28 +03:00
|
|
|
#if !defined WIN32_LEAN_AND_MEAN
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
2007-07-24 11:11:10 +00:00
|
|
|
#include <windows.h>
|
2019-04-05 13:15:42 +03:00
|
|
|
#include <odbcinst.h>
|
2007-07-24 11:11:10 +00:00
|
|
|
|
|
|
|
// displays the error text for the last error (GetLastError), and returns this error value
|
2018-09-24 15:41:53 +02:00
|
|
|
static int displayLastError()
|
2007-07-24 11:11:10 +00:00
|
|
|
{
|
|
|
|
DWORD dwError = GetLastError();
|
|
|
|
|
2017-11-02 13:22:41 +03:00
|
|
|
LPVOID lpMsgBuf = nullptr;
|
2017-09-20 20:20:44 +03:00
|
|
|
FormatMessageW(
|
2017-11-02 13:22:41 +03:00
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
2016-10-14 16:57:29 +02:00
|
|
|
nullptr,
|
2007-07-24 11:11:10 +00:00
|
|
|
dwError,
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
2017-09-20 20:20:44 +03:00
|
|
|
reinterpret_cast<LPWSTR>(&lpMsgBuf),
|
2007-07-24 11:11:10 +00:00
|
|
|
0,
|
2016-10-14 16:57:29 +02:00
|
|
|
nullptr
|
2007-07-24 11:11:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Display the string.
|
2017-09-20 20:20:44 +03:00
|
|
|
MessageBoxW( nullptr, static_cast<LPCWSTR>(lpMsgBuf), nullptr, MB_OK | MB_ICONERROR );
|
2007-07-24 11:11:10 +00:00
|
|
|
|
|
|
|
// Free the buffer.
|
2017-11-02 13:22:41 +03:00
|
|
|
HeapFree( GetProcessHeap(), 0, lpMsgBuf );
|
2007-07-24 11:11:10 +00:00
|
|
|
|
|
|
|
return dwError;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** registers the window class for our application's main window
|
|
|
|
*/
|
2019-11-19 15:15:50 +01:00
|
|
|
static bool registerWindowClass( HINSTANCE _hAppInstance )
|
2007-07-24 11:11:10 +00:00
|
|
|
{
|
2017-09-20 20:20:44 +03:00
|
|
|
WNDCLASSEXW wcx;
|
2007-07-24 11:11:10 +00:00
|
|
|
|
|
|
|
wcx.cbSize = sizeof(wcx); // size of structure
|
|
|
|
wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes
|
2017-09-20 20:20:44 +03:00
|
|
|
wcx.lpfnWndProc = DefWindowProcW; // points to window procedure
|
2007-07-24 11:11:10 +00:00
|
|
|
wcx.cbClsExtra = 0; // no extra class memory
|
|
|
|
wcx.cbWndExtra = 0; // no extra window memory
|
|
|
|
wcx.hInstance = _hAppInstance; // handle to instance
|
2016-10-14 16:57:29 +02:00
|
|
|
wcx.hIcon = nullptr; // predefined app. icon
|
|
|
|
wcx.hCursor = nullptr; // predefined arrow
|
|
|
|
wcx.hbrBackground = nullptr; // no background brush
|
|
|
|
wcx.lpszMenuName = nullptr; // name of menu resource
|
2007-07-24 11:11:10 +00:00
|
|
|
wcx.lpszClassName = L"ODBCConfigMainClass"; // name of window class
|
2016-10-14 16:57:29 +02:00
|
|
|
wcx.hIconSm = nullptr; // small class icon
|
2007-07-24 11:11:10 +00:00
|
|
|
|
2017-09-20 20:20:44 +03:00
|
|
|
return ( !!RegisterClassExW( &wcx ) );
|
2007-07-24 11:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// initializes the application instances
|
2018-09-24 15:41:53 +02:00
|
|
|
static HWND initInstance( HINSTANCE _hAppInstance )
|
2007-07-24 11:11:10 +00:00
|
|
|
{
|
2017-09-20 20:20:44 +03:00
|
|
|
HWND hWindow = CreateWindowW(
|
2007-07-24 11:11:10 +00:00
|
|
|
L"ODBCConfigMainClass", // name of window class
|
|
|
|
L"ODBC Config Wrapper", // title-bar string
|
|
|
|
WS_OVERLAPPEDWINDOW, // top-level window
|
|
|
|
CW_USEDEFAULT, // default horizontal position
|
|
|
|
CW_USEDEFAULT, // default vertical position
|
|
|
|
CW_USEDEFAULT, // default width
|
|
|
|
CW_USEDEFAULT, // default height
|
2016-10-14 16:57:29 +02:00
|
|
|
nullptr, // no owner window
|
|
|
|
nullptr, // use class menu
|
2007-07-24 11:11:10 +00:00
|
|
|
_hAppInstance, // handle to application instance
|
2016-10-14 16:57:29 +02:00
|
|
|
nullptr); // no window-creation data
|
2007-07-24 11:11:10 +00:00
|
|
|
|
|
|
|
// don't show the window, we only need it as parent handle for the
|
|
|
|
// SQLManageDataSources function
|
|
|
|
return hWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// main window function
|
2017-09-20 20:20:44 +03:00
|
|
|
extern "C" int APIENTRY wWinMain( HINSTANCE _hAppInstance, HINSTANCE, LPWSTR, int )
|
2007-07-24 11:11:10 +00:00
|
|
|
{
|
|
|
|
if ( !registerWindowClass( _hAppInstance ) )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
HWND hAppWindow = initInstance( _hAppInstance );
|
|
|
|
if ( !IsWindow( hAppWindow ) )
|
|
|
|
return displayLastError();
|
|
|
|
|
2019-04-05 13:15:42 +03:00
|
|
|
if (!SQLManageDataSources(hAppWindow))
|
2007-07-24 11:11:10 +00:00
|
|
|
return displayLastError();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|