C language call powerBuilder Development Database

Source: Internet
Author: User

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 );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.