LINUX.ORG.RU

Winemake: ошибки


0

0

Решил собрать свою Win32-прогу под Wine.

Вот текст:

***** main.cpp *****
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <cstdio>
#include "resource.h"

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

HINSTANCE hInstance;
char szClassname[256];

enum Class {
    A,
    B,
    C
} cls;

WPARAM GlobalWparamForSendMsg;
UINT GlobalMsgForSendMsg;

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
    SendMessage(hWnd, GlobalMsgForSendMsg, GlobalWparamForSendMsg, lParam);

    return TRUE;
}

void SendMessageToAllWindows(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    GlobalWparamForSendMsg = wParam;
    GlobalMsgForSendMsg = uMsg;

    EnumWindows(EnumWindowsProc, lParam);
}

int WINAPI WinMain(
    HINSTANCE hInst,
    HINSTANCE hPrevInst,
    PSTR szCmdLine,
    int nShowCmd)
{
    if (strcmp(szCmdLine, "A") == 0) {
        cls = A;
    } else if (strcmp(szCmdLine, "B") == 0) {
        cls = B;
    } else if (strcmp(szCmdLine, "C") == 0) {
        cls = C;
    } else {
        MessageBox(NULL, "Invalid class specified in command-line! Must be either A, B or C.", "Error!", MB_ICONERROR);
        return 1;
    }

    char szWindowName[128];
    sprintf(szWindowName, "Class %s", szCmdLine);
    strcpy(szClassname, szCmdLine);

    hInstance = hInst;

    WNDCLASSEX wc;

    wc.cbSize = sizeof(wc);
    wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInst;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW);
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
    wc.lpszClassName = szCmdLine;
    wc.hIconSm = NULL;

    ATOM Status = RegisterClassEx(&wc);

    HWND hWnd;

    hWnd = CreateWindow(
        szCmdLine,
        szWindowName,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        400,
        300,
        NULL,
        NULL,
        hInst,
        NULL
    );

    ShowWindow(hWnd, nShowCmd);
    UpdateWindow(hWnd);

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return static_cast<int>(msg.wParam);
}

/* continued... */
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HMENU hMenu;
    static bool bAActive, bBActive, bCActive;

    switch (uMsg)
    {
        case WM_CREATE:
        {
            // Get menu handle.

            hMenu = GetMenu(hWnd);

            bAActive = (bool)FindWindow("A", NULL);
            bBActive = (bool)FindWindow("B", NULL);
            bCActive = (bool)FindWindow("C", NULL);

            // Set "kill" and "run" menu itemz to enabled/grayed.

            EnableMenuItem(hMenu, ID_KILL_PROGRAMA, MF_GRAYED);
            EnableMenuItem(hMenu, ID_KILL_PROGRAMB, MF_GRAYED);
            EnableMenuItem(hMenu, ID_KILL_PROGRAMC, MF_GRAYED);

            EnableMenuItem(hMenu, ID_RUN_PROGRAMA, MF_ENABLED);
            EnableMenuItem(hMenu, ID_RUN_PROGRAMB, MF_ENABLED);
            EnableMenuItem(hMenu, ID_RUN_PROGRAMC, MF_ENABLED);

            if (bAActive) {
                if (cls != A) {
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMA, MF_ENABLED);
                }
                EnableMenuItem(hMenu, ID_RUN_PROGRAMA, MF_GRAYED);
            }

            if (bBActive) {
                if (cls != B) {
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMB, MF_ENABLED);
                }
                EnableMenuItem(hMenu, ID_RUN_PROGRAMB, MF_GRAYED);
            }

            if (bCActive) {
                if (cls != C) {
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMC, MF_ENABLED);
                }
                EnableMenuItem(hMenu, ID_RUN_PROGRAMC, MF_GRAYED);
            }

            // Send message to all appz that we have started.

            switch (cls) {
                case A:
                    SendMessageToAllWindows(WM_USER, 666, 66601);
                    break;
                case B:
                    SendMessageToAllWindows(WM_USER, 666, 66602);
                    break;
                case C:
                    SendMessageToAllWindows(WM_USER, 666, 66603);
                    break;
            }

            break;
        }

        case WM_USER:
        {
            if (wParam != 666) {
                break;
            }

            switch (lParam)
            {
                // Someone started.

                case 66601:
                    if (cls == A) {
                        break;
                    }
                    bAActive = true;
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMA, MF_ENABLED);
                    EnableMenuItem(hMenu, ID_RUN_PROGRAMA, MF_GRAYED);
                    break;

                case 66602:
                    if (cls == B) {
                        break;
                    }
                    bBActive = true;
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMB, MF_ENABLED);
                    EnableMenuItem(hMenu, ID_RUN_PROGRAMB, MF_GRAYED);
                    break;

                case 66603:
                    if (cls == C) {
                        break;
                    }
                    bCActive = true;
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMC, MF_ENABLED);
                    EnableMenuItem(hMenu, ID_RUN_PROGRAMC, MF_GRAYED);
                    break;

                // Someone goin' to die.

                case 77701:
                    bAActive = false;
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMA, MF_GRAYED);
                    EnableMenuItem(hMenu, ID_RUN_PROGRAMA, MF_ENABLED);
                    break;

                case 77702:
                    bBActive = false;
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMB, MF_GRAYED);
                    EnableMenuItem(hMenu, ID_RUN_PROGRAMB, MF_ENABLED);
                    break;

                case 77703:
                    bCActive = false;
                    EnableMenuItem(hMenu, ID_KILL_PROGRAMC, MF_GRAYED);
                    EnableMenuItem(hMenu, ID_RUN_PROGRAMC, MF_ENABLED);
                    break;

                // We (maybe) goin' to die.

                case 99901:
                case 99902:
                case 99903:
                {
                    if (cls == A && lParam == 99901) {
                        SendMessage(hWnd, WM_DESTROY, wParam, lParam);
                        break;
                    }

                    if (cls == B && lParam == 99902) {
                        SendMessage(hWnd, WM_DESTROY, wParam, lParam);
                        break;
                    }

                    if (cls == C && lParam == 99903) {
                        SendMessage(hWnd, WM_DESTROY, wParam, lParam);
                        break;
                    }

                    break;
                }
            }

            break;
        }

