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.
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.