Browse Source

Cleanup, print error if win32 CreateWindow fails

tags/v1.9.11
falkTX 6 years ago
parent
commit
faf4777b6e
5 changed files with 28 additions and 22 deletions
  1. +1
    -1
      source/backend/plugin/CarlaPluginVST2.cpp
  2. +2
    -0
      source/modules/water/common.hpp
  3. +1
    -1
      source/modules/water/files/File.cpp
  4. +1
    -1
      source/modules/water/water.cpp
  5. +23
    -19
      source/utils/CarlaPluginUI.cpp

+ 1
- 1
source/backend/plugin/CarlaPluginVST2.cpp View File

@@ -507,7 +507,7 @@ public:
value = (intptr_t)fUI.window->getDisplay(); value = (intptr_t)fUI.window->getDisplay();
#endif #endif


if (dispatcher(effEditOpen, 0, value, fUI.window->getPtr()) != 0 || 1)
if (dispatcher(effEditOpen, 0, value, fUI.window->getPtr()) != 0)
{ {
fUI.isOpen = true; fUI.isOpen = true;




+ 2
- 0
source/modules/water/common.hpp View File

@@ -52,6 +52,8 @@ int64 water_fileSetPosition (void* handle, int64 pos)
li.LowPart = SetFilePointer ((HANDLE) handle, (LONG) li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails) li.LowPart = SetFilePointer ((HANDLE) handle, (LONG) li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
return li.QuadPart; return li.QuadPart;
} }
HINSTANCE getCurrentModuleInstanceHandle() noexcept;
#else #else
static inline static inline
Result getResultForErrno() Result getResultForErrno()


+ 1
- 1
source/modules/water/files/File.cpp View File

@@ -1109,7 +1109,7 @@ File File::getSpecialLocation (const SpecialLocationType type)
} }
case currentExecutableFile: case currentExecutableFile:
return WindowsFileHelpers::getModuleFileName (water_getCurrentModuleInstanceHandle());
return WindowsFileHelpers::getModuleFileName (water::getCurrentModuleInstanceHandle());
case hostApplicationPath: case hostApplicationPath:
return WindowsFileHelpers::getModuleFileName (nullptr); return WindowsFileHelpers::getModuleFileName (nullptr);


+ 1
- 1
source/modules/water/water.cpp View File

@@ -25,7 +25,7 @@ namespace water
#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
static HINSTANCE currentModuleHandle = nullptr; static HINSTANCE currentModuleHandle = nullptr;
HINSTANCE water_getCurrentModuleInstanceHandle() noexcept
HINSTANCE getCurrentModuleInstanceHandle() noexcept
{ {
if (currentModuleHandle == nullptr) if (currentModuleHandle == nullptr)
currentModuleHandle = GetModuleHandleA (nullptr); currentModuleHandle = GetModuleHandleA (nullptr);


+ 23
- 19
source/utils/CarlaPluginUI.cpp View File

@@ -33,6 +33,7 @@


#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
# include <ctime> # include <ctime>
# include "water/common.hpp"
#endif #endif


#ifndef CARLA_PLUGIN_UI_CLASS_PREFIX #ifndef CARLA_PLUGIN_UI_CLASS_PREFIX
@@ -668,12 +669,12 @@ public:
{ {
// FIXME // FIXME
static int wc_count = 0; static int wc_count = 0;
char classNameBuf[256];
std::srand((std::time(NULL)));
_snprintf(classNameBuf, sizeof(classNameBuf), "CaWin_%d-%d", std::rand(), ++wc_count);
classNameBuf[sizeof(classNameBuf)-1] = '\0';
char classNameBuf[32];
std::srand((std::time(nullptr)));
std::snprintf(classNameBuf, 32, "CarlaWin-%d-%d", ++wc_count, std::rand());
classNameBuf[31] = '\0';


const HINSTANCE hInstance = GetModuleHandleA(nullptr);
const HINSTANCE hInstance = water::getCurrentModuleInstanceHandle();


carla_zeroStruct(fWindowClass); carla_zeroStruct(fWindowClass);
fWindowClass.style = CS_OWNDC; fWindowClass.style = CS_OWNDC;
@@ -699,10 +700,13 @@ public:
fWindow = CreateWindowEx(WS_EX_TOPMOST, fWindow = CreateWindowEx(WS_EX_TOPMOST,
classNameBuf, "Carla Plugin UI", winFlags, classNameBuf, "Carla Plugin UI", winFlags,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
nullptr, nullptr, hInstance, nullptr);


if (! fWindow) {
UnregisterClass(fWindowClass.lpszClassName, NULL);
if (fWindow == nullptr) {
const DWORD errorCode = ::GetLastError();
carla_stderr2("CreateWindowEx failed with error code 0x%x, class name was '%s'",
errorCode, fWindowClass.lpszClassName);
UnregisterClass(fWindowClass.lpszClassName, nullptr);
free((void*)fWindowClass.lpszClassName); free((void*)fWindowClass.lpszClassName);
return; return;
} }
@@ -727,13 +731,13 @@ public:
} }


// FIXME // FIXME
UnregisterClass(fWindowClass.lpszClassName, NULL);
UnregisterClass(fWindowClass.lpszClassName, nullptr);
free((void*)fWindowClass.lpszClassName); free((void*)fWindowClass.lpszClassName);
} }


void show() override void show() override
{ {
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);


if (fFirstShow) if (fFirstShow)
{ {
@@ -765,7 +769,7 @@ public:


void hide() override void hide() override
{ {
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);


ShowWindow(fWindow, SW_HIDE); ShowWindow(fWindow, SW_HIDE);
fIsVisible = false; fIsVisible = false;
@@ -774,7 +778,7 @@ public:


void idle() override void idle() override
{ {
if (fIsIdling || fWindow == 0)
if (fIsIdling || fWindow == nullptr)
return; return;


MSG msg; MSG msg;
@@ -818,7 +822,7 @@ public:


void focus() override void focus() override
{ {
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);


SetForegroundWindow(fWindow); SetForegroundWindow(fWindow);
SetActiveWindow(fWindow); SetActiveWindow(fWindow);
@@ -827,7 +831,7 @@ public:


void setSize(const uint width, const uint height, const bool forceUpdate) override void setSize(const uint width, const uint height, const bool forceUpdate) override
{ {
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);


const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fIsResizable ? WS_SIZEBOX : 0x0); const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fIsResizable ? WS_SIZEBOX : 0x0);
RECT wr = { 0, 0, static_cast<long>(width), static_cast<long>(height) }; RECT wr = { 0, 0, static_cast<long>(width), static_cast<long>(height) };
@@ -842,14 +846,14 @@ public:


void setTitle(const char* const title) override void setTitle(const char* const title) override
{ {
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);


SetWindowTextA(fWindow, title); SetWindowTextA(fWindow, title);
} }


void setTransientWinId(const uintptr_t winId) override void setTransientWinId(const uintptr_t winId) override
{ {
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);


fParentWindow = (HWND)winId; fParentWindow = (HWND)winId;
SetWindowLongPtr(fWindow, GWLP_HWNDPARENT, (LONG_PTR)winId); SetWindowLongPtr(fWindow, GWLP_HWNDPARENT, (LONG_PTR)winId);
@@ -873,9 +877,9 @@ public:
} }


private: private:
HWND fWindow;
HWND fChildWindow;
HWND fParentWindow;
HWND fWindow;
HWND fChildWindow;
HWND fParentWindow;
WNDCLASS fWindowClass; WNDCLASS fWindowClass;


bool fIsVisible; bool fIsVisible;


Loading…
Cancel
Save