Ivanz
() автор топика

/* continued... */

        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case ID_PROGRAM_QUIT:
                {
                    SendMessage(hWnd, WM_DESTROY, wParam, lParam);
                    return 0;
                }

                case ID_RUN_PROGRAMA:
                {
                    STARTUPINFO Si;
                    PROCESS_INFORMATION Pi;
                    char CmdLine[] = "ShProga A";

                    ZeroMemory(&Si, sizeof(Si));
                    Si.cb = sizeof(Si);

                    ZeroMemory(&Pi, sizeof(Pi));

                    // Start the  process.

                    CreateProcess(
                        NULL,               // No module name (use command line).
                        CmdLine,            // Command line.
                        NULL,               // Process handle not inheritable.
                        NULL,               // Thread handle not inheritable.
                        FALSE,              // Set handle inheritance to FALSE.
                        NULL,               // Creation flags.
                        NULL,               // Use parent's environment block.
                        NULL,               // Use parent's starting directory.
                        &Si,                // Pointer to STARTUPINFO structure.
                        &Pi                 // Pointer to PROCESS_INFORMATION structure.
                    );

                    break;
                }

                case ID_RUN_PROGRAMB:
                {
                    STARTUPINFO Si;
                    PROCESS_INFORMATION Pi;
                    char CmdLine[] = "ShProga B";

                    ZeroMemory(&Si, sizeof(Si));
                    Si.cb = sizeof(Si);

                    ZeroMemory(&Pi, sizeof(Pi));

                    // Start the  process.

                    CreateProcess(
                        NULL,               // No module name (use command line).
                        CmdLine,            // Command line.
                        NULL,               // Process handle not inheritable.
                        NULL,               // Thread handle not inheritable.
                        FALSE,              // Set handle inheritance to FALSE.
                        NULL,               // Creation flags.
                        NULL,               // Use parent's environment block.
                        NULL,               // Use parent's starting directory.
                        &Si,                // Pointer to STARTUPINFO structure.
                        &Pi                 // Pointer to PROCESS_INFORMATION structure.
                    );

                    break;
                }

                case ID_RUN_PROGRAMC:
                {
                    STARTUPINFO Si;
                    PROCESS_INFORMATION Pi;
                    char CmdLine[] = "ShProga C";

                    ZeroMemory(&Si, sizeof(Si));
                    Si.cb = sizeof(Si);

                    ZeroMemory(&Pi, sizeof(Pi));

                    // Start the  process.

                    CreateProcess(
                        NULL,               // No module name (use command line).
                        CmdLine,            // Command line.
                        NULL,               // Process handle not inheritable.
                        NULL,               // Thread handle not inheritable.
                        FALSE,              // Set handle inheritance to FALSE.
                        NULL,               // Creation flags.
                        NULL,               // Use parent's environment block.
                        NULL,               // Use parent's starting directory.
                        &Si,                // Pointer to STARTUPINFO structure.
                        &Pi                 // Pointer to PROCESS_INFORMATION structure.
                    );

                    break;
                }

                case ID_KILL_PROGRAMA:
                {
                    SendMessageToAllWindows(WM_USER, 666, 99901);
                    break;
                }

                case ID_KILL_PROGRAMB:
                {
                    SendMessageToAllWindows(WM_USER, 666, 99902);
                    break;
                }

                case ID_KILL_PROGRAMC:
                {
                    SendMessageToAllWindows(WM_USER, 666, 99903);
                    break;
                }

                case ID_HELP_ABOUT:
                {
                    MessageBox(hWnd, "ShProga 0.1  Copyright ╘ ******* ****** 2006.", "About", MB_OK);
                    break;
                }
            }

            break;
        }

        case WM_DESTROY:
        {
            LPARAM lparam;

            if (cls == A) {
                lparam = 77701;
            } else if (cls == B) {
                lparam = 77702;
            } else if (cls == C) {
                lparam = 77703;
            }

            // Send message to all appz that we r goin' to quit.

            SendMessageToAllWindows(WM_USER, 666, lparam);

            PostQuitMessage(0);
            break;
        }
    }

    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

