jamescookres988 2016-05-04 12:24 采纳率: 100%
浏览 372

怎么取string *hs_Result 的地址

void CMDExecute(void temp)
{
DWORD bytesRead;
//unsigned char buffer[4097]={0};
unsigned char buffer[4097]={0};
int *args=(int *)temp;

//THe address..
string *hs_Command=(string *)args[0];
string *hs_Result=(string
)args[1];
//unsigned char *hs_Result =(unsigned char *)args[1];

STARTUPINFO hs_StartInfo;
PROCESS_INFORMATION hs_ProcessInformation;
SECURITY_ATTRIBUTES hs_SecurityAttributes;
HANDLE hs_PipeRead,hs_PipeWrite;

memset(&hs_StartInfo,0,sizeof(STARTUPINFO));
memset(&hs_ProcessInformation,0,sizeof(PROCESS_INFORMATION));
memset(&hs_SecurityAttributes,0,sizeof(SECURITY_ATTRIBUTES));

hs_SecurityAttributes.nLength=sizeof(hs_SecurityAttributes);
hs_SecurityAttributes.lpSecurityDescriptor=NULL;
hs_SecurityAttributes.bInheritHandle=TRUE;

if (!CreatePipe(&hs_PipeRead,&hs_PipeWrite,&hs_SecurityAttributes,0))
{
    return;
}
GetStartupInfo(&hs_StartInfo);
hs_StartInfo.cb=sizeof(STARTUPINFO);
hs_StartInfo.dwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
hs_StartInfo.wShowWindow=SW_HIDE;
hs_StartInfo.hStdError=hs_StartInfo.hStdOutput=hs_PipeWrite;
hs_StartInfo.hStdInput=hs_PipeWrite;

#ifdef UNICODE
int wclen= MultiByteToWideChar(CP_ACP,0,hs_Command->c_str(),strlen(hs_Command->c_str())+1,NULL,0);
LPTSTR lpcmd=new WCHAR[wclen];
MultiByteToWideChar(CP_ACP,0,hs_Command->c_str(),strlen(hs_Command->c_str())+1,lpcmd,wclen);
#else
string lpcmd;
/*
use & to return..
char * to re
*/

UTF8ToANSI((char *)hs_Command->c_str(),&lpcmd);

#endif
#ifdef UNICODE
if (CreateProcess(NULL,lpcmd,NULL,NULL,1,0,NULL,NULL,&hs_StartInfo,&hs_ProcessInformation))
#else

//if (CreateProcess(NULL,(char *)lpcmd.c_str(),NULL,NULL,1,0,NULL,NULL,&hs_StartInfo,&hs_ProcessInformation))
    if (CreateProcess(NULL,(char *)lpcmd.c_str(),NULL,NULL,1,0,NULL,NULL,&hs_StartInfo,&hs_ProcessInformation))

#endif
//if (CreateProcess(NULL,lpcmd,NULL,NULL,1,0,NULL,NULL,&hs_StartInfo,&hs_ProcessInformation))
{
// WaitForSingleObject(hs_ProcessInformation.hProcess,INFINITE);
CloseHandle(hs_ProcessInformation.hProcess);
CloseHandle(hs_ProcessInformation.hThread);
CloseHandle(hs_PipeWrite);
#ifdef UNICODE

delete [] lpcmd;
#endif
}
else
{
CloseHandle(hs_PipeRead);
CloseHandle(hs_PipeWrite);
#ifdef UNICODE
delete [] lpcmd;
#endif
return;
}

while (true)  
{
    if (!ReadFile(hs_PipeRead,buffer,4096,&bytesRead,NULL))
    {
        break;
    }
    *hs_Result+=buffer;
    //hs_Result = CatUnSignedChar(hs_Result,buffer);
    memset(buffer,0,4097);
}
CloseHandle(hs_PipeRead);

}

void Base64Encode(unsigned char const* bytes_to_encode, unsigned int in_len,string &ret)
{
const string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];

while (in_len--)
{
    char_array_3[i++] = *(bytes_to_encode++);
    if (i == 3) 
    {
        char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
        char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
        char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
        char_array_4[3] = char_array_3[2] & 0x3f;

        for(i = 0; (i <4) ; i++)
        {
            ret += base64_chars[char_array_4[i]];
        }
        i = 0;
    }
}

if (i)
{
    for(j = i; j < 3; j++)
    {
        char_array_3[j] = '\0';
    }

    char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
    char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
    char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
    char_array_4[3] = char_array_3[2] & 0x3f;

    for (j = 0; (j < i + 1); j++)
    {
        ret += base64_chars[char_array_4[j]];
    }

    while((i++ < 3))
    {
        ret += '=';
    }
}

}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算