#include "stdafx.h" #include "paxcompilerlib.h" DWORD h_show_message; void show_message(char * s) { printf(s); } void create_compiled_script() { DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); DWORD hp = PaxProgram_Create(); PaxCompiler_Reset(hc); PaxCompiler_RegisterLanguage(hc, hl); h_show_message = PaxCompiler_RegisterRoutineEx(hc, 0, "ShowMessage", PaxTypeVOID, ccCDECL); PaxCompiler_RegisterParameter(hc, h_show_message, PaxTypePCHAR, false); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " ShowMessage('Hello');"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { PaxProgram_SaveToFile(hp, "1.bin"); printf("Compiled script has been created!\n"); } else { printf("there are errors:\n"); for (int i = 0; i < PaxCompiler_GetErrorCount(hc); i++) { printf(PaxCompiler_GetErrorMessage(hc, i)); } } PaxProgram_Destroy(hp); PaxPascalLanguage_Destroy(hl); PaxCompiler_Destroy(hc); } void load_compiled_script() { DWORD hp = PaxProgram_Create(); PaxProgram_LoadFromFile(hp, "1.bin"); PaxProgram_SetAddress(hp, h_show_message, &show_message); PaxProgram_Run(hp); PaxProgram_Destroy(hp); } int main(int argc, char* argv[]) { HMODULE h_lib = LoadPaxCompilerLib(); if (h_lib != 0) { create_compiled_script(); printf("Load and run compiled script:\n"); load_compiled_script(); } FreePaxCompilerLib(h_lib); getchar(); return 0; }