Ivanz
() автор топика

При сборке вот такая лабуда:

/Src/Win/ShProga ivanz@tux 0 5549
$ make
wineg++ -c  -mno-cygwin -I.   -o main.o main.cpp
In file included from main.cpp:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:167: error: `::snprintf' has not been declared
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:168: error: `::vfscanf' has not been declared
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:169: error: `::vscanf' has not been declared
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:171: error: `::vsscanf' has not been declared
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:177: error: `__gnu_cxx::snprintf' has not been declared
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:178: error: `__gnu_cxx::vfscanf' has not been declared
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:179: error: `__gnu_cxx::vscanf' has not been declared
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/include/g++-v3/cstdio:181: error: `__gnu_cxx::vsscanf' has not been declared
main.cpp:6: warning: `__stdcall__' attribute ignored
main.cpp:21: warning: `__stdcall__' attribute ignored
main.cpp:40: warning: `__stdcall__' attribute ignored
main.cpp:106: warning: `__stdcall__' attribute ignored
winegcc: g++ failed.
make: *** [main.o] Error 2

Ivanz
() автор топика

Если вверху заменить #include <cstdio> на #include <stdio.h>, то выдаёт следующее:

/Src/Win/ShProga ivanz@tux 0 5551
$ make        
wineg++ -c  -mno-cygwin -I.   -o main.o main.cpp
main.cpp:6: warning: `__stdcall__' attribute ignored
main.cpp:21: warning: `__stdcall__' attribute ignored
main.cpp:40: warning: `__stdcall__' attribute ignored
main.cpp:106: warning: `__stdcall__' attribute ignored
wrc   -I.   -foShProga.res ShProga.rc
wineg++ -mwindows -mno-cygwin -o shproga.exe.so  main.o ShProga.res     -lodbc32 -lole32 -loleaut32 -lwinspool -luuid
ld: Relocatable linking with relocations from format elf64-x86-64 (main.o) to format elf32-i386 (shproga.EZYxmN.o) is not supported
winebuild: ld -m elf_i386 -r failed with status 256
winegcc: winebuild failed.
make: *** [shproga.exe.so] Error 2

Ivanz
() автор топика
Ответ на: комментарий от e

Прога, конечно, ужоснах - но коллективный разум откорпораченных программеров способен исторгнуть еще и покруче ;)

Так что, дополнение - перепиши прогу на нормальном С и в соответствии с стандартами ;)

e
()
Ответ на: комментарий от e

Хммм.. Не понял :) Чем не устраивает стиль? Программа, если вы не заметили, на _C++_, а не на C. И выбор языка не обсуждается :) И где вы увидили несоответствие стандартам? :)

// // Ivanz //

anonymous
()
Ответ на: комментарий от anonymous

Ниасилил фразу, поясните - где там плюсы у с, если нет ни единого класса или там шаблона? ;)

А "стандарт" - это POSIX и X11, на линуксе сия прога и не обязана собираться - но может запуститься ;)

e
()
2 ноября 2006 г.
Ответ на: комментарий от Ivanz

>Чиво делать? :)

wineg++ -c -I. -o main.o main.cpp

gcc -lstdc++ main.o -o main.exe

AcidumIrae ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.