Example: Administration APIs
This example demonstrates how an application might use Administration APIs.
In this example, the APIs are used to get and display:
- The current product Version/Release/Modification level
- The current service pack (fix) level
- The features that currently are installed on the PC
Usage notes:
Include cwbad.h *
Link with cwbapi.lib
Example

#include <windows.h>
#include <stdio.h>
#include "cwbad.h"
/*
* This is the highest numbered component ID known (it is
* the ID of the last component defined in cwbad.h).
*/
#define LAST_COMPID_WE_KNOW_ABOUT (CWBAD_COMP_SSL)
/*
* Array of component names, taken from comments for component IDs
* in cwbad.h, so human-readable component descriptions are displayed .
* In the compDescr array, the component ID for a component must match
* the index in the array of that component's description.
*
* For a blank or unknown component name, a string is provided to display
* an indication that the component ID is unknown, and what that ID is.
*/
static const char* compDescr[ LAST_COMPID_WE_KNOW_ABOUT + 1 ] = {
"", // #0 is not used
"Required programs",
"", // #2 is not used
"", // #3 is not used
"", // #4 is not used
"", // #5 is not used
"", // #6 is not used
"", // #7 is not used
"Data Access",
"Data Transfer",
"Data Transfer Base Support",
"", // #11 is not used
"", // #12 is not used
"ODBC",
"OLE DB Provider",
"", // #15 is not used
"", // #16 is not used
"", // #17 is not used
"Printer Drivers",
"AFP printer driver",
"", // #20 is not used
"", // #21 is not used
"IBM i Access Programmer's Toolkit",
"Headers, Libraries, and Documentation",
"", // #24 is not used
"", // #25 is not used
"", // #26 is not used
"", // #27 is not used
".NET Data Provider",
"", //-------------#29
"", "", "", "", "", // #30-34
"", "", "", "", "", // #35-39
"", "", "", "", "", // #40-44
"", "", "", "", "", // #45-49
"", "", "", "", "", // #50-54
"", "", "", "", "", // #55-59
"", "", "", "", "", // #60-64
"", "", "", "", "", // #65-69
"", "", "", "", "", // #70-74
"", "", "", "", "", // #75-79
"", "", "", "", "", // #80-84
"", "", "", "", "", // #85-89
"", "", "", "", "", // #90-94
"", "", "", "", "", // #95-99
"", "", "", "", "", // not #100-104
"", "", "", "", "", // #105-109
"", "", "", "", "", // #110-114
"", "", "", "", "", // used #115-119
"", "", "", "", "", // #120-124
"", "", "", "", "", // #125-129
"", "", "", "", "", // #130-134
"", "", "", "", "", // #135-139
"", "", "", "", "", // #140-144
"", "", "", "", "", // #145-149
"", "", "", "", "", // #150-154
"", "", "", "", "", // #155-159
"", "", "", "", "", // #160-164
"", "", "", "", "", // #165-169
"", "", "", "", "", // #170-174
"", "", "", "", "", // #175-179
"", "", "", "", "", // #180-184
"", "", "", "", "", // #185-189
"", "", "", "", "", // #190-194
"", "", "", "", "", //------------ #195-199
"Secure Sockets Layer (SSL)" } ; // last one defined
static char unknownComp[] = "unknown, ID= ";
static char* pInsertID = &( unknownComp[12] ); // insert ID here!
/**************************************************************************
* Show the IBM i Access Version/Release/Modification level
**************************************************************************/
void showCA_VRM()
{
ULONG caVer, caRel, caMod;
UINT rc;
char fixlevelBuf[ MAX_PATH ];
ULONG fixlevelBufLen = sizeof( fixlevelBuf );
printf( "IBM i Access level installed:\n\n" );
rc = cwbAD_GetClientVersion( &caVer, &caRel, &caMod);
if ( rc != CWB_OK )
{
printf( " Error %u occurred when calling cwbAD_GetClientVersion()\n\n",
rc );
}
else
{
printf( " Version %lu, Release %lu, Modification %lu\n\n",
caVer, caRel, caMod );
printf( "IBM i Access service pack level installed:\n\n" );
rc = cwbAD_GetProductFixLevel( fixlevelBuf, &fixlevelBufLen );
if ( rc != CWB_OK )
{
printf( " Error %u occurred when calling "
"cwbAD_GetProduceFixLevel()\n\n", rc );
}
else if ( fixlevelBuf[0] == '\0' ) // empty, no service packs applied
{
printf( " None\n\n" );
}
else
{
printf( " %s\n\n", fixlevelBuf );
}
}
}
/**************************************************************************
* Call IBM i Access API to determine if the component is installed,
* and pass back:
* NULL if the component is not installed or an error occurs,
* OR
* A string indicating the component name is unknown if the
* component ID is higher than we know about OR the component
* description is blank,
* OR
* The human-readable component description if known.
**************************************************************************/
const char* isCompInstalled( ULONG compID )
{
cwb_Boolean bIsInstalled;
const char* pCompName;
UINT rc = cwbAD_IsComponentInstalled( compID, &bIsInstalled );
/*
* Case 1: Error OR component not installed, return NULL to
* indicate not installed.
*/
if ( ( rc != CWB_OK ) || ( bIsInstalled == CWB_FALSE ) )
{
pCompName = NULL;
}
/*
* Case 2: Component IS installed, but its name is not known,
* return component name unknown string.
*/
else if ( ( compID > LAST_COMPID_WE_KNOW_ABOUT ) ||
( compDescr[ compID ][ 0 ] == '\0' ) )
{
pCompName = unknownComp;
sprintf( pInsertID, "%lu", compID );
}
/*
* Case 3: Component IS installed, and a name is known, return it
*/
else
{
pCompName = compDescr[ compID ];
}
return pCompName;
}
/**************************************************************************
* List the IBM i Access Client Solutions features that currently are installed.
**************************************************************************/
void showCA_CompInstalled()
{
ULONG compID;
const char* compName;
printf( "IBM i Access features installed:\n\n" );
/*
* Try all known features, plus a bunch more in case some
* have been added (via service pack).
*/
for ( compID = 0;
compID < (LAST_COMPID_WE_KNOW_ABOUT + 50);
compID++ )
{
compName = isCompInstalled( compID );
if ( compName != NULL )
{
printf( " %s\n", compName );
}
}
printf( "\n" );
}
/**************************************************************************
* MAIN PROGRAM BODY
**************************************************************************/
int main(void)
{
UINT rc;
char pluginName[ MAX_PATH ];
cwb_Boolean bPluginInstalled;
printf( "=======================================\n");
printf( "IBM i Access What's Installed Reporter\n" );
printf( "=======================================\n\n");
showCA_VRM();
showCA_CompInstalled();
printf( "\nEnd of program.\n\n" );
return 0;
}
