小编Mir*_*ePV的帖子

使用C++中的CreateProcess()开始语音识别

我需要帮助我的简单程序,它试图创建一个运行语音识别的新进程.当我打开cmd并输入命令时C:\Windows\Speech\Common\sapisvr.exe -SpeechUX,语音识别将成功启动.即使在跑步时它也会启动system(C:\\Windows\\...),基本上只是模仿cmd.但是,使用如下CreateProcess()创建新进程时,该函数将失败.如果我将整个路径和参数放入第二个参数CreateProcess(NULL, TEXT("C:\\Windows...\\sapisvr.exe -SpeechUX"), ...),那么我得到一个运行时异常:访问冲突写入位置

#include <windows.h>
int main()
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    if (!CreateProcess(
    TEXT("C:\\Windows\\Speech\\Common\\sapisvr.exe"), //Module name
    TEXT(" -SpeechUX"),     //command line params
    NULL,       //Process attributes
    NULL,       //Thread attributes
    FALSE,      //Handle inheritance
    0,          //No creation flags
    NULL,       //Use parent's environment
    NULL,       //Use parent's starting directory
    &si,        //Pointer to STARTUPINFO structure
    &pi ))      //Pointer to PROCESS_INFORMATION structure
    {
        printf("error creating process\n");
        return 1;
    }

    WaitForSingleObject(pi.hProcess, INFINITE); …
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi accessibility process

3
推荐指数
1
解决办法
200
查看次数

标签 统计

accessibility ×1

c++ ×1

process ×1

winapi ×1

windows ×1