Listing 1
// load PBVM DLL
HINSTANCE hinst = LoadLibrary("pbvm90.dll");
// get pointer to PB_GetVM function
P_PB_GetVM getvm = (P_PB_GetVM)GetProcAddress(hinst, "PB_GetVM");
IPB_VM* vm = NULL;
getvm(&vm); // call PB_GetVM function
// mypbl.pbl is where the NVO lives
static const char *liblist[] = { "mypbl.pbl" };
IPB_Session* session = NULL;
vm->CreateSession("myapp", liblist, 1, &session); // create a session
PBSessionOwner sessionOwner(session);
// find the group for the NVO
pbgroup group = session->FindGroup("mynvo", pbgroup_userobject);
// find the NVO class
pbclass cls = session->FindClass(group, "mynvo");
// get the method ID
pbmethodID mid = session->GetMethodID(cls, "foo", PBRT_FUNCTION, "IS");
// create an instance of the NVO
pbobject obj = session->NewObject(cls);
PBObjectUser objUser(session, &obj);
PBCallInfo ci(session);
session->InitCallInfo(cls, mid, &ci);
ci.pArgs->GetAt(O)->.SetString("call foo");
session->InvokeObjectFunction(obj, mid, &ci); // call the function
pbint returnValue = ci.returnValue->getInt();
cout << "return value: " << returnValue << endl;
// call the function again with different parameter
ci.pArgs->GetAt(O)->.SetString("call foo for the second time");
session->InvokeObjectFunction(obj, mid, &ci);
returnValue = ci.returnValue->getInt();
cout << "return value: " << returnValue << endl;
FreeLibrary(hinst);