首页
社区
课程
招聘
d3d9 CreateDevice失败 求帮忙看看
发表于: 2023-4-6 07:58 7621

d3d9 CreateDevice失败 求帮忙看看

2023-4-6 07:58
7621

返回值;E_INVALIDARG 一个或多个参数无效。
好像是创建的那个透明窗口有问题,
我用hWnd=(hwnd)0x002318C2;给定句柄就成功。
或者是缓冲区的问题,搞不懂。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void initialize_direct3d9(hwnd hWnd)
{
//    hWnd=(hwnd)0x002318C2;
    //if (IsWindow(hWnd))printf("ok");
    //getchar();
    g_IDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);
    error(g_IDirect3D9, "Direct3DCreate9失败");
    ZeroMemory(&g_present, sizeof(g_present));
    g_present.Windowed = TRUE;
    g_present.SwapEffect = D3DSWAPEFFECT_DISCARD;
    g_present.BackBufferFormat = D3DFMT_UNKNOWN;//D3DFMT_UNKNOWN;
    g_present.EnableAutoDepthStencil = TRUE;
    g_present.AutoDepthStencilFormat = D3DFMT_D16;
    g_present.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    hresult result = g_IDirect3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_present, &g_IDirect3DDevice9);
    error(result == S_OK, "CreateDevice失败");//S_OK
    D3DXCreateLine(g_IDirect3DDevice9, &g_ID3DXLine);
    D3DXCreateFontA(g_IDirect3DDevice9, 20, 0, FW_DONTCARE, D3DX_DEFAULT, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Arial", &g_ID3DXFont);//Arial Vernada
}

下面是创建透明窗口的代码;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
hwnd create_transparent_window(hwnd game_hwnd)
{
 
    const char* window_name = "transparent";
 
    WNDCLASSEXA window_class;
    ZeroMemory(&window_class, sizeof(window_class));
    window_class.cbSize = sizeof(window_class);
    window_class.hCursor = LoadCursor(0, IDC_ARROW);
    window_class.hInstance = GetModuleHandle(NULL);
    window_class.lpfnWndProc = window_proc;
    window_class.lpszClassName = window_name;
    window_class.lpszMenuName = window_name;
    window_class.style = CS_VREDRAW | CS_HREDRAW;
    hresult result = RegisterClassExA(&window_class);
    error(result, "RegisterClassExA失败");
 
    int x, y, width, height;
    get_window_size(game_hwnd, x, y, width, height);
    hwnd transparent_hwnd = CreateWindowExA(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED,
        window_name, window_name, WS_POPUP, x, y, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
    error(transparent_hwnd, "CreateWindowExA失败");
 
    SetLayeredWindowAttributes(transparent_hwnd, 0, RGB(0, 0, 0), LWA_COLORKEY);
    UpdateWindow(transparent_hwnd);
    ShowWindow(transparent_hwnd, SW_SHOW);
 
    return transparent_hwnd;
}

附件是整个源代码;CSGO外部方框自瞄(基址是错的,只能玩玩机器人模式)


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2023-4-6 09:12 被seth-yu编辑 ,原因:
上传的附件:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 729
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
2
我只能说真的神奇,FindWindowA(nullptr,“Counter-Strike: Global Offensive”); 这样也能获得正确的句柄,但就是不行,所有要调用这个句柄的函数全部被搞成一坨shi,我真的真的服气了。
非得这样FindWindow("Valve001", nullptr);
2023-4-7 04:32
0
游客
登录 | 注册 方可回帖
返回
//