CNntpClient::GetArticle Method  
 
INT GetArticle(
  LONG nArticleId,  
  LPBYTE lpBuffer,  
  LPDWORD lpdwLength  
);
INT GetArticle(
  LONG nArticleId,  
  HGLOBAL* lpBuffer,  
  LPDWORD lpdwLength  
);
INT GetArticle(
  LONG nArticleId,  
  CString& strBuffer  
);
INT GetArticle(
  LPCTSTR lpszMessageId,  
  LPBYTE lpBuffer,  
  LPDWORD lpdwLength  
);
INT GetArticle(
  LPCTSTR lpszMessageId,  
  HGLOBAL* lpBuffer,  
  LPDWORD lpdwLength  
);
INT GetArticle(
  LPCTSTR lpszMessageId,  
  CString& strBuffer  
);

The GetArticle method retrieves the specified article and copies the contents to a local buffer.

Parameters

nArticleId
An integer value which specifies the number of the article to retrieve from the server. This value must be greater than zero. Overloaded versions of this method also support article IDs that are 64-bit integers.
lpszMessageId
A pointer to a string which specifies the message ID of the article to retrieve from the server. This parameter cannot be NULL or specify an empty string.
lpBuffer
A pointer to a byte buffer which will contain the data transferred from the server, or a pointer to a global memory handle which will reference the data when the method returns.
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 length of the file that was downloaded.

Return Value

If the method succeeds, the return value is the server result code. If the method fails, the return value is NNTP_ERROR. To get extended error information, call GetLastError.

Remarks

The GetArticle method is used to retrieve an article from the server and copy it into a local buffer. The method may be used 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 contents of the article. 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.

The second method that can be used is have the lpBuffer parameter point to a global memory handle which will contain the article data 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. See the example code below.

This method will cause the current thread to block until the complete article has been retrieved, a timeout occurs or the operation is canceled. During the transfer, the NNTP_EVENT_PROGRESS event will be periodically fired, enabling the application to update any user interface controls. Event notification must be enabled, either by calling EnableEvents, or by registering a callback function using the RegisterEvent method.

To determine the current status of a transfer while it is in progress, use the GetTransferStatus method.

Example

HGLOBAL hgblBuffer = (HGLOBAL)NULL;
LPBYTE lpBuffer = (LPBYTE)NULL;
DWORD cbBuffer = 0;

// Return the article into block of global memory allocated by
// the GlobalAlloc function; the handle to this memory will be
// returned in the hgblBuffer parameter
nResult = pClient->GetArticle(nArticleId, &hgblBuffer, &cbBuffer);

if (nResult != NNTP_ERROR)
{
    // Lock the global memory handle, returning a pointer to the
    // article text
    lpBuffer = (LPBYTE)GlobalLock(hgblBuffer);
    
    // After the data has been used, the handle must be unlocked
    // and freed, otherwise a memory leak will occur
    GlobalUnlock(hgblBuffer);
    GlobalFree(hgblBuffer);
}

Requirements

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

See Also

CreateArticle, EnableEvents, GetArticleHeaders, GetTransferStatus, RegisterEvent