Making a 64 bit Windows plug-in for Photoshop

This page describes the process for creating a 64 bit Windows plug-in for Photoshop.

Here is a list of the items needed to build and test a 64 bit Windows plug-in. This documentation will focus on updating the Dissolve filter example for 64 bit. All projects in the SDK have a 64 bit output option. Refer to the specific plug-in type for more information.

  • Adobe Photoshop CS5 Windows
  • Adobe Photoshop CS5 SDK
  • Microsoft Visual Studio 2008 Professional Edition
  • Microsoft Windows Vista 64

Step 1: Find portability issues

The majority of the problems you will deal with when converting from 32 bit to 64 bit are assumptions made about the size of a pointer. There is a lot of code that puts a pointer ( 4 or 8 bytes ) into an int or long ( 4 bytes only ). As you can see, that will no longer work in the 64 bit environment. The second biggest problem is using the wrong type when getting the size of information. The new operator and many size operators return a size_t type ( 4 or 8 bytes ) and are assigned to int or long ( 4 byte ) values. Visual Studio has an option to give developers warnings about these situations. The warnings occur in your 32 bit build environment so you can start removing those issues before you tackle 64 bit specific problems. It is recommended that this be the first step in getting your plug-in to 64 bit. Visual Studio has an option that will generate warnings for 64 bit compatibility issues. From the Project menu select Properties. In the left pane select Configuration Properties, select C/C++, select General. In the right pane change "Detect 64-bit Portability Issues" to Yes

Detect64BitIssues.jpg

After building with this option on you will find four typcical warnings that are all basically the same type of a problem outlined above. "Possible loss of data" converting from one type to another. Typically, changing one location moves the problem to another location until you finally refactor your code all the way. You will find that many helper and utility routines found in the SDK common folder had to be modified for such situations.

  • size_t is 4 or 8 bytes
  • int is 4 bytes
  • long is 4 bytes
  • pointer is 4 or 8 bytes
  • intptr_t is 4 or 8 bytes

Step 2: Add 64 bit target

Once completing step 1 a new target for 64 bit builds needs to be made to your project. From the Project menu select Properties. Click the Configuration Manager button at the top right. From the Active Solution Platform select new. Select x64 from the Type or Select new platform. If you do not see the x64 target option you will need to re-run the installer for Visual Studio. See Microsoft Visual Studio Installer notes below.

Adjust your intermediate and output files for the Debug x64 target. I changed all locations from a Debug folder to a Debug64 folder. Go through each option in your Properties dialog to find all locations for your outputs.

Step 3: Fix entry point and PiPL

The main entry point to the plug-in needs to be changed.

// --------------------------------------
// The old entrypoint
// --------------------------------------
DLLExport MACPASCAL void PluginMain(
  const int16 selector, 
  void * filterRecord, 
  int32 * data, 
  int16 * result)

// --------------------------------------
// Thew new entrypoint
// using the dynamic type intptr_t 
// --------------------------------------
DLLExport MACPASCAL void PluginMain(
  const int16 selector, 
  void * filterRecord, 
  intptr_t * data, 
  int16 * result)

The PiPL property needs a 64 bit selector. Here is the recommended PiPL properties for all platforms:

#ifdef __PIMac__
    #if (defined(__x86_64__))
        CodeMacIntel64 { "PluginMain" },
    #endif
#else
    #if defined(_WIN64)
        CodeWin64X86 { "PluginMain" },
    #else
        CodeWin32X86 { "PluginMain" },
    #endif
#endif

Step 4: Test

Adobe Photoshop CS5 installs two copies on a 64 bit compatibile operating system. The 32 bit version can be found at
C:\Program Files (x86)\Adobe\Adobe Photoshop CS5 
This is the default location for 32 bit applications for Windows Vista 64. The 64 bit version can be found at
C:\Program Files\Adobe\Adobe Photoshop CS5 
Ensure that you copy the correct version of your plug-in to the correct version of the host application. The Windows Task Manager will show a *32 next to the application name in the "Image Name" column under the Processes tab.

Other Issues

Inline assembly will not work for 64 bit targets. MMX code will not work for 64 bit targets. These can work using the Intel compiler but not Visual Studio. Please refer to the Intel web page for information about the Intel Compiler. The Photoshop SDK does not use any assembler code in the examples. Use the WIN64 compile flag to determine that the target is 64 bit.

Online Information

More information is found on the Microsoft Developer Network. Common Visual C++ 64-bit Migration Issues and Predefined Macros are good starting points.

Finding the Version info in Visual Studio

Find the version from the command line. Type "cl /?" at the prompt. The Version at the beginning is 15.00.30729.01.

Or from the Help > About Microsoft Visual Studio menu

Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1
Microsoft Visual C++ 2008   91605-270-4005417-60312

Microsoft Visual Studio Installer

Run the Microsoft Visual Studio Installer. At the Options Page dialog make sure the X64 Compilers and Tools option is selected. After running the installer make sure that Visual Studio is up to date by running the Microsoft Updater. Service Pack 1 and many other updates are required before proceeding. This image is from the 2005 installer. The 2008 installer is very similar.

VisualStudio64BitOption.jpg