#include "stdafx.h" #include "paxcompilerlib.h" long y = 5; int main(int argc, char* argv[]) { HMODULE h_lib = LoadPaxCompilerLib(); if (h_lib != 0) { DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); DWORD hp = PaxProgram_Create(); PaxCompiler_Reset(hc); PaxCompiler_RegisterLanguage(hc, hl); DWORD h_y = PaxCompiler_RegisterVariable(hc, 0, "Y", PaxTypeLONG); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "procedure ScriptProc(X: Integer);"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " Y := Y + X;"); PaxCompiler_AddCode(hc, "1", "end;"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { DWORD h_ScriptProc = PaxCompiler_GetHandle(hc, 0, "ScriptProc", true); void * p = PaxProgram_GetAddress(hp, h_ScriptProc); // get address of script-defined procedure PaxProgram_SetAddress(hp, h_y, &y); __asm { push 10 // push parameter call p // call script-defined procedure } printf("y = %d", y); } 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); } FreePaxCompilerLib(h_lib); getchar(); return 0; }