CString 错误,“CString”:不是“ATL::CStringT”的成员

发布于 2024-10-09 22:56:41 字数 451 浏览 4 评论 0原文

我正在尝试这样做:

#include <atlstr.h>

CHAR Filename; // [sp+26Ch] [bp-110h]@1
char v31; // [sp+36Ch] [bp-10h]@1
int v32; // [sp+378h] [bp-4h]@1

 GetModuleFileNameA(0, &Filename, 0x100u);
 CString::CString(&v31, &Filename);

但我收到编译器错误 C2039:'CString': is not a member of 'ATL::CStringT'

This is a non MFC based dll, but 根据文档,您应该能够使用带有 include #include atlstr.h 的 CString 功能如何使其工作?

谢谢

I am trying to do this:

#include <atlstr.h>

CHAR Filename; // [sp+26Ch] [bp-110h]@1
char v31; // [sp+36Ch] [bp-10h]@1
int v32; // [sp+378h] [bp-4h]@1

 GetModuleFileNameA(0, &Filename, 0x100u);
 CString::CString(&v31, &Filename);

But I am getting the compiler error C2039:'CString': is not a member of 'ATL::CStringT'

This is a non MFC based dll, but according to the docs you should be able to use CString functionality with the include #include atlstr.h how do I make it work?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晒暮凉 2024-10-16 22:56:41

这不是 C++ 中调用构造函数的方式。

CString s = CString(&v21,&File);

请注意,GetModuleFilename 需要一个指向字符数组(它填充的)的指针,而不是指向单个字符。因此,您的代码注定会在运行时崩溃。

That's not how constructors are invoked in C++.

CString s = CString(&v21,&File);

Note that GetModuleFilename expects a pointer to an array of characters (which it fills), not a pointer to a single character. Your code is therefore doomed to crash at runtime.

淡水深流 2024-10-16 22:56:41

此代码片段中存在几个问题:

1) CHAR Filename; 声明一个仅为单个字符的变量。但是,GetModuleFileNameA 期望获得一个指向字符数组的指针。当您传递参数 &Filename0x100u 时,您会使其认为 &Filename 指向一个具有 up 空间的内存数组最多 256 个字符。然而,正如你的片段中所写的,它只是一个字符。因此你会遇到严重的缓冲区溢出。

在这种情况下,Filename 最有可能被声明为 CHAR Filename[0x100];。这也意味着您在将文件名传递给该函数时不需要获取文件名的地址。因此,调用将写为 GetModuleFileNameA(0, Filename, 0x100u);

2) 为构造函数编写代码时,您可以通过编写类似于 CString::CString 的内容来定义code> (使用类的名称),然后填写函数。但是,当使用构造函数时,您根本不使用该语法。您无需调用 CString::CString() 来创建 CString 对象。

您必须为 CString 对象选择一个名称,例如“FilenameStr”。因此,在您的代码上下文中,您将编写类似 CString FilenameStr(Filename);

3) 正如最后一点末尾所暗示的那样,您尝试传递给构造函数的参数是错误的。 &v31&Filename 将分别指向原始代码中的字符。但是,据我所知,CString 没有任何采用两个字符指针的构造函数。

我什至不知道 v31 应该如何参与其中,但似乎根本没有必要。如果您想用字符数组的内容填充 CString,那么您只需将该数组传递给构造函数,它就会处理所有事情。所以,类似于 CString FilenameStr(Filename);

You have several problems in this code snippet:

1) CHAR Filename; declares a variable that is only a single character. However, GetModuleFileNameA expects to be given a pointer to an array of characters. When you pass the parameters &Filename and 0x100u you would make it think that &Filename points to an array of memory with room for up to 256 characters. However, as written in your snipped, it's only a single character. Thus you would have a bad buffer overflow.

Filename should most likely be declared as CHAR Filename[0x100]; in this case. That would also mean you don't need to take the address of Filename when passing it to that function. So the call would then be written as GetModuleFileNameA(0, Filename, 0x100u);

2) When writing code for a constructor, you define is by writing something similar to CString::CString (using whatever your class's name is) and then filling out the function. However, when using a constructor you don't use that syntax at all. You don't call CString::CString() to create a CString object.

You would have to choose an name for the CString object, such as "FilenameStr". So the in the context of you code you would write something like CString FilenameStr(Filename);

3) As implied at the end of the last point, the parameters you are trying to pass to the constructor are wrong. &v31 and &Filename would each by pointers to characters in your original code. However, as far as I know, CString does not have any constructor that takes two character pointers.

I can't even tell how v31 is supposed to be involved there, but it doesn't seem necessary at all. If you want to fill a CString with the contents of a character array, then you can just pass that array to the constructor and it will take care of everything. So, something like CString FilenameStr(Filename);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文