简体   繁体   English

为什么ShellExecuteEx不返回进程句柄?

[英]Why is ShellExecuteEx not returning the process handle?

I am trying to open an image with the following function: 我正在尝试使用以下功能打开图像:

HANDLE openFile(char *path){ // path = "C:\Users\Foo Bar\Code\Test\test.jpg"
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

    SHELLEXECUTEINFOW info;
    memset(&info, 0, sizeof(info));
    info.cbSize = sizeof(info);
    info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC ;
    info.hwnd = NULL;
    info.lpVerb = L"open";
    info.lpFile = utf8_toWchar(path);
    info.lpParameters = NULL;
    info.lpDirectory = NULL;
    info.nShow = SW_SHOW;
    info.hInstApp = NULL;

    if (!ShellExecuteExW(&info)){
        System_printLastErrorString(); //never gets here
    }
    //free((void*)info.lpFile);
    CoUninitialize();

    return info.hProcess; //this is always NULL
}

The problem is that info.hProcess is always NULL despite the fact that the default image editing program is not open and is opened a bit later. 问题是,尽管默认图像编辑程序未打开,但稍后打开,但info.hProcess始终为NULL

How do I fix this? 我该如何解决?

Side Note: I dont know if this is relevant, but the calling program is a Qt Application. 旁注:我不知道这是否相关,但是调用程序是Qt应用程序。

I ended up calling CreateProcess myself to the result of AssocQueryString . 我最终自己给AssocQueryString的结果调用CreateProcess This gave me the handle I needed. 这给了我所需的手柄。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 ShellExecuteEx 启动终止进程 - Kill process started with ShellExecuteEx ShellExecuteEx和GetExitCodeProcess - 处理无效或分段错误 - ShellExecuteEx & GetExitCodeProcess - Handle Invalid or Segmentation Fault 等待ShellExecuteEx(在Windows进程上设置访问权限) - Waiting for ShellExecuteEx (Setting access rights on Windows process) 使用参数创建进程(CreateProcess或ShellExecuteEx)的小问题 - Small issue with creating a process ( CreateProcess or ShellExecuteEx) with parameters 如何将以ShellExecuteEx作为子进程运行的进程在父退出后关闭? - How to run a process with ShellExecuteEx as as a child that closes after parent exit? 如何找出用ShellExecuteEx创建的进程是否拥有一个窗口? - How to find out if process created with ShellExecuteEx owns a window? 为什么将ReadProcessMemory()与当前进程的句柄一起使用? - Why use ReadProcessMemory() with handle to current process? 为什么 if (fork() == 0) { getpid() } 和 popen() 进程返回相同的进程 ID? - Why is if (fork() == 0) { getpid() } and a popen() process returning the same process id? ShellExecuteEx和getexitcodeprocess - ShellExecuteEx and getexitcodeprocess 为什么由“ CreateEvent”创建的HANDLE在另一个进程中无效? - Why HANDLE created by 'CreateEvent' isn't valid in another process?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM