CRshClient::Search  
 
BOOL Search(
  LPCTSTR lpszString  
);
BOOL Search(
  LPCTSTR lpszString,  
  LPVOID lpBuffer,  
  LPDWORD lpdwLength  
);
BOOL Search(
  LPCTSTR lpszString,  
  HGLOBAL *lpBuffer,  
  LPDWORD lpdwLength  
);
BOOL Search(
  LPCTSTR lpszString,  
  CString& strBuffer  
);

The Search method searches for a specific character sequence in the data stream and stops reading if the sequence is encountered.

Parameters

lpszString
A null-terminated string which specifies the sequence of characters to search for in the data stream. This parameter cannot be NULL or point to an empty string.
lpBuffer
A buffer which will contain the output from the server, or a pointer to a global memory handle which will reference the output when the method returns. An alternate form of this method accepts a CString object which will contain the output when the method returns. If the output from the server is not required, this parameter may be NULL.
lpdwLength
A pointer to an unsigned integer which should be initialized to the maximum number of bytes that can be copied to the buffer specified by the lpBuffer parameter. If the lpBuffer parameter points to a global memory handle, the length value should be initialized to zero. When the method returns, this value will be updated with the actual number of bytes of output stored in the buffer. If the lpBuffer parameter is NULL, this parameter should also be NULL.

Return Value

If the method succeeds and the character sequences was found in the data stream, the return value is non-zero. If the method fails or a timeout occurs before the sequence is found, the return value is zero. To get extended error information, call GetLastError.

Remarks

The Search method searches for a character sequence in the data stream and stops reading when it is found. This is useful when the client wants to automate responses to the server, such as executing a command and processing the output. The method collects the output from the server and stores it in the buffer specified by the lpBuffer parameter. When the method returns, the buffer will contain everything sent by the server up to and including the search string.

The lpBuffer parameter may be specified in one of two ways, depending on the needs of the application. The first method is to pre-allocate a buffer large enough to store the a fixed amount of output. In this case, the lpBuffer parameter will point to the buffer that was allocated, the value that the lpdwLength parameter points to should be initialized to the size of that buffer. If the server sends more output than can be stored in the buffer, the remaining output will be discarded.

The second method that can be used is have the lpBuffer parameter point to a global memory handle which will contain the output when the method returns. In this case, the value that the lpdwLength parameter points to must be initialized to zero. It is important to note that the memory handle returned by the method must be freed by the application, otherwise a memory leak will occur. This method is preferred if the client application does not have a general idea of how much output will be generated until the search string is found.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csrshv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also