非托管C ++如何使用resx文件? [英] How can unmanaged C++ use a resx file?

查看:112
本文介绍了非托管C ++如何使用resx文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio,我可以将.resx资源文件添加到非托管的Visual C ++项目中.但是我该怎么用呢?

Using Visual Studio, I can add a .resx resources file to the unmanaged Visual C++ project. But how can I use it?

它可以正常编译,但是不会生成可包含在源代码中的资源标头.对于经典的RC文件,存在带有资源ID的标头.

It compiles fine, but no resource headers are generated that can be included in source. For the classical RC files, there are headers with resource IDs.

我想使用resx文件在托管库和非托管库之间具有共享资源,例如字符串和图标.想法是在两个项目中都包含相同的resx文件.

I want to use resx files to have a shared resources, like strings and icons, between managed and unmanaged libraries. The idea was to include the same resx file in both projects.

推荐答案

您不能.该工具缺少将它们从.resx格式转换为二进制.resource文件并将其嵌入托管程序集清单中的工具.因此,本机C ++项目不必创建程序集.

You can't. The tooling is missing to translate them from their .resx format to binary .resource files and embed them in the managed assembly manifest. Necessarily so, native C++ projects don't create an assembly.

请改用.rc文件. C ++ IDE很好地支持它,如果您还没有的话,请使用Project + Add New Item,Resource节点,"Resource File(.rc)"模板.双击添加的项目以打开资源编辑器.使用winapi函数(例如LoadString,LoadIcon等)在运行时加载资源.如果需要与托管代码共享资源,则该代码将需要调用这些相同的函数.您可以考虑复制它们以避免这种情况.否则,要求共享没有任何意义.

Use a .rc file instead. Well supported by the C++ IDE, if you don't have one yet then use Project + Add New Item, Resource node, "Resource File (.rc)" template. Double-click the added item to open the resource editor. Load resources at runtime with winapi functions, like LoadString, LoadIcon, etc. If you need to share them with managed code then that code will need to pinvoke those same functions. You might consider duplicating them to avoid that. It doesn't otherwise make a lot of sense to require sharing.

这篇关于非托管C ++如何使用resx文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