Article ID: 150764
Article Last Modified on 11/21/2006
/* Compile options needed: /MT
*/
#include <afx.h>
#include <stdio.h>
#include <conio.h>
#define IDS_HELLO 1
BOOL LoadStringResource(CString &cszString, UINT nID)
{
int nSize = 0;
int nLen = -1;
cszString.Empty();
//Keep looping until we have the whole string
while ((nLen != 0) && (nLen == nSize - 1))
{
//Grow buffer by 256 bytes
nSize += 256;
//Load String Resource
nLen = ::LoadString( GetModuleHandle(NULL), nID,
cszString.GetBuffer(nSize-1), nSize);
}
cszString.ReleaseBuffer();
return (BOOL) nLen;
}
void main(void)
{
AfxInitialize();
CString cszString;
// IDS_HELLO is a string resource attached to the console
application
if (LoadStringResource(cszString, IDS_HELLO))
printf("The string was loaded\n%s\n", (LPCTSTR) cszString);
else
printf("Error loading string");
getch();
}
/* Compile options needed: /MT
*/
#include <afx.h>
#include <afxwin.h>
#include <conio.h>
#define IDS_HELLO 1
CWinApp theApp;
void main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL,
::GetCommandLine(), 0))
{
printf("Couldn't initialize MFC!\n");
return;
}
CString cszString;
// IDS_HELLO is a string resource attached to the console
application
if (cszString.LoadString(IDS_HELLO))
printf("The string was loaded\n%s\n", (LPCTSTR) cszString);
else
printf("Error loading string");
getch();
}
Additional query words: 2.00 2.10 2.20 4.00 4.10
Keywords: kbprb KB150764