Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关闭时出现错误消息 < >用VisualC++ 2010 Express用编译以下代码 cl test.cpp_C++_Winapi_Shutdown_Explorer - Fatal编程技术网

关闭时出现错误消息 < >用VisualC++ 2010 Express用编译以下代码 cl test.cpp

关闭时出现错误消息 < >用VisualC++ 2010 Express用编译以下代码 cl test.cpp,c++,winapi,shutdown,explorer,C++,Winapi,Shutdown,Explorer,并运行.exe,然后关闭Windows 7,我会收到如下错误消息: The instruction 0x00f....9 in explorer.exe cannot access memory at 0x00000000. Memory cannot be read. 我在下面的代码中尝试了很多修改,但无法解决这个问题。 另一句话:我确信是这个程序导致了崩溃:我不运行它,没有关机错误消息,如果我运行它,就会有一条 坠机的原因可能是什么 也许您可以准确地描述您的程序正在尝试执行的操作。您的问

并运行.exe,然后关闭Windows 7,我会收到如下错误消息:

The instruction 0x00f....9 in explorer.exe cannot access memory at 0x00000000. Memory cannot be read.
我在下面的代码中尝试了很多修改,但无法解决这个问题。 另一句话:我确信是这个程序导致了崩溃:我不运行它,没有关机错误消息,如果我运行它,就会有一条

坠机的原因可能是什么


也许您可以准确地描述您的程序正在尝试执行的操作。您的问题是,未经另一进程的同意,您正在使您的窗口归另一进程中的某个窗口所有。别那样做,那有什么用?很明显,他正在反引用一个空指针。让我们找到它。我强烈怀疑hwndMain或hwndOwner为NULL,但OP在检查n tut tut!;-OP,为什么不在IDe中设置一个断点并检查这两个变量?@dan78这是我的小项目,完整的.cpp在这里:。我需要主窗口与桌面合并/混合,因此lines@MawgExplorer是出现错误的进程。这是因为asker的进程使其窗口由explorershell窗口拥有。
#pragma comment(lib, "user32.lib")
#define UNICODE
#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
    const wchar_t CLASS_NAME[]  = L"Sample Window Class";
    WNDCLASS wc = { };
    wc.lpfnWndProc   = WindowProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = CLASS_NAME;
    RegisterClass(&wc);

    HWND hwndMain = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED, wc.lpszClassName, 0, WS_POPUP | WS_VISIBLE | WS_SYSMENU, 0, 0, 300, 300, 0, 0, 0, 0);
    SetLayeredWindowAttributes(hwndMain, 0, 192, LWA_ALPHA);
    ShowWindow(hwndMain, nCmdShow);

    // without the next 2 lines, no crash at shutdown
    // but these 2 next lines are really important to make the main 
    // window part of the windows' desktop    
    // see comments on http://stackoverflow.com/a/27787003/1422096
    HWND hwndOwner = GetWindow(GetWindow(GetTopWindow(0), GW_HWNDLAST), GW_CHILD);   
    SetWindowLong(hwndMain, GWL_HWNDPARENT, (LONG) hwndOwner);      

    MSG msg = { };
    while (GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}