Skip to content

Commit

Permalink
* Fix compilation with mingw / ansi
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Feb 1, 2025
1 parent 99d5058 commit 2ce408c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
1 change: 0 additions & 1 deletion deps/iprogramsterminate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ extern "C" void Terminate(const char*, ...);

#define terminateAsio() terminateApplication("asio")
#define terminateWebsocketpp() terminateApplication("websocketpp")
#define terminateIprogsThreads() terminateApplication("iprogsthreads")

#endif
35 changes: 22 additions & 13 deletions src/windows/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ static Image DecodeWebp(const uint8_t* pData, size_t size)

#else

static Image DecodeWebp(const uint8_t* pData, size_t size, int* width, int* height)
static Image DecodeWebp(const uint8_t* pData, size_t size)
{
return {};
return Image();
}

#endif
Expand Down Expand Up @@ -121,9 +121,9 @@ static Image DecodeWithStbImage(const uint8_t* pData, size_t size)

#else

static Image DecodeWithStbImage(const uint8_t* pData, size_t size, int* width, int* height)
static Image DecodeWithStbImage(const uint8_t* pData, size_t size)
{
return {};
return Image();
}

#endif
Expand Down Expand Up @@ -175,6 +175,16 @@ HImage* ImageLoader::ConvertToBitmap(const uint8_t* pData, size_t size, bool& ou

for (size_t i = 0; i < loadedImageCount; i++)
{
// NOTE: Have to define these extra early, because gcc is picky about initialization
// even though I don't goddamn use these after `DoneHBM'. But these are used later
HGDIOBJ old;
int x, oldMode;
BITMAPINFO bmi2;
BITMAPINFOHEADER& hdr2 = bmi2.bmiHeader;
uint32_t* alphaPixels;
int width, height;
bool needDeletePixels;

auto& frm = img.Frames[i];

// pre-multiply alpha
Expand Down Expand Up @@ -226,8 +236,9 @@ HImage* ImageLoader::ConvertToBitmap(const uint8_t* pData, size_t size, bool& ou
goto DoneHBM;
}

bool needDeletePixels = false;
int width = img.Width, height = img.Height;
needDeletePixels = false;
width = img.Width;
height = img.Height;

// Check if we need to stretch the bitmap.
if (newWidth == width && newHeight == height)
Expand All @@ -254,22 +265,21 @@ HImage* ImageLoader::ConvertToBitmap(const uint8_t* pData, size_t size, bool& ou

// Yeah, need to stretch the bitmap. Because of that, we need to perform two stretch
// operations and combine the bits together.
uint32_t* alphaPixels = new uint32_t[pixelCount];
alphaPixels = new uint32_t[pixelCount];
for (size_t i = 0; i < pixelCount; i++) {
uint32_t alpha = (pixels[i]) >> 24;
alphaPixels[i] = (255 << 24) | (alpha << 16) | (alpha << 8) | alpha;
}

// Create the alpha channel bitmap.
hbm = CreateCompatibleBitmap(wndHdc, newWidth, newHeight);
HGDIOBJ old = SelectObject(hdc, hbm);
int oldMode = SetStretchBltMode(hdc, HALFTONE);
int x = StretchDIBits(hdc, 0, 0, newWidth, newHeight, 0, 0, width, height, alphaPixels, &bmi, DIB_RGB_COLORS, SRCCOPY);
old = SelectObject(hdc, hbm);
oldMode = SetStretchBltMode(hdc, HALFTONE);
x = StretchDIBits(hdc, 0, 0, newWidth, newHeight, 0, 0, width, height, alphaPixels, &bmi, DIB_RGB_COLORS, SRCCOPY);
SetStretchBltMode(hdc, oldMode);
SelectObject(hdc, old);
delete[] alphaPixels;

BITMAPINFO bmi2;

size_t newPixelCount;
uint32_t *pvAlphaBits, *pvColorBits;

Expand All @@ -280,7 +290,6 @@ HImage* ImageLoader::ConvertToBitmap(const uint8_t* pData, size_t size, bool& ou
}

ZeroMemory(&bmi2, sizeof bmi2);
BITMAPINFOHEADER& hdr2 = bmi2.bmiHeader;
hdr2.biSizeImage = 0;
hdr2.biWidth = newWidth;
hdr2.biHeight = -newHeight;
Expand Down
14 changes: 10 additions & 4 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ bool g_bFromStartup = false;

void CheckIfItsStartup(const LPSTR pCmdLine)
{
g_bFromStartup = StrStrA(pCmdLine, g_StartupArg);
g_bFromStartup = strstr(pCmdLine, g_StartupArg);
}

void AddOrRemoveAppFromStartup()
Expand All @@ -665,7 +665,7 @@ void AddOrRemoveAppFromStartup()
const std::string sPath = "\"" + MakeStringFromTString(tPath) + "\" " + std::string(g_StartupArg);
const LPTSTR finalPath = ConvertCppStringToTString(sPath);

RegSetValueEx(hkey, value, 0, REG_SZ, (BYTE *)finalPath, (wcslen(finalPath) + 1) * sizeof(TCHAR));
RegSetValueEx(hkey, value, 0, REG_SZ, (BYTE *)finalPath, (_tcslen(finalPath) + 1) * sizeof(TCHAR));
}
else
{
Expand Down Expand Up @@ -1033,6 +1033,12 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
try {
GetWebsocketClient()->Init();
}
catch (websocketpp::exception ex) {
Terminate("hey, websocketpp excepted: %s | %d | %s", ex.what(), ex.code(), ex.m_msg.c_str());
}
catch (std::exception ex) {
Terminate("hey, websocketpp excepted (generic std::exception): %s", ex.what());
}
catch (...) {
MessageBox(hWnd, TmGetTString(IDS_CANNOT_INIT_WS), TmGetTString(IDS_PROGRAM_NAME), MB_ICONERROR | MB_OK);
g_bQuittingEarly = true;
Expand Down Expand Up @@ -1639,7 +1645,7 @@ HTTPClient* GetHTTPClient()

InstanceMutex g_instanceMutex;

static bool ForceSingleInstance(LPCWSTR pClassName)
static bool ForceSingleInstance(LPCTSTR pClassName)
{
HRESULT hResult = g_instanceMutex.Init();

Expand All @@ -1664,7 +1670,7 @@ static bool ForceSingleInstance(LPCWSTR pClassName)

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nShowCmd)
{
LPCWSTR pClassName = TEXT("DiscordMessengerClass");
LPCTSTR pClassName = TEXT("DiscordMessengerClass");

g_hInstance = hInstance;
ri::InitReimplementation();
Expand Down
5 changes: 5 additions & 0 deletions src/windows/MissingDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#define SS_REALSIZECONTROL 0x00000040
#endif // SS_REALSIZECONTROL

// NOTE: This was added in Windows Vista, so it won't work on XP and earlier. but who cares
#ifndef SMTO_ERRORONEXIT
#define SMTO_ERRORONEXIT 0x20
#endif

#ifdef MINGW_SPECIFIC_HACKS

#if(WINVER >= 0x0500)
Expand Down

0 comments on commit 2ce408c

Please sign in to comment.