- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我在命名空间中使用 LoadString
WinAPI 宏时,我遇到了问题。我的功能:
namespace Bushman {
// Get the string from the resource's string table of the module.
// I use the same name like WinAPI macros but with own signature.
PTSTR LoadString(HMODULE h, DWORD id) {
h = NULL == h ? ::GetModuleHandle(NULL) : h;
PTSTR ptr = NULL;
// it returns really length instead of concatenated
// string length, therefore I can use it for malloc.
int i = ::LoadString(h, id, (PTSTR)&ptr, 0);
if (0 == i) {
return NULL;
}
PTSTR string = (PTSTR)malloc(i * (sizeof(TCHAR) + 1));
::LoadString(h, id, string, i + 1);
return string; // NOTE: don't forget free resource in the outer code.
}
}
我得到编译错误:
'LoadStringW': is not a member of 'Bushman'
'LoadStringW': is not a member of 'Bushman'
'LoadStringW': is not a member of 'Bushman'
我该如何解决?
UPD
我认为问题是宏有这样的定义
#ifdef UNICODE
#define LoadString LoadStringW
#else
#define LoadString LoadStringA
#endif // !UNICODE
而不是像这样:
#ifdef UNICODE
#define LoadString ::LoadStringW
#else
#define LoadString ::LoadStringA
#endif // !UNICODE
UPD 2
我找到了问题的原因。问题出在我的代码的其他地方。我在我的代码中使用了这样的声明:
namespace Bushman {} // namespace declaration
PTSTR Bushman::LoadString(HMODULE h, DWORD id); // function declaration
但这是错误的。如果我将其重写为:
namespace Bushman {
PTSTR LoadString(HMODULE h, DWORD id);
}
最佳答案
您有几个选择:
LoadString
宏的 Windows 头文件,或者#undef
取消定义宏。这个问题确实没有很好的解决方案。一旦你开始使用宏,你就失去了轻松隔离和控制它们影响的能力。预处理器不关心您的 namespace 。
关于你对问题的更新,你并没有真正解决问题。从 UPD2 中的代码开始,预处理器将 LoadString
转换为 LoadStringW
。您只是没有意识到这一点,因为它在编译过程中透明地发生。但是,如果您尝试从另一个未定义 LoadString
宏的翻译单元使用您的类,您会发现该函数名为 LoadStringW
。
关于c++ - 如何在我的命名空间中使用 LoadString 宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33277639/
标题够明确,我想让用户选择他想要打开的文本文件。 我不知道是否已经在处理中实现了资源管理器或输入字段。 任何帮助都会很棒。 最佳答案 使用 selectInput .从处理引用: Opens a pl
我是 C++ 的新手,需要一些帮助。我创建了一个包含字符串的纯资源 dll,我需要在不同的项目中使用这个 dll 来读取存储的字符串。 我编写了以下函数来读取字符串: LPTSTR GetResour
我希望能够以编程方式修改应用程序的语言,或者至少使用在控制面板 -> 区域和语言选项 -> 格式中指定的语言。 如果我添加一个英语字符串表,制作一份法语和德语拷贝,然后删除英语,我可以通过编程方式在加
我的项目是这样设置的,所以所有的框架代码和模块都被编译成一个静态的.lib(我们称之为framework.lib),许多测试项目使用framework.lib并编译成可执行文件文件。 对于错误处理,我
我正在实现一个多线程应用程序,它从使用 MFC 编写的遗留应用程序中调用模块。 当我只使用一个线程运行它时,我的代码运行完美,但如果我使用多个线程运行它,当 CString::LoadString()
MS Visual Studio 2015 企业版; C++。 在我的控制台项目中,我添加了 RC 文件(即资源)并向其中添加了两个字符串: 我写了这样的函数来获取字符串: PCTSTR LoadSt
当我在命名空间中使用 LoadString WinAPI 宏时,我遇到了问题。我的功能: namespace Bushman { // Get the string from the reso
我想听听您对 LoadString Win32 函数包装器的看法。 int LoadWString( HINSTANCE hInstance_In, UINT uID_In, std::wstring
复制代码 代码如下: do local errorInfo = loadfile("test.lua"); --load code file i
1.loadfile只编译,不运行 loadfile(filename, mode, env) 用于加载一个指定路径filename的代码块,参数如下: 基本和load等同,区别是用来加载一个文件的代
我正在尝试测试 Lua loadstring 函数。 此示例是从 Lua 文档中获取指导的: f = loadstring("i = i + 1") 但是,当我尝试在以下位置运行它时: https
loadstring() 和 loadfile() Lua 函数允许在运行时加载远程库和模块。如本文所示,它非常简单:How Do I Load Lua Module as a String Inst
Windows 中定义的 LoadString 函数可用于从 dll 或 exe 等资源加载字符串。 Linux 中的 LoadString 等效函数是什么? 最佳答案 正如评论中所指出的,没有单一的
我有一些 Lua 代码,这似乎是试图通过隐藏来保护代码。我对loadstring()函数的理解是由Lua源代码文本组成的文本字符串,然后通过loadstring()方法转换为可执行的Lua代码。 通过
我正在尝试从我正在处理的 DLL 文件中的 Strin 表加载一个字符串。这是应该将字符串加载到 std::wstring 中的函数(因为我的项目使用 Unicode 字符集)。 void Error
我一直在尝试使用有前途的 p5.js 库制作一个简单的 Web 应用程序,但我陷入困境,不知道如何继续前进。为什么以下几行不起作用对我来说确实是个谜。我只是想加载一个简单的文本文件,但不能。它一直说它
我有一个静态链接的 MFC 应用程序,我正在尝试对其进行本地化。为方便起见,我希望所有字符串都来自 XML 文件。我已经为我的应用程序的其余部分设置了它。但是,MFC 会在内部从字符串资源中检索一些字
我一直在尝试使用 Scala 和 XML,我发现使用 XML.load(或 loadString)创建的 XML 标记与将其写为文字之间在行为上存在奇怪的差异。这是代码: import scala.x
另一个问题( String to Table in Lua )询问如何将格式化为表格的字符串转换为字符串,给出的答案是使用 loadstring 或 load 将字符串转换为 block 然后执行。
在我的 flutter 代码中,我有这样做的逻辑: final jsonString = await rootBundle.loadString('AssetManifest.json'); 我有测试
我是一名优秀的程序员,十分优秀!