Сегодня случайно открыл для себя что wine это не только запускалка .exe файлов на linux, но также и портированное win32 api.

Наверное, это и так все знают, хотя часто вижу сообщения в духе: «никогда не портируют на linux, так как прибито гвоздями к Win32».

Те кто так думают, знайте, Win32 кросплатформенный api, и нужно всего лишь перекомпилировать.

Нашёл в интернете hello world на Win32 api:

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASSW wc = {0};
wc.lpszClassName = L"Static Control";
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);


RegisterClassW(&wc);
CreateWindowW(wc.lpszClassName, L"Native App",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 330, 270, 0, 0, hInstance, 0);

while (GetMessage(&msg, NULL, 0, 0)) {

TranslateMessage(&msg);
DispatchMessage(&msg);
}

return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {

static wchar_t *lyrics = L"Hello World!";

switch(msg) {

case WM_CREATE:

CreateWindowW(L"Static", lyrics,
WS_CHILD | WS_VISIBLE | SS_LEFT,
20, 20, 300, 230,
hwnd, (HMENU) 1, NULL, NULL);
break;

case WM_DESTROY:

PostQuitMessage(0);
break;
}

return DefWindowProcW(hwnd, msg, wParam, lParam);
}

собрал

winegcc main.c -o hello

создалось два файла:

  • hello.exe
  • hello.exe.so

hello.exe это на самом деле баш скрипт:

#!/bin/sh

appname="hello.exe.so"
# determine the application directory
appdir=''
case "$0" in
*/*)
# $0 contains a path, use it
appdir=`dirname "$0"`
;;
*)
# no directory in $0, search in PATH
saved_ifs=$IFS
IFS=:
for d in $PATH
do
IFS=$saved_ifs
if [ -x "$d/$appname" ]; then appdir="$d"; break; fi
done
;;
esac

# figure out the full app path
if [ -n "$appdir" ]; then
apppath="$appdir/$appname"
WINEDLLPATH="$appdir:$WINEDLLPATH"
export WINEDLLPATH
else
apppath="$appname"
fi

# determine the WINELOADER
if [ ! -x "$WINELOADER" ]; then WINELOADER="wine"; fi

# and try to start the app
exec "$WINELOADER" "$apppath" "$@"

выглядит как-то так:
https://i.imgur.com/u6pzVeJ.png








 , , , ,






URL записи