目前共有3篇帖子。 內容轉換:不轉換▼
 
點擊 回復
199 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)
 

本帖信息

點擊數:199 回複數:2
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2016-6-20 21:03
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。