Step 1 : Write the Java Code
Following is an snippet Java code for Recording, Saving the Recorded Macro in a file, and Playing the recorded macro.
public class TethysSDK{
public static native long StartRecording();
public static native long StopRecording();
public static native long SaveRecording (String FileName, String Password, long OverWrite, long CreateFolder);
public static native long RegisterProduct (String UserName, String Key);
public static native long RunMacro (String FileName, String Password, long StopOnEsc, String LogErrorFileName);
static{
System.loadLibrary ("VC_WKSPSDK");
}
public static void main (String [] args){
long RetVal;
String UName = "TrialUsername"; //Trial User Name
String Key = "TrialKey"; // Trial Key
// File Name where the Macros will be saved
String FName = "c:\\MyWKSP.wksp";
String Pass = "MyPassword"; //Password of the Macro.
//Application in which Macros will be recorded
String pExeName = "Excel.exe";
String pTitle = "";
long StopEsc = 1;
//Calling the RegisterProduct function to register the Product
RetVal = RegisterProduct(UName,Key);
if (RetVal == 0){
System.out.println("Register Product Success");
}
else{
System.out.println("Register Product Failed");
}
//Calling the Start Recording function.
RetVal = StartRecording();
if (RetVal == 0){
System.out.println("Start Recording Success");
}
else{
System.out.println("Start Recording Failed");
}
//Calling the StopRecording function.
RetVal = StopRecording();
if (RetVal == 0){
System.out.println("Stop Recording Success");
}
else{
System.out.println("Stop Recording Failed");
}
//Calling the SaveRecording function
RetVal = SaveRecording(FName,Pass,0,0);
if (RetVal == 0){
System.out.println("Recorded File saved at location : " + FName );
}
else{
System.out.println("Save Recording Failed");
}
//Calling the RunMacro function
RetVal = RunMacro(FName,Pass,StopEsc,LogFileName);
if (RetVal == 0){
System.out.println("Run Macro Success");
}
else{
System.out.println("Run Macro Failed");
}
}//Main method ends
}//Class Ends
Step 2: Compile the Java code
Command: javac TethysSDK.java
Step 3: Make a header file of the java code.
Command: javah –jni TethysSDK.java
The above command will make a .h file in the current directory. In this case TethysSDK.h.
Step 4 : Create a VC++ DLL, that calls the Tethys Macro SDK DLL (i.e. WKSPSDK.DLL)
Go to http://www.tethyssolutions.com/Downloads/sdk/Java-VC-Recorder.zip
Download the above link
Extract to a folder, and double click on VC_WKSPSDK.dsw, to open VC++ project file.
Open StdAfx.h file, from the Header files section in the File View tab of VC++
The functions prefixed with JNIEXPORT keyword, are the functions that are being called from Java. i.e. for example if from Java StartRecording function is called, then the function which has a declaration like JNIEXPORT jlong JNICALL Java_WkspRecorder_StartRecording (JNIEnv *env, jclass jc) in StdAfx.h file, is called, and this function in turn calls the StartRecording function from Tethys Macro SDK DLL (i.e WKSPSDK.dll).
Step 5: Copy jni.h, jni_md.h (Both these files are system files that comes with java) and WkspRecorder.h to the folder where the VC++ code exist.
Step 6: Compile the VC++ code. It will create a DLL.
In the IDE of VC++, go to Build menu and click on Clean.
Again in the IDE of VC++, click on Build Menu and then select Build VC_WKSPSDK.dll. It will create a DLL called VC_WKSPSDK.dll.
Step 7: Copy the VC++ DLL either to the System32 folder or to the folder where the java code exist.
Step 8: Compile the Java code
Command: javac TethysSDK.java
Step 9: Execute the Java Code.
Command: java TethysSDK