gpt4 book ai didi

c++ - Windows Metro 模式 (C++) : Waiting on semaphore (WaitForSingleObjectEx): failed with Access Denied [partially solved]

转载 作者:行者123 更新时间:2023-11-30 02:03:39 30 4
gpt4 key购买 nike

也许这对你来说是个愚蠢的问题..但它对我不起作用! (WinRT 的新手......也可能是 Windows!)只是试图创建信号量并试图获取它......没什么特别的。但它因 WAIT_FAILED 失败:5(拒绝访问)

void MainPage::simple_Sema_test1()
{

HANDLE p_sema;
DWORD ret, err;
p_sema = CreateSemaphoreEx(NULL, 1, MAX_LIMIT, L"sema1", 0, SEMAPHORE_MODIFY_STATE);
if(p_sema == NULL)
print_on_textbox("CreateSemaphoreEx Failed!\n");
ret = WaitForSingleObjectEx(p_sema, 1000, TRUE);
switch(ret){
case WAIT_ABANDONED:
print_on_textbox("WAIT_ABANDONED\n");
case WAIT_IO_COMPLETION:
print_on_textbox("WAIT_IO_COMPLETION\n");
case WAIT_OBJECT_0:
print_on_textbox("WAIT_OBJECT_0\n");
case WAIT_TIMEOUT:
print_on_textbox("WAIT_TIMEOUT\n");
case WAIT_FAILED:
print_on_textbox("WAIT_FAILED: " + (GetLastError()).ToString());
}

Edit <<< (Partially solved) Create Semaphore with SEMAPHORE_ALL_ACCESS

*sema = CreateSemaphoreEx(NULL, initial, MAX_LIMIT, L"sema1", 0, SEMAPHORE_ALL_ACCESS);

如果有人知道为什么它不能使用修改权限,请解释一下!

最佳答案

要等待一个同步对象,你必须有 SYNCHRONIZE access rights :

SYNCHRONIZE: The right to use the object for synchronization. This enables a thread to wait until the object is in the signaled state.

SEMAPHORE_ALL_ACCESS 值包括 SYNCHRONIZE 标志。

关于c++ - Windows Metro 模式 (C++) : Waiting on semaphore (WaitForSingleObjectEx): failed with Access Denied [partially solved],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11570336/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com