Linking to presentationcore.dll in mixed mode DLL

℡╲_俬逩灬. 提交于 2019-12-10 22:38:05

问题


We have a mixed mode DLL written in C++ which wraps native C++ DLLs and exposes managed classes. In the exposed managed classes, we use method arguments of type Vector3D etc., which are part of PresentationCore.DLL.

Therefore, the mixed mode C++ code needs to reference PresentationCore.DLL. We do this via

#using <PresentationCore.dll>

which requires the project's search path to include the folder PresentationCore.dll lives in.

This is bad, because these folders vary on different machines, and our projects need to compile without changes on several machines. At the moment, we have solved this by including a copy of PresentationCore.dll in our code repository, which is obviously not a good solution.

I'd be grateful for suggestions how we can get around specifying an explicit path to a DLL that should be perfectly accessible via GAC.


回答1:


Don't do #using <PresentationCore.dll>. You need to right click on the project, go to References..., click Add New Reference... and pick PresentationCore from the .Net tab. I got the hint from:

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




回答2:


Phew I got it working. I have a native project and I had the same issue, I need to use HwndSource from PresentationCore, to do some analysis on hwnds. What I did was to leave my project as native (no /clr switch), then for my source file which had the function that used HwndSource I added the /clr switch, that way I can contain the settings for other sources, like exception handling and such.

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

This works just fine, you will just won't get any Intellisense support. And some warnings in the output, if you can live with that, this is for you.




回答3:


The GAC is found in %windir%\Assembly\ then the subdirectory GAC_32 or GAC_64

In a situation like this I would use a symbolic link. Create a link to the DLL in the local directory. Then compile from that link.

Yes you have to change it for each machine. But all you have to do is a single line of batch script to do it.

Consider this running on my machine.

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

Pick the one you need (say GAC_64) and set a link to it- this all you should need.

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


来源:https://stackoverflow.com/questions/8891688/linking-to-presentationcore-dll-in-mixed-mode-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!