I get an illegal instruction exception when using GetOpenFileName(), I know its strange to post windows issues here, but the bug is only when using either DMD or DMC. VC++ 2008 produces a working executable in both 32bits and 64bits.

The program crashes on a LES instruction (opcode 0xC4) which is an invalid instruction in 64bit mode. Why it crashes there is beyond me, but its really annoying!

If anyone better at debugging than I am wants to give it a try, it would be great, at least to pinpoint what is leading to the crash.

I am using Windows 7 x64 build 7100.

Jeremie

#include <windows.h>

LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM w, LPARAM l) {
        switch(msg) {
        case WM_CREATE:
                {
                char fileBuf[MAX_PATH];
                fileBuf[0] = '\0';

                OPENFILENAMEA ofn;
                ZeroMemory(&ofn, sizeof(OPENFILENAMEA));
                ofn.lStructSize = sizeof(OPENFILENAMEA);
                ofn.hwndOwner = wnd;
                ofn.hInstance = GetModuleHandle(NULL);
                ofn.lpstrFilter = "*.*";
                ofn.lpstrFile = fileBuf;
                ofn.nMaxFile = MAX_PATH;

                GetOpenFileNameA(&ofn);
                }
                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProcA(wnd, msg, w, l);
        }

        return 0;
}

int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPSTR, int) {
        WNDCLASSA wc;
        ZeroMemory(&wc, sizeof(WNDCLASS));
        wc.hInstance = inst;
        wc.lpfnWndProc = &WndProc;
        wc.lpszClassName = "TheClass";
        RegisterClassA(&wc);

        HWND wnd = CreateWindowExA(WS_EX_OVERLAPPEDWINDOW, "TheClass", "Test",
                WS_OVERLAPPEDWINDOW, -1, -1, -1, -1, NULL, NULL, inst, NULL);

        ShowWindow(wnd, SW_SHOW);

        MSG msg;
        while(GetMessageA(&msg, NULL, 0, 0)) {
                TranslateMessage(&msg);
                DispatchMessageA(&msg);
        }

        return msg.wParam;
}

import core.sys.windows.windows;

int main() {
        HINSTANCE inst = GetModuleHandleA(null);

        WNDCLASSA wc;
        wc.hInstance = inst;
        wc.lpfnWndProc = &WndProc;
        wc.lpszClassName = "TheClass";
        RegisterClassA(&wc);

        HWND wnd = CreateWindowExA(0, "TheClass", "Test",
                WS_OVERLAPPEDWINDOW, -1, -1, -1, -1, null, null, inst, null);

        ShowWindow(wnd, SW_SHOW);

        MSG msg;
        while(GetMessageA(&msg, null, 0, 0)) {
                TranslateMessage(&msg);
                DispatchMessageA(&msg);
        }

        return msg.wParam;
}

extern(Windows)
LRESULT WndProc(HWND wnd, uint msg, WPARAM w, LPARAM l) {
        switch(msg) {
        case WM_CREATE:
                char[MAX_PATH] fileBuf = void;
                fileBuf[0] = '\0';

                OPENFILENAMEA ofn;
                ofn.lStructSize = OPENFILENAMEA.sizeof;
                ofn.hwndOwner = wnd;
                ofn.hInstance = GetModuleHandleA(null);
                ofn.lpstrFilter = "*.*";
                ofn.lpstrFile = fileBuf.ptr;
                ofn.nMaxFile = MAX_PATH;

                GetOpenFileNameA(&ofn);

                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProcA(wnd, msg, w, l);
        }

        return 0;
}

Reply via email to