链接到混合模式DLL中的presentationcore.dll

时间:2012-01-17 08:36:09

标签: c++ gac using managed mixed-mode

我们有一个用C ++编写的混合模式DLL,它包装本机C ++ DLL并公开托管类。在公开的托管类中,我们使用Vector3D等类型的方法参数,它们是PresentationCore.DLL的一部分。

因此,混合模式C ++代码需要引用PresentationCore.DLL。我们通过

来做到这一点
#using <PresentationCore.dll>

需要项目的搜索路径包含PresentationCore.dll所在的文件夹。

这很糟糕,因为这些文件夹在不同的机器上有所不同,我们的项目需要在几台机器上进行编译而无需更改。目前,我们已经通过在我们的代码库中包含一份PresentationCore.dll来解决这个问题,这显然不是一个好的解决方案。

我很感激建议我们如何绕过指定一个可以通过GAC完全访问的DLL的显式路径。

3 个答案:

答案 0 :(得分:1)

不要#using <PresentationCore.dll>。您需要右键点击该项目,转到References...,点击Add New Reference...,然后从PresentationCore标签中选择.Net。我得到了提示:

http://msdn.microsoft.com/en-us/library/aa970266.aspx

答案 1 :(得分:0)

Phew我得到了它的工作。我有一个原生项目,我有同样的问题,我需要使用PresentationCore的HwndSource,对hwnds做一些分析。我做的是将我的项目保留为本机(无/ clr开关),然后对于我的源文件,其中有使用HwndSource的函数我添加了/ clr开关,这样我可以包含其他源的设置,如异常处理等等。

#using <System.dll>
#using <WindowsBase.dll>
#using <PresentationFramework.dll>
#using <PresentationCore.dll>
#using <UIAutomationProvider.dll>
#using <UIAutomationTypes.dll>

这很好用,你将不会获得任何Intellisense支持。输出中的一些警告,如果你可以忍受,那就适合你。

答案 2 :(得分:-1)

在%windir%\ Assembly \中找到GAC,然后是子目录GAC_32或GAC_64

在这种情况下,我会使用符号链接。在本地目录中创建DLL的链接。然后从该链接进行编译。

是的,您必须为每台机器更改它。但是你要做的就是用一行批处理脚本来完成它。

考虑在我的机器上运行。

C:\temp>for /f "tokens=*" %f in ('dir \windows\assembly\presentationcore.dll  /s/b') do @echo %f
C:\windows\assembly\GAC_32\PresentationCore\3.0.0.0__31bf3856ad364e35\PresentationCore.dll
C:\windows\assembly\GAC_64\PresentationCore\3.0.0.0__31bf3856ad364e35\PresentationCore.dll

选择你需要的那个(比如说GAC_64)并设置一个链接 - 这就是你应该需要的。

@for /f "tokens=*" %f in ('dir \windows\assembly\presentationcore.dll  /s/b') do @echo %f | @findstr GAC_64 | mklink .\presentationCore.dll "%f"
相关问题