目前共有3篇帖子。 字体大小:较小 - 100% (默认)▼  内容转换:港澳繁體▼
 
点击 回复
494 2
【方法】獲取字符串資源中某個字符串的長度的方法
一派掌门 二十级
1楼 发表于:2016-6-20 21:00
#include <stdio.h>
#include <Windows.h>
#include "resource.h"

int main(void)
{
    HINSTANCE hInst = GetModuleHandle(NULL);
    LPWSTR p = NULL;
    LoadStringW(hInst, IDS_STRING101, (LPWSTR)&p, 0);
    printf("長度為: %d\n", wcslen(p));
}


一派掌门 二十级
2楼 发表于:2016-6-20 21:02
參考資料:
https://msdn.microsoft.com/en-us/library/ms647486(VS.85).aspx

nBufferMax [in]
Type: int
The size of the buffer, in characters. The string is truncated and null-terminated if it is longer than the number of characters specified. If this parameter is 0, then lpBuffer receives a read-only pointer to the resource itself.

最後一個參數設為0,可以獲得指向字符串資源的原始指針。
只針對LoadStringW函數有效,LoadStringA不行。因為字符串資源裏面只有Unicode版本的內容,沒有ANSI版本的內容。自然就不存在指向ANSI版本內容的指針。
 
一派掌门 二十级
3楼 发表于:2016-6-20 21:03
 

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:494 回复数:2
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2016-6-20 21:03
 
©2010-2025 Purasbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。