Accessing embedded resources in C++/CLI

妖精的绣舞 提交于 2019-12-07 00:25:30

In Visual Studio, C# projects have a resx file designer and a properties class generator. C++/CLI projects only get the resx file designer. Both get the build steps to embed the compiled resources in the assembly.

You can write a Properties class yourself or just access the resources in code where you need them like this:

auto resourceAssembly = Reflection::Assembly::GetExecutingAssembly();
// .Resources is the name generated by resxgen, e.g., from the input file name Resources.resx
auto resourceName = resourceAssembly->GetName()->Name + ".Resources"; 
auto resourceManager = gcnew Resources::ResourceManager(resourceName, resourceAssembly);
auto String1 = cli::safe_cast<String^>(resourceManager->GetObject("String1"));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!