It is inconvenient to write a database system in C language. You can use the PBNI interface to operate powerbuilder, making it easy to develop databases.
[Cpp]
// Pbtest. cpp: Defines the entry point for the console application.
//
# Include "stdafx. h"
# Include "stdio. h"
Typedef pbxexport pbxresult (* P_PB_GetVM) (IPB_VM ** vm );
Int main (int argc, char * argv [])
{
IPB_Session * session;
IPB_VM * pbvm = NULL; // Load the PowerBuilder VM module
HINSTANCE hinst = LoadLibrary ("pbvm90.dll ");
If (hinst = NULL)
Return 0;
Fprintf (stderr, "Loaded PBVM successfully \ n ");
P_PB_GetVM getvm = (P_PB_GetVM) GetProcAddress (hinst, "PB_GetVM ");
If (getvm = NULL) return 0;
Getvm (& pbvm );
If (pbvm = NULL) return 0;
LPCTSTR LibList [] = {"genapp. dll "};
If (pbvm-> CreateSession ("genapp", LibList, 1, & session )! = PBX_ OK)
{
Fprintf (stderr, "Error in CreateSession \ n ");
Return 1;
}
Fprintf (stderr, "Created session successfully \ n ");
Pbgroup group = session-> FindGroup ("nvo_mult", pbgroup_userobject );
If (group = NULL)
Return 0; // Now find the class nvo_mult in the group
Pbclass cls = session-> FindClass (group, "nvo_mult ");
If (cls = NULL)
Return 0; // Create an instance of the PowerBuilder object
Pbobject pbobj = session-> NewObject (cls );
PBCallInfo ci; // To call the class member function f_mult, // pass its signature as the last argument // to GetMethodID
PbmethodID mid = session-> GetMethodID (cls, "f_mult", PBRT_FUNCTION, "III"); // Initialize call info structure based on method ID
Session-> InitCallInfo (cls, mid, & ci );
Ci. pArgs-> GetAt (0)-> SetInt (10 );
Ci. pArgs-> GetAt (1)-> SetInt (20 );
Try {
Session-> InvokeObjectFunction (pbobj, mid, & ci); // Was PB exception thrown?
If (session-> HasExceptionThrown ())
{// Handle PB exception
Session-> ClearException ();
}
} Catch (...)
{// Handle C ++ exception
} // Get the return value and print it to the console
Pbint ret = ci. returnValue-> GetInt ();
Fprintf (stderr, "The product of 123 and 45 is % I \ n", ret );
Session-> FreeCallInfo (& ci );
// Delete & ci; // Release session
Session-> Release ();
Return 0;
FreeLibrary (hinst );
}