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 I wrote and 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 able to 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). I suggest you install in "c:\program files\perforce" or wherever you installed Perforce.

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 Projects

These are to be found in the zip file.

They demonstrate 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"

There are 3 example projects (very similar functionality):

Just load them up, compile and run and you should be fine (provided DLL was previously registered).

Unicode Enabled

p4com.dll is unicode enabled and is an example of how to use the Perforce API with Unicode servers (where P4CHARSET is in use). Being COM, all strings such as filenames, change descriptions and the like, may be in Unicode and will be handled correctly.

Top