This example illustrates using remote iSeries™ Access for Windows® Command/Distributed Program Call APIs.
#ifdef UNICODE #define _UNICODE #endif #include <windows.h> // Include the necessary RC/DPC Classes #include <stdlib.h> #include <iostream.h> #include <TCHAR.H> #include "cwbrc.h" #include "cwbcosys.h" /**********************************************************************/ void main() { cwbCO_SysHandle system; cwbRC_SysHandle request; cwbRC_PgmHandle program; // Create the system object if ( (cwbCO_CreateSystem("AS/400SystemName",&system)) != CWB_OK ) return; // Start the system if ( (cwbRC_StartSysEx(system,&request)) != CWB_OK ) return; // Call the command to create a library char* cmd1 = "CRTLIB LIB(RCTESTLIB) TEXT('RC TEST LIBRARY')"; if ( (cwbRC_RunCmd(request, cmd1, 0)) != CWB_OK ) return; cout << "Created Library" << endl; // Call the command to delete a library char* cmd2 = "DLTLIB LIB(RCTESTLIB)"; if ( (cwbRC_RunCmd(request, cmd2, 0)) != CWB_OK ) return; cout << "Deleted Library" << endl; // Create a program object to create a user space if ( cwbRC_CreatePgm(_TEXT("QUSCRTUS"), _TEXT("QSYS"), &program) != CWB_OK ) return; // Add the parameters // name is DPCTESTSPC/QGPL unsigned char name[20] = {0xC4,0xD7,0xC3,0xE3,0xC5,0xE2,0xE3,0xE2,0xD7,0xC3, 0xD8,0xC7,0xD7,0xD3,0x40,0x40,0x40,0x40,0x40,0x40}; // extended attribute is not needed unsigned char attr[10] = {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40}; // initial size is 100 bytes unsigned long size = 0x64000000; // initial value is blank unsigned char init = 0x40; // public authority is CHANGE unsigned char auth[10] = {0x5C,0xC3,0xC8,0xC1,0xD5,0xC7,0xC5,0x40,0x40,0x40}; // description is DPC TEMP SPACE unsigned char desc[50] = {0xC4,0xD7,0xC3,0x40,0xE3,0xC5,0xD4,0xD7,0x40,0xE2, 0xD7,0xC1,0xC3,0xC5,0x40,0x40,0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40}; if ( cwbRC_AddParm(program, CWBRC_INPUT, 20, name) != CWB_OK) return; if ( cwbRC_AddParm(program, CWBRC_INPUT, 10, attr) != CWB_OK) return; if ( cwbRC_AddParm(program, CWBRC_INPUT, 4, (unsigned char*)&size) != CWB_OK) return; if ( cwbRC_AddParm(program, CWBRC_INPUT, 1, &init) != CWB_OK) return; if ( cwbRC_AddParm(program, CWBRC_INPUT, 10, auth) != CWB_OK) return; if ( cwbRC_AddParm(program, CWBRC_INPUT, 50, desc) != CWB_OK) return; // Call the program if ( cwbRC_CallPgm(request, program, 0) != CWB_OK ) return; cout << "Created User Space" << endl; // Delete the program if ( cwbRC_DeletePgm(program) != CWB_OK ) return; // Create a program object to delete a user space if ( cwbRC_CreatePgm(_TEXT("QUSDLTUS"), _TEXT("QSYS"), &program) != CWB_OK ) return; // Add the parameters // error code structure will not be used unsigned long err = 0x00000000; if ( cwbRC_AddParm(program, CWBRC_INPUT, 20, name) != CWB_OK) return; if ( cwbRC_AddParm(program, CWBRC_INOUT, 4, (unsigned char*)&err) != CWB_OK) return; // Call the program if ( cwbRC_CallPgm(request, program, 0) != CWB_OK ) return; // Delete the program if ( cwbRC_DeletePgm(program) != CWB_OK ) return; cout << "Deleted User Space" << endl; // Stop the system if ( cwbRC_StopSys(request) != CWB_OK ) return; // Delete the system object if ( cwbCO_DeleteSystem(system) != CWB_OK ) return; }