Difference between revisions of "RPC's with Visual Cpp"

From VistApedia
Jump to: navigation, search
m
m
Line 1: Line 1:
First you will need to install the RPC Broker Kit (available at ftp://ftp.va.gov).
+
First you will need to install the RPC Broker Kit (available at ftp://ftp.va.gov). For Example1, I created an M program and set-up the Remote Procedures File accordingly.
  
 
Copy Bapi32.hpp into your Visual C++ project's header files directory.
 
Copy Bapi32.hpp into your Visual C++ project's header files directory.
Line 32: Line 32:
 
     for (int j=0;j<num2.GetLength();j++)
 
     for (int j=0;j<num2.GetLength();j++)
 
         num2c[j]=num2[j];
 
         num2c[j]=num2[j];
 
+
   
 +
    RPCBroker.RPCBPropSet("RemoteProcedure","TEST");
 
     RPCBroker.RPCBPropSet("ClearParameters","1");
 
     RPCBroker.RPCBPropSet("ClearParameters","1");
 
     RPCBroker.RPCBPropSet("ClearResults","1");
 
     RPCBroker.RPCBPropSet("ClearResults","1");

Revision as of 21:04, 20 July 2007

First you will need to install the RPC Broker Kit (available at ftp://ftp.va.gov). For Example1, I created an M program and set-up the Remote Procedures File accordingly.

Copy Bapi32.hpp into your Visual C++ project's header files directory.

In Visual Studio, right-click on your "Header Files" folder and click "Add Files to Folder..." Add Bapi32.hpp. Be sure to add an include line for this header file in one of your source files:

  1. include "Bapi32.hpp"


In your dialog cpp file, create a new global instance of TRPCBroker:

TRPCBroker RPCBroker;


Variable declarations for my examples:

   char * result = "";
   CString num1="";
   CString num2="";
   CString num3="";
   char num1c[10]="";
   char num2c[10]="";
   CString name="";
   char namec[255]="";
   int Ulocation=0;


Example 1: This example takes two user-specified integers, passes those integers to VistA, and receives the sum.

   for (int i=0;i<num1.GetLength();i++)
       num1c[i]=num1[i];
   for (int j=0;j<num2.GetLength();j++)
       num2c[j]=num2[j];
   
   RPCBroker.RPCBPropSet("RemoteProcedure","TEST");
   RPCBroker.RPCBPropSet("ClearParameters","1");
   RPCBroker.RPCBPropSet("ClearResults","1");
   RPCBroker.RPCBPropSet("Server","brokerserver");
   RPCBroker.RPCBPropSet("ListenerPort","9200");
   RPCBroker.RPCBParamSet(0,0,num1c);
   RPCBroker.RPCBParamSet(1,0,num2c);
   try
   {
       result = RPCBroker.RPCBCall("");
   }
   catch ( ... )
   {
       MessageBox("Runtime Error","RPCBroker Call");
       result = "Error";
   }
   num3=result;


Example 2: This example uses the server settings as shown in Example 1; This code will ask VistA for the user's DUZ, then request the user's name, ip address, current port number, server operating system, and current job number.

   RPCBroker.RPCBPropSet("Connected","1"); //Displays VistA sign-on splash screen
   RPCBroker.RPCBPropSet("RemoteProcedure","XWB GET VARIABLE VALUE");
   RPCBroker.RPCBParamSet(0,1,"DUZ");
   result = RPCBroker.RPCBCall("");
   name.Format("^VA(200,%s,0)",result);
   for (int i1=0;i1<name.GetLength();i1++)
       namec[i1]=name[i1];
   RPCBroker.RPCBParamSet(0,1,namec);
   result = RPCBroker.RPCBCall("");
   namebox = result;
   for (int i2=0;i2<namebox.GetLength();i2++)
   {
       if (result[i2]==94) 
       {
           Ulocation=i2;
           i2=namebox.GetLength();
       }
   }
   namebox = namebox.Mid(0,Ulocation);
   RPCBroker.RPCBParamSet(0,1,"XWBTIP");
   result = RPCBroker.RPCBCall("");
   ipbox = result;
   RPCBroker.RPCBParamSet(0,1,"XWBTSKT");
   result = RPCBroker.RPCBCall("");
   portbox=result;
   RPCBroker.RPCBParamSet(0,1,"$ZV");
   result = RPCBroker.RPCBCall("");
   osbox = result;
   RPCBroker.RPCBParamSet(0,1,"$J");
   result = RPCBroker.RPCBCall("");
   jobbox = result;


Example 3: This example disconnects the previous server.

   RPCBroker.RPCBPropSet("Connected","0");