Perforce API

Introduction

The Perforce API is an API provided by Perforce to programmatically interact with the Perforce server. The API is available for several programming languages. This tutorial focuses on using the C++ API with Visual Studio 2012.

Installing the Perforce API headers and libraries

The API is available from the Perforce FTP site: http://ftp.perforce.com/perforce/. You first have to choose which version of the API you want to use. There shouldn't be a need to select exactly the same version as the one of the server. Later versions of the API should be able to interact with earlier version of the server. However I haven't tested that in depth. For this tutorial we choose version 13.3: http://ftp.perforce.com/perforce/r13.3/. Then we need to choose the OS and architecture. For Windows that would be either bin.ntx86, bin.ntx64 or bin.ntia64. Note that if you are on a 64-bit version of the OS but develop a 32-bit application you would use bin.ntx86 not bin.ntx64. For this tutorial we use the 32-bit version found at: http://ftp.perforce.com/perforce/r13.3/bin.ntx86/.

The last choice to be made is which version of Visual Studio will be used and which runtime library. The files with a "dyn" in the name are for use with the DLL version of the runtime library (/MD or /MDd option) while the files with a "static" in it are for the static version of the runtime library (/MT or /MTd option). The files with a "vsdebug" part are to be used with the "Debug" build and the other for the "Release" build. For this tutorial we will be using Visual Studio 2012 and the static version of the runtime library in both the "Debug" (/MTd option) and "Release" (/MT option) configuration so we will download both http://ftp.perforce.com/perforce/r13.3/bin.ntx86/p4api_vs2012_static.zip and http://ftp.perforce.com/perforce/r13.3/bin.ntx86/p4api_vs2012_static_vsdebug.zip. We unzip the release version in C:\p4api and the debug version in C:\p4apidebug.

The test environment

We do need a Perforce server to send the commands to. For this tutorial we assumed we have a server running on the local network reachable via 192.168.28.131:1666. You will have to update the examples to use the address for your environment.

The server has one defined workspace, Workspace1, owned by TestUser1 and mapped to C:\p4clients\Workspace1. This is shown in figures 1 and 2.

Perforce API test server workspaces
Figure 1: Perforce API test server workspaces
Perforce API test server Workspace1 specification
Figure 2: Perforce API test server Workspace1 specification
Perforce API test server users
Figure 3: Perforce API test server users
Perforce API test server depots
Figure 4: Perforce API test server depots

blog comments powered by Disqus

Copyright(c) 2006-2015 Xavier Leclercq | Privacy policy

Home
Contact Us
Search