vc中的pin_ptr和interior_ptr++
我正在开发一个由以前在 Visual C++ 2008 中工作的人编写的项目(STM32 的 HID 接口)。因此,为了模仿导致问题的行,我在 VC++ 2008 中创建了一个示例 winform 应用程序。这是仅当为 x64 构建时,这一行的单击事件才会给出构建错误,但 win32 构建不会给出任何构建错误并且工作正常。
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ devPath = this->textBox1->Text;
MessageBox::Show(devPath);
pin_ptr<const TCHAR> pPath = PtrToStringChars(devPath); *error line
}
};
仅针对 x64 构建出现的构建错误是:
Error 1 error C2440: 'initializing' : cannot convert from 'cli::interior_ptr<Type>' to 'cli::pin_ptr<Type>'
谢谢。
I am working on a project that was written(a HID inteface for STM32) by a person who worked before in visual c++ 2008. So to imitate the line that is causing problem, I created a sample winform application in VC++ 2008. Here is the click event with this one line giving build error only when built for x64, but a win32 build doesn't give any building error and works fine.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ devPath = this->textBox1->Text;
MessageBox::Show(devPath);
pin_ptr<const TCHAR> pPath = PtrToStringChars(devPath); *error line
}
};
and the the build error that appears only for x64 build is:
Error 1 error C2440: 'initializing' : cannot convert from 'cli::interior_ptr<Type>' to 'cli::pin_ptr<Type>'
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这解决了问题。
This fixed the problem.
“更好”的解决方案可能是:
然后使用 CreateFileW,因为您有一个 Unicode 字符串。
这样,无论项目文件 Unicode 配置如何,您的代码都将正常工作。
The "better" solution is probably:
and then use
CreateFileW
, because you have a Unicode string.That way your code will work regardless of project-file Unicode configuration.