可以与.NET的64位COM服务器(Photoshop)进行交互吗? [英] Possible to interact with a 64-bit COM server (Photoshop) from .NET?

查看:65
本文介绍了可以与.NET的64位COM服务器(Photoshop)进行交互吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过添加COM引用和后期绑定来编写一些与Photoshop进行交互的代码.我花了一段时间才意识到代码确实有效,但不适用于64位版本的Photoshop.

I've been trying to write some code to interact with Photoshop, both by adding a COM reference and by late binding. It took me a while to realise that the code did work, but not with the 64-bit version of Photoshop.

我在64位Photoshop中遇到的异常如下:

The exception I get with 64-bit Photoshop is as follows:

未处理COMException

COMException was unhandled

检索COM类工厂以获取 具有CLSID的组件 {D9389EDE-AEF8-4092-9377-075E94B7CB9A} 由于以下错误而失败: 80080005服务器执行失败 (来自HRESULT的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE).

Retrieving the COM class factory for component with CLSID {D9389EDE-AEF8-4092-9377-075E94B7CB9A} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

我的应用程序是否可以与64位版本的Photoshop通信?还是仅限于与32位版本进行通信?

Is it possible for my application to communicate with the 64-bit version of Photoshop? Or is it limited to just communicating with the 32-bit version?

在尝试寻找解决方案的众多尝试之一中,我遇到了 ,但我不知道如何将CLSCTX_ACTIVATE_64_BIT_SERVER标志与COM引用或后期绑定一起使用,假设它是 解决方案.

I've come across this in one of my numerous attempts to find a solution, but I don't see how I could put the CLSCTX_ACTIVATE_64_BIT_SERVER flag into use with either a COM reference or late binding, well, supposing that it is the solution.

异常发生在这里:

Type photoshopType = Type.GetTypeFromProgID("Photoshop.Application");
if (photoshopType != null)
{
    object photoshop = Activator.CreateInstance(photoshopType);

推荐答案

.NET应用程序可执行文件(.exe)如果标记为AnyCPU,将始终以运行中的处理器体系结构的本机位运行,该编译为MSIL.因此,在64位平台上运行的任何MSIL程序集都将运行64位,而在32位平台上运行的所有MSIL程序集将运行32位.

.NET application executables (.exe) will always run in the native bitness of the running processor architecture if marked for AnyCPU, which compiles down to MSIL. So any MSIL assembly running on a 64-bit platform will run 64-bit, and on a 32-bit platform will run 32-bit.

在您的情况下,您要么希望针对AnyCPU进行编译,但是如果必须强制使用64位互操作,请使用x64.当然,这在32位计算机上不起作用.这将从注册表的64位视图(包括InProc

In your case you'd either want to compilre for AnyCPU, but if you must force a 64-bit interop use x64. This won't work on a 32-bit machine, of course. This will natively read from the 64-bit view of the registry (including InProc

您还必须注意如何整理指针.如果编写自己的互操作代理,请确保使用IntPtr作为句柄.

You must also be careful of how pointers are marshaled. Be sure to use IntPtr for handles if writing your own interop proxy.

这篇关于可以与.NET的64位COM服务器(Photoshop)进行交互吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