各位高手,我是用SHELLEXECUTE调用NET SEND,但是,不知道发送是否成功,需要获得它的返回字符串,请赐教!!谢谢。

解决方案 »

  1.   

    管道
      Platform SDK: Interprocess Communications 
    CreatePipeThe CreatePipe function creates an anonymous pipe, and returns handles to the read and write ends of the pipe.
    BOOL CreatePipe(
      PHANDLE hReadPipe,
      PHANDLE hWritePipe,
      LPSECURITY_ATTRIBUTES lpPipeAttributes,
      DWORD nSize
    );Parameters
    hReadPipe 
    [out] Pointer to a variable that receives the read handle for the pipe. 
    hWritePipe 
    [out] Pointer to a variable that receives the write handle for the pipe. 
    lpPipeAttributes 
    [in] Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpPipeAttributes is NULL, the handle cannot be inherited. 
    The lpSecurityDescriptor member of the structure specifies a security descriptor for the new pipe. If lpPipeAttributes is NULL, the pipe gets a default security descriptor. The ACLs in the default security descriptor for a pipe come from the primary or impersonation token of the creator.nSize 
    [in] Size of the buffer for the pipe, in bytes. The size is only a suggestion; the system uses the value to calculate an appropriate buffering mechanism. If this parameter is zero, the system uses the default buffer size. 
    Return Values
    If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.Res
    CreatePipe creates the pipe, assigning the specified pipe size to the storage buffer. CreatePipe also creates handles that the process uses to read from and write to the buffer in subsequent calls to the ReadFile and WriteFile functions.To read from the pipe, a process uses the read handle in a call to the ReadFile function. ReadFile returns when one of the following is true: a write operation completes on the write end of the pipe, the number of bytes requested has been read, or an error occurs.When a process uses WriteFile to write to an anonymous pipe, the write operation is not completed until all bytes are written. If the pipe buffer is full before all bytes are written, WriteFile does not return until another process or thread uses ReadFile to make more buffer space available.Anonymous pipes are implemented using a named pipe with a unique name. Therefore, you can often pass a handle to an anonymous pipe to a function that requires a handle to a named pipe.Example Code 
    For an example, see Creating a Child Process with Redirected Input and Output.Requirements
    Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, and Windows 95.
    Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server.
    Header: Declared in Winbase.h; include Windows.h.
    Library: Use Kernel32.lib.
    See Also
    Pipes Overview, Pipe Functions, ReadFile, SECURITY_ATTRIBUTES, WriteFilePlatform SDK Release: February 2003  What did you think of this topic?
      Order a Platform SDK CD  Requirements
    Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, and Windows 95.
    Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server.
    Header: Declared in Winbase.h; include Windows.h.
    Library: Use Kernel32.lib.See Also
    Pipes Overview, Pipe Functions, ReadFile, SECURITY_ATTRIBUTES, WriteFile
      

  2.   

    bright2k(大辉) 能否给个例子?
      

  3.   

    codeproject上有一个封装好的匿名管道的类,你可以参考一下
    http://www.codeproject.com/internet/canonpipe.asp?
      

  4.   

    #include <stdio.h> 
    #include <windows.h> 
     
    #define BUFSIZE 4096 
     
    HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup, 
       hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup, 
       hInputFile, hSaveStdin, hSaveStdout; 
     
    BOOL CreateChildProcess(VOID); 
    VOID WriteToPipe(VOID); 
    VOID ReadFromPipe(VOID); 
    VOID ErrorExit(LPTSTR); 
    VOID ErrMsg(LPTSTR, BOOL); 
     
    DWORD main(int argc, char *argv[]) 

       SECURITY_ATTRIBUTES saAttr; 
       BOOL fSuccess; 
     
    // Set the bInheritHandle flag so pipe handles are inherited. 
     
       saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
       saAttr.bInheritHandle = TRUE; 
       saAttr.lpSecurityDescriptor = NULL; 
     
       // The steps for redirecting child process's STDOUT: 
       //     1. Save current STDOUT, to be restored later. 
       //     2. Create anonymous pipe to be STDOUT for child process. 
       //     3. Set STDOUT of the parent process to be write handle to 
       //        the pipe, so it is inherited by the child process. 
       //     4. Create a noninheritable duplicate of the read handle and
       //        close the inheritable read handle. 
     
    // Save the handle to the current STDOUT. 
     
       hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
     
    // Create a pipe for the child process's STDOUT. 
     
       if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) 
          ErrorExit("Stdout pipe creation failed\n"); 
     
    // Set a write handle to the pipe to be STDOUT. 
     
       if (! SetStdHandle(STD_OUTPUT_HANDLE, hChildStdoutWr)) 
          ErrorExit("Redirecting STDOUT failed"); 
     
    // Create noninheritable read handle and close the inheritable read 
    // handle.     fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
            GetCurrentProcess(), &hChildStdoutRdDup , 0,
            FALSE,
            DUPLICATE_SAME_ACCESS);
        if( !fSuccess )
            ErrorExit("DuplicateHandle failed");
        CloseHandle(hChildStdoutRd);   // The steps for redirecting child process's STDIN: 
       //     1.  Save current STDIN, to be restored later. 
       //     2.  Create anonymous pipe to be STDIN for child process. 
       //     3.  Set STDIN of the parent to be the read handle to the 
       //         pipe, so it is inherited by the child process. 
       //     4.  Create a noninheritable duplicate of the write handle, 
       //         and close the inheritable write handle. 
     
    // Save the handle to the current STDIN. 
     
       hSaveStdin = GetStdHandle(STD_INPUT_HANDLE); 
     
    // Create a pipe for the child process's STDIN. 
     
       if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) 
          ErrorExit("Stdin pipe creation failed\n"); 
     
    // Set a read handle to the pipe to be STDIN. 
     
       if (! SetStdHandle(STD_INPUT_HANDLE, hChildStdinRd)) 
          ErrorExit("Redirecting Stdin failed"); 
     
    // Duplicate the write handle to the pipe so it is not inherited. 
     
       fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, 
          GetCurrentProcess(), &hChildStdinWrDup, 0, 
          FALSE,                  // not inherited 
          DUPLICATE_SAME_ACCESS); 
       if (! fSuccess) 
          ErrorExit("DuplicateHandle failed"); 
     
       CloseHandle(hChildStdinWr); 
     
    // Now create the child process. 
     
       if (! CreateChildProcess()) 
          ErrorExit("Create process failed"); 
     
    // After process creation, restore the saved STDIN and STDOUT. 
     
       if (! SetStdHandle(STD_INPUT_HANDLE, hSaveStdin)) 
          ErrorExit("Re-redirecting Stdin failed\n"); 
     
       if (! SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout)) 
          ErrorExit("Re-redirecting Stdout failed\n"); 
     
    // Get a handle to the parent's input file. 
     
       if (argc > 1) 
          hInputFile = CreateFile(argv[1], GENERIC_READ, 0, NULL, 
             OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); 
       else 
          hInputFile = hSaveStdin; 
     
       if (hInputFile == INVALID_HANDLE_VALUE) 
          ErrorExit("no input file\n"); 
     
    // Write to pipe that is the standard input for a child process. 
     
       WriteToPipe(); 
     
    // Read from pipe that is the standard output for child process. 
     
       ReadFromPipe(); 
     
       return 0; 

     
    BOOL CreateChildProcess() 

       PROCESS_INFORMATION piProcInfo; 
       STARTUPINFO siStartInfo; 
     
    // Set up members of the PROCESS_INFORMATION structure. 
     
       ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
     
    // Set up members of the STARTUPINFO structure. 
     
       ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
       siStartInfo.cb = sizeof(STARTUPINFO); 
     
    // Create the child process. 
     
       return CreateProcess(NULL, 
          "child",       // command line 
          NULL,          // process security attributes 
          NULL,          // primary thread security attributes 
          TRUE,          // handles are inherited 
          0,             // creation flags 
          NULL,          // use parent's environment 
          NULL,          // use parent's current directory 
          &siStartInfo,  // STARTUPINFO pointer 
          &piProcInfo);  // receives PROCESS_INFORMATION 
    }
     
    VOID WriteToPipe(VOID) 

       DWORD dwRead, dwWritten; 
       CHAR chBuf[BUFSIZE]; 
     
    // Read from a file and write its contents to a pipe. 
     
       for (;;) 
       { 
          if (! ReadFile(hInputFile, chBuf, BUFSIZE, &dwRead, NULL) || 
             dwRead == 0) break; 
          if (! WriteFile(hChildStdinWrDup, chBuf, dwRead, 
             &dwWritten, NULL)) break; 
       } 
     
    // Close the pipe handle so the child process stops reading. 
     
       if (! CloseHandle(hChildStdinWrDup)) 
          ErrorExit("Close pipe failed\n"); 

     
    VOID ReadFromPipe(VOID) 

       DWORD dwRead, dwWritten; 
       CHAR chBuf[BUFSIZE]; 
       HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); // Close the write end of the pipe before reading from the 
    // read end of the pipe. 
     
       if (!CloseHandle(hChildStdoutWr)) 
          ErrorExit("Closing handle failed"); 
     
    // Read output from the child process, and write to parent's STDOUT. 
     
       for (;;) 
       { 
          if( !ReadFile( hChildStdoutRdDup, chBuf, BUFSIZE, &dwRead, 
             NULL) || dwRead == 0) break; 
          if (! WriteFile(hSaveStdout, chBuf, dwRead, &dwWritten, NULL)) 
             break; 
       } 

     
    VOID ErrorExit (LPTSTR lpszMessage) 

       fprintf(stderr, "%s\n", lpszMessage); 
       ExitProcess(0); 

     
    // The code for the child process. #include <windows.h> 
    #define BUFSIZE 4096 
     
    VOID main(VOID) 

       CHAR chBuf[BUFSIZE]; 
       DWORD dwRead, dwWritten; 
       HANDLE hStdin, hStdout; 
       BOOL fSuccess; 
     
       hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
       hStdin = GetStdHandle(STD_INPUT_HANDLE); 
       if ((hStdout == INVALID_HANDLE_VALUE) || 
          (hStdin == INVALID_HANDLE_VALUE)) 
          ExitProcess(1); 
     
       for (;;) 
       { 
       // Read from standard input. 
          fSuccess = ReadFile(hStdin, chBuf, BUFSIZE, &dwRead, NULL); 
          if (! fSuccess || dwRead == 0) 
             break; 
     
       // Write to standard output. 
          fSuccess = WriteFile(hStdout, chBuf, dwRead, &dwWritten, NULL); 
          if (! fSuccess) 
             break; 
       } 
    }
      

  5.   

    http://www.0mai.com/bbs 上有这问题的解答 我把我做的例子放到 http://www.0mai.com/bbs/down_default.asp 上了你可以看一看我OICQ:9199333