CLlmClient::SendMessage Method  
 
BOOL SendMessage(
  LPCTSTR lpszPrompt,  
  LPTSTR lpszResponse,  
  LPDWORD lpdwLength,  
  LPDWORD lpdwMessageId  
);

The SendMessage method sends a prompt to the model and returns the response as a string.

Parameters

lpszPrompt
A pointer to a null-terminated string which specifies the message prompt which should be sent to the model. This parameter cannot be NULL or a zero-length string. If the string consists only of whitespace characters, or contains invalid Unicode or non-text data, this method will fail.
lpszResponse
A pointer to a string buffer which will contain the model's response to the prompt. The response will always be null terminated and if the buffer is not large enough to store the complete response, the response will be truncated. The lpdwLength parameter must be initialized with the maximum number of characters which can be copied into the buffer or the method will fail.
lpdwLength
A pointer to an unsigned integer which should be initialized to the size of the lpszResponse string buffer. When the method returns, this value will be updated with the actual number of characters copied into the buffer, not including the terminating null character. This parameter cannot be NULL and its initial value must be greater than zero.
lpdwMessageId
A pointer to an unsigned integer which will contain the ID for the message when the method returns. This parameter may be NULL if the application does not require the message ID.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The SendMessage method provides a simplified interface for sending a single text prompt to the model and receiving the response as a string. This method is intended for applications that do not require structured input or detailed control over message formatting.

This method will not return until the request has completed, an error has occurred, or the operation has timed out. Applications that call this method from a user interface thread should provide visual feedback while waiting for the response, or perform the request on a background thread to maintain responsiveness.

Applications that accept user input should apply appropriate validation, filtering, or normalization before sending requests to the service provider. The ValidateText method verifies that the prompt contains valid message text and the NormalizeText method can be used to normalize text formatting. These functions do not perform any semantic analysis of the prompt and do not provide protection against malicious or intentionally misleading input.

This method does not validate or restrict the content of the input message. It is the responsibility of the application to ensure that user-provided input is appropriate for its intended use. This includes considering scenarios where input may attempt to override instructions, inject unintended prompts, or otherwise influence the behavior of the model.

The response is written to the buffer specified by lpszResponse. If the buffer is not large enough to contain the complete response, the text will be truncated. The lpdwLength parameter will always contain the number of characters actually copied to the buffer.

Line breaks in the response text are normalized before being stored in the client history. Line feed and carriage return characters are converted to the standard Windows CRLF end-of-line sequence, ensuring consistent formatting across different providers and applications. This also helps ensure compatibility with Windows common controls and other user interface components.

Some models are capable of performing additional internal reasoning before generating a response. The amount of reasoning performed and whether it is exposed by the provider is model-specific. The library returns the final response intended for the user and does not currently expose model reasoning or intermediate processing steps. This behavior ensures consistent results across providers, regardless of how individual models implement or expose reasoning capabilities.

If the lpdwMessageId parameter is specified, it will receive a unique identifier for the message within the current client session. Message identifiers are assigned sequentially, but applications should treat them as opaque values. They are only guaranteed to be unique within a single session and should not be compared across different client sessions.

This method automatically adds the message to the conversation history for the session. Subsequent calls will include previous messages as context, subject to any configured history or token limits. To clear the conversation context, call ClearHistory or ResetSession.

Applications that require more advanced features, such as structured messages, role-based input, or access to detailed response metadata, should use the SendMessageEx method instead.

Example

#include "cstools12.h"
#include <stdio.h>

int _tmain(void)
{
    CLlmClient llmClient;
    
    // Establish a connection to OpenAI using the default endpoint
    // and a lightweight model
    BOOL bConnected = llmClient.Connect(
        LLM_PROVIDER_OPENAI,
        LLM_OPTION_DEFAULT,
        LLM_TIMEOUT,
        NULL,                   // Use default base URL
        _T("gpt-6-luna"),       // Model name
        _T("%OPENAI_API_KEY%")  // Provider API key
    );

    if (!bConnected)
    {
        dwError = llmClient.GetLastError();
        _tprintf(_T("Unable to connect, error %lu\n"), dwError);
        return 1;
    }

    TCHAR szResponse[4096] = {0};
    DWORD dwResponseLength = _countof(szResponse); // number of TCHARs
    DWORD dwMessageId = 0;

    // Send a simple message to the model
    if (llmClient.SendMessage(
                    _T("What is the capital city of Denmark?"),
                    szResponse,
                    &dwResponseLength,
                    &dwMessageId))
    {
        _tprintf(_T("Response:\n%s\n"), szResponse);
    }
    else
    {
        dwError = llmClient.GetLastError();
        _tprintf(_T("Request failed, error %lu\n"), dwError);
    }

    // Close the connection explicitly
    llmClient.Disconnect();
    return 0;
}

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: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also