Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to interact with a 64-bit COM server (Photoshop) from .NET?

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.

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

COMException was unhandled

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)).

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?

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.

The exception occurs here:

Type photoshopType = Type.GetTypeFromProgID("Photoshop.Application");
if (photoshopType != null)
{
    object photoshop = Activator.CreateInstance(photoshopType);
like image 369
unrelativity Avatar asked May 12 '11 07:05

unrelativity


2 Answers

.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.

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

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

like image 155
Heath Avatar answered Nov 04 '22 11:11

Heath


Couple of things to check for using COM from/to different environments:

  1. Toggle the "Embed Interop Types" for the COM reference (see image 1)
  2. Check the Platform Target (see image 2)

Image 1 - Reference PropertyImage 2 - Platform Target

like image 45
Aaron Barker Avatar answered Nov 04 '22 13:11

Aaron Barker