将资源添加到Visual C ++ / CLI混合DLL

时间:2022-06-01 17:50:27

I'm writing a mixed C++/CLI DLL with both managed and unmanaged classes. Both need access to string and other types of resources, like Direct3D textures.

我正在编写一个包含托管和非托管类的混合C ++ / CLI DLL。两者都需要访问字符串和其他类型的资源,如Direct3D纹理。

How best to embed them within the DLL? It seems like there are several ways to do this; .resx (new style, managed), .rc (old style) which can be used to generate .resources files and (optionally) embedded within the assembly.

如何最好地将它们嵌入DLL中?似乎有几种方法可以做到这一点; .resx(新样式,托管),. rc(旧样式),可用于生成.resources文件和(可选)嵌入在程序集中。

Currently I'm using a .rc file and ::LoadString() to get my strings. I have a managed wrapper for this to return String^ values to managed code. And a similar method to return WCHAR* to native code.

目前我正在使用.rc文件和:: LoadString()来获取我的字符串。我有一个托管包装器,用于将String ^值返回给托管代码。以及将WCHAR *返回到本机代码的类似方法。

Is there a better way of doing this? What are the tradeoffs? I could for instance use a .resx file and the ResourceManager class for managed code and an .rc for native but this means I can't share resources etc. Is there a recommended approach?

有没有更好的方法呢?有什么权衡?我可以使用.resx文件和ResourceManager类用于托管代码,而.rc用于本机,但这意味着我无法共享资源等。是否有推荐的方法?

Thanks,

Ade

1 个解决方案

#1


I just use a .resx and if there is any strings the native code needs I use managed to get stuff out of my .resx file and convert it into a CString on the next line.

我只使用.resx,如果有本地代码需要的任何字符串我使用托管来从我的.resx文件中获取东西并将其转换为下一行的CString。

Although you already have a wrapper to do this so it would be even easier.

虽然你已经有一个包装器来做这个,所以它会更容易。

.rc files are so 1997 man!

.rc文件是如此1997年的男人!

#1


I just use a .resx and if there is any strings the native code needs I use managed to get stuff out of my .resx file and convert it into a CString on the next line.

我只使用.resx,如果有本地代码需要的任何字符串我使用托管来从我的.resx文件中获取东西并将其转换为下一行的CString。

Although you already have a wrapper to do this so it would be even easier.

虽然你已经有一个包装器来做这个,所以它会更容易。

.rc files are so 1997 man!

.rc文件是如此1997年的男人!