当前位置: 首页>>代码示例>>C++>>正文


C++ CharArray::appendString方法代码示例

本文整理汇总了C++中CharArray::appendString方法的典型用法代码示例。如果您正苦于以下问题:C++ CharArray::appendString方法的具体用法?C++ CharArray::appendString怎么用?C++ CharArray::appendString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CharArray的用法示例。


在下文中一共展示了CharArray::appendString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createProcess

    static HANDLE createProcess(const String& win32ProgramFileName,
                                const String& commandLine,
                                EnvMap::Ptr   environmentMap = Null,
                                HANDLE*       inputHandle    = NULL,
                                HANDLE*       outputHandle   = NULL,
                                HANDLE*       stderrHandle   = NULL)
    {
        STARTUPINFO         su;
        memset(&su, 0, sizeof(su));
        su.cb = sizeof(su);

        bool useHandles = (    inputHandle != NULL 
                           && outputHandle != NULL 
                           && stderrHandle != NULL);

        HANDLE stdinRead,  stdinWrite;
        HANDLE stdoutRead, stdoutWrite;
        HANDLE stderrRead, stderrWrite;
        
        if (useHandles)
        {
            createPipeForCreatedProcess(&stdinRead,  &stdinWrite);
            createPipeForCreatedProcess(&stdoutRead, &stdoutWrite);
            createPipeForCreatedProcess(&stderrRead, &stderrWrite);
            
            setInheritFlag(stdinRead);
            setInheritFlag(stdoutWrite);
            setInheritFlag(stderrWrite);

            *inputHandle  = stdinWrite;
            *outputHandle = stdoutRead;
            *stderrHandle = stderrRead;

            su.hStdInput  = stdinRead;
            su.hStdOutput = stdoutWrite;
            su.hStdError  = stderrWrite;
            su.dwFlags |= STARTF_USESTDHANDLES;
        }

        PROCESS_INFORMATION pi;
        memset(&pi, 0, sizeof(pi));
        
        CharArray commandLineBuffer;
                  commandLineBuffer.appendString(commandLine);
                  commandLineBuffer.append('\0');
        
        {
            char*      environmentStringsPtr = NULL;
            CharArray  environmentStrings;
            if (environmentMap.isValid()) {
                environmentStrings.appendString(buildEnvironmentStringsFromMap(environmentMap));
                environmentStringsPtr = environmentStrings.getPtr();
            }
            const bool inheritHandles = useHandles;
            
            bool wasOK = CreateProcess(win32ProgramFileName.toCString(),   // lpApplicationName
                                       commandLineBuffer.getPtr(),    // lpCommandLine
                                       0,         // lpProcessAttributes,
                                       0,         // lpThreadAttributes,
                                       inheritHandles,      // bInheritHandles,
                                       DETACHED_PROCESS|HIGH_PRIORITY_CLASS, // dwCreationFlags,
                                       environmentStringsPtr,      // lpEnvironment,
                                       NULL,      // lpCurrentDirectory,
                                       &su,         // in:  lpStartupInfo,
                                       &pi);        // out: lpProcessInformation
    
            if (!wasOK)
            {
                throw SystemException(String() << "Error in call to Win32 CreateProcess for '" << win32ProgramFileName << "'");
            }
        }
        if (useHandles) {
            CloseHandle(stdinRead);
            CloseHandle(stdoutWrite);
            CloseHandle(stderrWrite);
        }
        CloseHandle(pi.hThread);        
        
        return pi.hProcess;
    }
开发者ID:osch,项目名称:luced,代码行数:80,代码来源:Win32Util.hpp


注:本文中的CharArray::appendString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。