简体   繁体   English

托管C ++ dll中的XmlnsDefinition

[英]XmlnsDefinition in a managed C++ dll

We have a managed dll that implements a public ref class derived from HwndHost in a Cpp namespace. 我们有一个托管的dll,它在Cpp命名空间中实现从HwndHost派生的公共引用类。 We build a x86 version named mydll10.dll and a x64 version named mydll10_x64.dll. 我们构建一个名为mydll10.dll的x86版本和一个名为mydll10_x64.dll的x64版本。 We are using the Cpp namespace in a WPF application in the xaml page. 我们在xaml页面的WPF应用程序中使用Cpp名称空间。 We are able to add the proper reference in the project using '$(Platform)' conditions. 我们可以使用'$(Platform)'条件在项目中添加适当的引用。 But we should use in the same page both xmlns:c="clr-namespace:Cpp;assembly=UvpProInspectWpf10" for the x86 and xmlns:c="clr-namespace:Cpp;assembly=UvpProInspectWpf10_x64" for the x64 exe. 但是对于x86,我们应该在同一页面中同时使用xmlns:c =“ clr-namespace:Cpp; assembly = UvpProInspectWpf10”和x64 exe都应使用xmlns:c =“ clr-namespace:Cpp; assembly = UvpProInspectWpf10_x64”。 It is no possible to use any sort of #if #then #else in the xaml. 在xaml中无法使用任何类型的#if #then #else。

If the Cpp namespace would be in a C# project, a solution could be in the write 如果Cpp名称空间位于C#项目中,则可以在写入中提供解决方案

`myurl:"http://schemas.me.com/wpf/"
#if x64
[assembly: XmlnsDefinition(myurl, "UvpProInspectWpf10_x64")]
#else
[assembly: XmlnsDefinition(myurl, "UvpProInspectWpf10")]
#endif

Assembly.cs file and define Assembly.cs文件并定义

xmlns:c=" http://schemas.me.com/wpf/” 

in the xaml. 在xaml中。 I cannot find how to do these assembly definitions in the managed C++ project. 我在托管C ++项目中找不到如何执行这些程序集定义。 Is this possible? 这可能吗? Of course we could break our naming rules… Thanks 当然,我们可以打破命名规则…谢谢

Found it. 找到了。 Add a reference to System.Xaml.dll to the C++ managed project. 将对System.Xaml.dll的引用添加到C ++托管项目中。 Add an AssemblyInfo.cpp file with 使用以下命令添加AssemblyInfo.cpp文件

using namespace System::Windows::Markup;
[assembly:XmlnsDefinition("http://schemas.me.com/wpf/", "Cpp")];

Then you can use in the xaml page 然后您可以在xaml页面中使用

xmlns:c=" http://schemas.me.com/wpf/” 

with the project referring to the proper x86 or x64 version 该项目引用了正确的x86或x64版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM