什么是LoadString

核心提示LoadString是一个函数类型。外文名LoadString含义资源里加载字符串到CString对象参数应用程序实例句柄性质函数LoadString简介从 资源 里加载字符串资源到CString对象里。LoadString声明函数Load

最佳答案:

LoadString是一个函数类型。

详情介绍

LoadString是一个函数类型。

外文名
LoadString
含义
资源里加载字符串到CString对象
参数
应用程序实例句柄
性质
函数

LoadString简介

从 资源 里加载字符串资源到CString对象里。

LoadString声明

函数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是指明缓冲的大小。

返回值:如果调用成功,返回被加载到字符串长度(不包括0结尾字节),否则返回0

参数

hInstance :

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 :

Specifies the integer identifier of the string to be loaded.

lpBuffer :

Pointer to the buffer to receive the string.

nBufferMax :

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, 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) 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里的英文及例子就明白了。

 
友情链接
鄂ICP备19019357号-22