LoadString

LoadString是一個函式類型。

基本介紹

  • 外文名:LoadString
  • 含義:資源里載入字元串到CString對象
  • 參數:應用程式實例句柄
  • 性質:函式
簡介,聲明,

簡介

從 資源 里載入字元串資源到CString對象里。

聲明

函式LoadString聲明如下:
WINUSERAPI int WINAPI LoadStringA(
__in_opt HINSTANCE hInstance,
__in UINT uID,
__out_ecount(cchBufferMax) LPSTR lpBuffer,
__in int nBufferMax);
參數1: hInstance是應用程式實例句柄。
參數2: uID是資源中的字元串編號。
參數3: lpBuffer是接收從資源里拷貝字元串出來的緩衝區。
參數4: nBufferMax是指明緩衝的大小。
參數
hInstance [in]:
Handle to an instance of the module whose executable file contains the string resource. To get the handle to the application itself, use GetModuleHandle(NULL).
uID [in] :
Specifies the integer identifier of the string to be loaded.
lpBuffer [out]:
Pointer to the buffer to receive the string.
nBufferMax [in]:
Specifies the size of the buffer, in TCHARs. This refers to bytes for ANSI versions of the function or WCHARs for Unicode versions. The string is truncated and NULL terminated if it is longer than the number of characters specified.
返回值
If the function succeeds, the return value is the number of TCHARs copied into the buffer, not including the terminating NULL character, or zero if the string resource does not exist. To get extended error information, call GetLastError.
說明
Security Alert
Using this function incorrectly can compromise the security of your application. Incorrect use includes specifying the wrong size in the nBufferMax parameter. For example, if lpBuffer points to a buffer szBuffer which is declared as TCHAR szBuffer[100], then sizeof(szBuffer) gives the size of the buffer in bytes, which could lead to a buffer overflow for the Unicode version of the function. Buffer overflow situations are the cause of many security problems in applications. In this case, using sizeof(szBuffer)/sizeof(TCHAR) or sizeof(szBuffer)/sizeof(szBuffer[0]) would give the proper size of the buffer.
Windows 95/98/Me: LoadStringW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
系統要求
Minimum DLL Version: user32.dll
Header: Declared in Winuser.h, include Windows.h
Import library: User32.lib
Minimum operating systems: Windows 95, Windows NT 3.1
Unicode: Implemented as ANSI and Unicode versions.
看完上面的資料可能大家都蒙了,不知道具體是在做什麼,
其實這個成員函式是在調用String Table裡面定義的信息,
也就是說,把String Table中Caption裡面的字元串讀出來到CString對象里。
String Table中的ID號及其對應的字元串都是可以自己定義的。
String Table在ResourceView視窗中,也就是ClassView右邊那個視窗。
雙擊之後就能看到,在最下面的選項中追加新的ID信息。
如果還是理解不清楚的話,請自己嘗試多讀msdn里的英文及例子就明白了。

相關詞條

熱門詞條

聯絡我們