P4API - Wrapper around Perforce C++ API on Windows

Contributed by Robert Cowham of Vizim Worldwide. Robert is a Perforce Consulting Partner and Trainer.

Introduction

This is a simple wrapper around the P4API to make it slightly easier to use from C++, and to make it similar in function to P4Ruby, P4Python etc.

Requirements:

Download

See p4api.zip for full sources.

Alternatively just navigate to this area of the Perforce Public Depot and sync as usual (requires a login from support@perforce.com).

Examples

See P4APITest/TestP4API.cpp for full examples.

StrBuf errMsg;
P4Connection p4;
InitP4(p4);     // Just sets Port/Client/User
p4.ParseForms();
WIN_ASSERT_ZERO(p4.Connect(errMsg), _T("Connect should work"));
p4.Run("info", 0, NULL);
WIN_ASSERT_TRUE(p4.InfoArray()->Count() > 0, _T("Some info returned."));
TraceResults(p4);

{
char *args[] = {"-s"};
p4.Run("login", 1, args);
TraceResults(p4);
}

p4.SetInput((LPCSTR) "brunopass");
p4.Run("login", 0, NULL);
TraceResults(p4);

Outputs from test harness:

See P4APITest/TEST_OUTPUT.txt.

Credits

Thanks to Tony Smith who helped along the way, and whose Ruby API provided inspiration.

Changes

See CHANGES.txt

Top