P4COM - COM Interface to Perforce C++ API on Windows

p4com is contributed by Robert Cowham of Vaccaperna Systems Ltd.

See the paper I presented at the Perforce User Conference in 2001: Adventures in API Land for an overview of the API and how I use it. In particular pay attention to the section on error handling!

This DLL is similar to p4vb which is part of P4OFC - the integration between Microsoft Office and Perforce and thus is stable and tested.

Compiler

This COM DLL has been built with MS VC++ 6.0 (SP5). Future versions will be built with VC++ 7.0.

Use either of the project settings:

You can download the complete source and a pre-built (release) version of the resulting DLL from p4com.zip.

To use it, you need to register the DLL (run regsvr32.exe on the DLL).

An installer will be provided in the future.

Main Interface

The interface has been reworked from previous incarnations and is similar to that implemented by Tony Smith for Ruby.

There is a single object P4COMLib.p4 which should be instantiated and used.

Note that the command will pick up Perforce environment information in the the normal way - so global settings are used, or P4CONFIG settings are used. Make sure the current directory where your code is executing is set appropriately.

Examples

As an example of using it, in a VB project, make sure you have set a reference to COM object "p4com 1.0 Type Library".

You can then execute a simple command such as "p4 info":

Dim p4 As P4COMLib.p4
Dim InfoArr() As String
Dim ErrorArr() As String

p4.Connect

InfoArr = m_p4.run("info")

Dim i as integer
For i = LBound(InfoArr) To UBound(InfoArr)
    ResultBox.AddItem InfoArr(i)
Next
p4.Disconnect

This assumes a Listbox called ResultBox.

Example VB Project

A simple VB test project is to be found in the zip file.

This demonstrates how to read and set environment values (p4.port, p4.client), and also how to perform a submit using a combination of "p4 change -o", manipulate the results and then execute the command with "p4 submit -i"

Example C# Project

This will be included shortly and shows how to call from C# (VS.NET). Principles will be the same for any of the other .NET languages.

 

Top