Life is Good.

Enhance Tech and English
随笔 - 65, 文章 - 20, 评论 - 21, 引用 - 0
数据加载中……

CreateProcess

    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    si.cb = sizeof(STARTUPINFO);
    si.lpReserved = NULL;
    si.lpTitle = NULL;
    si.lpDesktop = NULL;
    si.dwX = si.dwY = si.dwYSize = si.dwXSize = 0;
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;
    si.lpReserved2 = NULL;
    si.cbReserved2 = 0;

    BOOL ret = CreateProcess(strHostFileFullName, NULL, NULL, NULL, FALSE, 0, NULL, strPath, &si, &pi);
    if (!ret) {
        return false;
    }

    WaitForInputIdle(pi.hProcess, 30000);

    XXXCtxActivator activator;
    if(!activator.IsActivated())
        return false;

    CComPtr<IClassFactory> pFactory;
    HRESULT hr = CoGetClassObject(CLSID_XXX, CLSCTX_LOCAL_SERVER, NULL, __uuidof(pFactory), reinterpret_cast<void**>(&pFactory));
    if (FAILED(hr))
        return false;

    CComPtr<IXXX> s_spXXX;
    hr = pFactory->CreateInstance(NULL, __uuidof(*s_spXXX), reinterpret_cast<void**>(&s_spXXX));
    if(FAILED(hr))
        return false;
    
    // If created successfully, start the monitoring thread
    DWORD dwProcessId = GetCurrentProcessId();
    long nMonitoringPid = 0;

    hr = s_spXXX->StartProcessManagementThread(dwProcessId, &nMonitoringPid);
    if (FAILED(hr) || nMonitoringPid == 0)
        return false;

posted on 2012-04-12 16:59 Mike Song 阅读(254) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理