Sybase PB12.5PBNI Programmers
Sybase PB12.5PBNI Programmers
PowerBuilder® Classic
12.5
DOCUMENT ID: DC37794-01-1250-01
To order additional documents, U.S. and Canadian customers should call Customer Fulfillment at (800) 685-8225, fax (617) 229-9845.
Customers in other countries with a U.S. license agreement may contact Customer Fulfillment via the above fax number. All other
international customers should contact their Sybase subsidiary or local distributor. Upgrades are provided only at regularly scheduled
software release dates. No part of this publication may be reproduced, transmitted, or translated in any form or by any means, electronic,
mechanical, manual, optical, or otherwise, without the prior written permission of Sybase, Inc.
Sybase trademarks can be viewed at the Sybase trademarks page at http://www.sybase.com/detail?id=1011207. Sybase and the marks listed
are trademarks of Sybase, Inc. ® indicates registration in the United States of America.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of
SAP AG in Germany and in several other countries all over the world.
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Unicode and the Unicode Logo are registered trademarks of Unicode, Inc.
All other company and product names mentioned may be trademarks of the respective companies with which they are associated.
Use, duplication, or disclosure by the government is subject to the restrictions set forth in subparagraph (c)(1)(ii) of DFARS 52.227-7013
for the DOD and as set forth in FAR 52.227-19(a)-(d) for civilian agencies.
PART 2 REFERENCE
GetClass................................................................................ 125
GetClassName ...................................................................... 126
GetCurrGroup........................................................................ 126
GetDateString........................................................................ 127
GetDateTimeString................................................................ 127
GetDecimalString .................................................................. 128
GetEnumItemName............................................................... 128
GetEnumItemValue ............................................................... 129
GetException......................................................................... 130
GetFieldID ............................................................................. 130
GetFieldName ....................................................................... 131
GetFieldType......................................................................... 132
GetGlobalVarID ..................................................................... 132
GetGlobalVarType................................................................. 133
GetMarshaler......................................................................... 134
GetMethodID ......................................................................... 135
GetMethodIDByEventID ........................................................ 136
GetNativeInterface ................................................................ 137
GetNumOfFields.................................................................... 138
GetPBAnyArrayItem .............................................................. 138
GetPBAnyField...................................................................... 139
GetPBAnyGlobalVar.............................................................. 141
GetPBAnySharedVar ............................................................ 141
GetProp ................................................................................. 142
GetResultSetAccessor .......................................................... 142
GetSharedVarID.................................................................... 143
GetSharedVarType ............................................................... 144
GetString ............................................................................... 145
GetStringLength .................................................................... 146
GetSuperClass ...................................................................... 146
GetSystemClass.................................................................... 147
GetSystemGroup................................................................... 147
GetTimeString ....................................................................... 148
HasExceptionThrown ............................................................ 148
HasPBVisualObject ............................................................... 149
InitCallInfo ............................................................................. 150
InvokeClassFunction ............................................................. 151
InvokeObjectFunction............................................................ 152
IsArrayItemNull...................................................................... 153
IsAutoInstantiate.................................................................... 153
IsFieldArray ........................................................................... 153
IsFieldNull.............................................................................. 154
IsFieldObject ......................................................................... 155
IsGlobalVarArray ................................................................... 155
SetFieldToNull....................................................................... 190
SetGlobalVarToNull............................................................... 190
SetMarshaler ......................................................................... 191
SetProp ................................................................................. 192
SetSharedVarToNull ............................................................. 194
SetString................................................................................ 194
SetTime ................................................................................. 196
SetValue................................................................................ 197
SplitDate................................................................................ 197
SplitDateTime........................................................................ 198
SplitTime ............................................................................... 198
ThrowException..................................................................... 199
TriggerEvent.......................................................................... 200
UpdateField ........................................................................... 201
IPB_Value interface ..................................................................... 202
Get<type>.............................................................................. 203
GetClass................................................................................ 204
GetType................................................................................. 204
IsArray ................................................................................... 205
IsByRef.................................................................................. 205
IsEnum .................................................................................. 206
IsNull ..................................................................................... 206
IsObject ................................................................................. 207
Set<type> .............................................................................. 208
SetToNull............................................................................... 210
IPB_VM interface ......................................................................... 211
CreateSession....................................................................... 211
RunApplication ...................................................................... 213
IPBX_Marshaler interface ............................................................ 215
Destroy .................................................................................. 215
GetModuleHandle ................................................................. 216
InvokeRemoteMethod ........................................................... 217
IPBX_NonVisualObject interface ................................................. 218
IPBX_UserObject interface .......................................................... 219
Destroy .................................................................................. 219
Invoke.................................................................................... 220
IPBX_VisualObject interface ........................................................ 221
CreateControl ........................................................................ 221
GetEventID............................................................................ 223
GetWindowClassName ......................................................... 225
PBArrayInfo structure ................................................................... 226
PBCallInfo structure ..................................................................... 226
PB_DateData structure ................................................................ 227
PB_DateTimeData structure ........................................................ 227
PART 3 APPENDIX
Audience This book is for C++ programmers who will use the PowerBuilder®
Native Interface (PBNI) to build PowerBuilder extensions. The book
assumes that you are familar with the C++ language and a C++
development tool.
Related documents This book contains information about building PowerBuilder extensions.
The PowerBuilder Extension Reference contains information about using
extensions that are provided with PowerBuilder.
Other sources of Use the Sybase® Getting Started CD and the Sybase Product
information Documentation Web site to learn more about your product:
• The Getting Started CD contains release bulletins and installation
guides in PDF format. It is included with your software. To read or
print documents on the Getting Started CD, you need Adobe Acrobat
Reader, which you can download at no charge from the Adobe Web
site using a link provided on the CD.
• The Sybase Product Documentation Web site is accessible using a
standard Web browser. In addition to product documentation, you
will find links to EBFs/Maintenance, Technical Documents, Case
Management, Solved Cases, newsgroups, and the Sybase Developer
Network.
To access the Sybase Product Documentation Web site, go to Product
Documentation at http://www.sybase.com/support/manuals/.
Conventions The formatting conventions used in this manual are:
Formatting example To indicate
Retrieve and Update When used in descriptive text, this font indicates:
• Command, function, and method names
• Keywords such as true, false, and null
• Datatypes such as integer and char
• Database column names such as emp_id and
f_name
• User-defined objects such as dw_emp or
w_main
If you need help Each Sybase installation that has purchased a support contract has one or more
designated people who are authorized to contact Sybase Technical Support. If
you cannot resolve a problem using the documentation or online help, please
have the designated person contact Sybase Technical Support or the Sybase
subsidiary in your area.
About this chapter This chapter provides a brief introduction to the PowerBuilder Native
Interface.
Contents
Topic Page
About PBNI 3
The elements of PBNI 6
The PBNI SDK 8
Comparing PBNI and JNI 10
About PBNI
PBNI is a standard programming interface that enables developers to
extend the functionality of PowerBuilder. Using PBNI, you can create
extensions to PowerBuilder—nonvisual, visual, and marshaler
extensions—and embed the PowerBuilder virtual machine (PBVM) into
C++ applications. Through the Java Native Interface (JNI) and PBNI,
Java applications can also communicate with the PBVM.
Code samples
This documentation contains two complete but very simple examples that
illustrate some basic principles of using the PowerBuilder Native
Interface (PBNI): “Nonvisual extension example” on page 11 and
“Creating a PowerBuilder object to be called from C++” on page 66. For
more real-world examples, see the PBNI section of the PowerBuilder
CodeXchange Web site at http://powerbuilder.codeXchange.sybase.com/.
4 PowerBuilder Classic
CHAPTER 1 Introduction to PBNI
Marshaler extensions Marshaler extensions act as bridges between PowerBuilder and other
components, such as Enterprise JavaBeans (EJB) components, Java classes,
Web services, and CORBA components. PowerBuilder provides a marshaler
extension for creating clients for EJB components running in any
J2EE-compliant application server. Other techniques for calling EJBs from
PowerBuilder do not provide a standard way to marshal PowerBuilder requests
to other components and unmarshal the result back to PowerBuilder.
6 PowerBuilder Classic
CHAPTER 1 Introduction to PBNI
Interaction between The following diagram summarizes how an extension interacts with the
an extension and the PBVM.
PBVM
Figure 1-2: Interaction between an extension and the PowerBuilder VM
8 PowerBuilder Classic
CHAPTER 1 Introduction to PBNI
Component Description
include\pbfield.h A header file that contains helper classes that make it
easier to access data in fields.
include\pbtraits.h A header file used by pbarray.h and pbfield.h that provides
specializations for the pbvalue_type enumerated types.
include\pbext.h A header file that defines the functions that PowerBuilder
extension functions must export.
include\pbevtid.h A header file that maps the PowerBuilder event IDs to
event names for use in visual extensions.
include\pbnimd.h A header file that defines machine-dependent datatypes
used in pbni.h.
include\pbrsa.h A header file that defines interfaces and structures used to
access DataWindow and DataStore data.
src\pbarray.cpp A source file that must be added to your project if you want
to use the following helper classes defined in pbarray.h:
PBArrayAccessor
PBObjectArrayAccessor
PBBoundedArrayCreator
PBBoundedObjectArrayCreator
PBUnboundedArrayCreator
PBUnboundedObjectArrayCreator
src\pbfuninv.cpp A source file that must be added to your project if you want
to use the following helper classes defined in pbni.h:
PBGlobalFunctionInvoker
PBObjectFunctionInvoker
PBEventTrigger
src\pbobject.cpp A source file that must be added to your project if you want
to use the following helper class defined in pbni.h:
PBObjectCreator.
wizards\VCProjects 8.0 A Microsoft Visual Studio 2005 wizard that makes it easier
for you to create PBNI projects.
wizards\VCProjects 7.1 A Microsoft Visual Studio .NET 2003 wizard that makes it
easier for you to create PBNI projects.
wizards\VCProjects 7.0 A Microsoft Visual Studio .NET 2002 wizard that makes it
easier for you to create PBNI projects.
wizards\VCWizards Files required by the Visual Studio wizards.
pbni125.hlp, Help files for PBNI.
pbni125.cnt
10 PowerBuilder Classic
CH A PTE R 2 Building PowerBuilder
Extensions
About this chapter This chapter describes how to build a PowerBuilder extension. It begins
with a sample application that uses a simple nonvisual extension.
Contents
Topic Page
Nonvisual extension example 11
Creating a PowerBuilder extension 17
Adding an extension to a PowerBuilder target 26
Using the extension 27
Creating and using a visual extension 28
Creating visual class instances 31
Event processing in visual extensions 34
Calling PowerScript from an extension 39
Exception handling and debugging 43
For more realistic examples, see the PowerBuilder CodeXchange Web site
at http://powerbuilder.codexchange.sybase.com.
12 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
private:
virtual void Destroy();
};
2 Create the main.cpp file, which includes pbadd.h and implements the
standard functions, PBX_GetDescription and PBX_CreateNonvisualObject:.
• PBX_GetDescription is used to pass the descriptions of classes in the
extension to PowerBuilder.
• The PBX_CreateNonVisualObject method creates the object instance.
The PowerScript CREATE statement maps to this PBNI method.
The following is the code for main.cpp:
#include "pbadd.h"
// initialize the PBX
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_all,
LPVOID lpReserved
)
{
switch(ul_reason_for_all)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
14 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
4 In the System Tree, expand the new target, right-click the library, and
select Import PB Extension from the pop-up menu.
16 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
For every native class, you must implement two PBNI methods, Invoke and
Destroy, in addition to the methods the class will provide. The use of these
PBNI methods is described in “Step 4: Implement native classes and global
functions” on page 22.
18 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
Describing nonvisual Nonvisual classes can inherit from the NonVisualObject PowerBuilder system
classes class or any of its descendants. While a native class can inherit from a
user-defined user object, Sybase recommends that you use only system classes.
Each native class can provide several functions, subroutines, and events.
The following example shows how you use the PBX_GetDescription method in
the C++ code for an extension that includes three nonvisual classes.
ClassName1 inherits from NonVisualObject, ClassName2 inherits from
Exception, and ClassName3 inherits from Transaction. All three classes must
be in a single description passed by PBX_GetDescription:
PBXEXPORT LPCTSTR PBXCALL PBX_GetDescription()
{
static const TCHAR desc[] = {
// Description begins here
"class ClassName1 from NonVisualObject\n"
"function integer objectFunction(integer a[])\n"
"subroutine objectSubroutine(integer ai_ref)\n"
"event integer eventName(integer b)\n"
"end class\n"
Describing global An extension can include global functions as well as classes. This example
functions shows a description for two global functions:
"globalfunctions \n" \
"function int g_1(int a, int b)\n" \
"function long g_2(long a, long b)\n" \
"end globalfunctions\n"
The syntax and usage of global functions defined in an extension are the same
as for global functions defined in the Function painter in PowerBuilder.
Using forward PowerBuilder extensions can provide multiple classes. A class can reference
declarations any class that is defined earlier in the description, but if it references a class
defined later in the description, you must provide a forward declaration. This
example shows a description that includes forward declarations for two classes,
nativeclass_1 and nativeclass_2, that reference each other. This example also
demonstrates that a single description can include global functions as well as
classes:
"forward\n" \
"class nativeclass_1 from nonvisualobject\n"\
"class nativeclass_2 from nonvisualobject\n"\
"end forward\n" \
"globalfunctions \n" \
"function int g_1(int a, int b)\n" \
"function long g_2(long a, long b)\n" \
"end globalfunctions\n"
20 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
// member methods
PBXRESULT Invoke(
IPB_Session *session,
pbobject obj,
pbmethodID mid,
PBCallInfo *ci
);
void Destroy();
private:
void funcA(IPB_Session* session, pbobject obj,
PBCallInfo* ci);
void funcB(IPB_Session* session, pbobject obj,
PBCallInfo* ci);
};
If you declare global functions in your extension, the extension must export the
PBX_InvokeGlobalFunction method. The following PBX_GetDescription call
declares three global functions: bitAnd, bitOr, and bitXor:
PBXEXPORT LPCTSTR PBXCALL PBX_GetDescription()
{
static const TCHAR desc[] = {
"globalfunctions\n"
"function int bitAnd(int a, int b)\n"
"function int bitOr(int a, int b)\n"
"function int bitXor(int a, int b)\n"
"end globalfunctions\n"
};
return desc;
}
When the PowerBuilder application calls a method on the native class, the
PBVM calls the Invoke method, which dispatches the call based on the method
ID or method name. The method name is used when the method is called
dynamically.
The Invoke method must be coded to invoke each method in the class. The
example that follows shows a switch-case statement that invokes either funcA
or funcB, depending on the value of the method ID. When the PowerBuilder
application has finished using an instance of a native class, the PBVM calls the
Destroy method.
22 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
This example does not show the implementation of the methods of the class
itself:
PBXRESULT MyClass::Invoke(IPB_Session *session,
pbobject obj, pbmethodID mid, PBCallInfo *ci)
{
PBXRESULT result = PBX_OK;
switch (mid)
{
case mFunca:
result = funcA(session, obj, ci);
break;
case mFuncb:
result = funcB(session, obj, ci);
break;
default:
result = PBX_E_INVOKE_FAILURE;
break;
}
return result;
}
// Implementation of funcA and funcB not shown
void Destroy()
{
delete this;
}
if (stricmp(functionName, "bitand") == 0)
{
ci->returnValue->SetInt(arg1 & arg2);
}else if (strcmp(functionName, "bitor") == 0)
{
ci->returnValue->SetInt(arg1 | arg2);
}else if (strcmp(functionName, "bitxor") == 0)
{
ci->returnValue->SetInt(arg1 ^ arg2);
}else
{
return PBX_FAIL;
}
return pbrResult;
}
24 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
26 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
28 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
return desc;
}
There are no events in the preceding example, but a typical visual extension
makes use of events such as mouse clicks. There are two ways to declare and
handle events. See “Event processing in visual extensions” on page 34.
Code samples
The code fragments in the rest of this section are based on complete sample
applications that you can find on the PowerBuilder CodeXchange Web site at
http://powerbuilder.codexchange.sybase.com.
30 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
string cn(className);
if (cn.compare("visualext") == 0)
{
*obj = new CVisualExt(pbsession, pbobj);
}
else
{
*obj = NULL;
result = PBX_FAIL;
}
return PBX_OK;
};
Registering the Before CreateControl can be called, the window class must be registered. This
window class code uses the Windows RegisterClass method to register the window class with
the class name s_className:
void CVisualExt::RegisterClass()
{
WNDCLASS wndclass;
::RegisterClass (&wndclass);
}
You must also implement the Windows UnregisterClass method to unregister
the class when the window is closed:
void CVisualExt::UnregisterClass()
{
::UnregisterClass(s_className, g_dll_hModule);
}
The RegisterClass and UnregisterClass methods are called in the initialization
code for the PBX. This is the Visual C++ DllMain method:
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD reasonForCall,
LPVOID lpReserved
)
{
g_dll_hModule = (HMODULE)hModule;
switch (reasonForCall)
{
case DLL_PROCESS_ATTACH:
CVisualExt::RegisterClass();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
32 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
break;
case DLL_PROCESS_DETACH:
CVisualExt::UnregisterClass();
break;
}
return TRUE;
}
Implementing Every visual native class must implement the IPBX_VisualObject
CreateControl CreateControl method. After getting the class name with the
IPBX_VisualObject GetClassName method, CreateControl passes the class
name to the Windows CreateWindowEx method to create the window, then
returns the window handle to the PBVM:
TCHAR CVisualExt::s_className[] = "PBVisualExt";
LPCTSTR CVisualExt::GetWindowClassName()
{
return s_className;
}
HWND CVisualExt::CreateControl
(
DWORD dwExStyle, // extended window style
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or
// owner window
HINSTANCE hInstance // handle to application
// instance
)
{
d_hwnd = CreateWindowEx(dwExStyle, s_className,
lpWindowName, dwStyle, x, y, nWidth, nHeight,
hWndParent, NULL, hInstance, NULL);
34 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
Capturing messages The code in the extension captures the Windows messages that cause the
and mouse clicks window to be drawn, as well as mouse clicks and double clicks:
LRESULT CALLBACK CVisualExt::WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
CVisualExt* ext = (CVisualExt*)::GetWindowLong(hwnd,
GWL_USERDATA);
switch(uMsg) {
case WM_CREATE:
return 0;
case WM_SIZE:
return 0;
case WM_COMMAND:
return 0;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
RECT rc;
GetClientRect(hwnd, &rc);
LOGBRUSH lb;
lb.lbStyle = BS_SOLID;
}
return 0;
case WM_LBUTTONDBLCLK:
ext->TriggerEvent("ondoubleclick");
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Triggering click events The following is the TriggerEvent method that triggers the Onclick and
Ondoubleclick events:
void CVisualExt::TriggerEvent(LPCTSTR eventName)
{
pbclass clz = d_session->GetClass(d_pbobj);
pbmethodID mid = d_session->GetMethodID(clz,
eventName, PBRT_EVENT, "I");
PBCallInfo ci;
d_session->InitCallInfo(clz, mid, &ci);
d_session->TriggerEvent(d_pbobj, mid, &ci);
d_session->FreeCallInfo(&ci);
}
36 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
LPCTSTR CVisualExt::GetWindowClassName()
{
return s_className;
}
HWND CVisualExt::CreateControl
(
DWORD dwExStyle, // extended window style
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle of parent or owner window
HINSTANCE hInstance // handle of application instance
)
{
d_hwnd = CreateWindowEx(dwExStyle, s_className,
lpWindowName, dwStyle, x, y, nWidth, nHeight,
hWndParent, NULL, hInstance, NULL);
return d_hwnd;
}
38 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
int CVisualExt::GetEventID(
HWND hWnd, /* Handle of parent window */
UINT iMsg, /* Message sent to parent window*/
WPARAM wParam, /* Word parameter of message*/
LPARAM lParam /* Long parameter of message*/
)
{
if (iMsg == WM_COMMAND)
{
if ((HWND)lParam == d_hwnd)
{
switch(HIWORD(wParam))
{
case BN_CLICKED:
return PB_BNCLICKED;
break;
}
}
}
if (iMsg == WM_NOTIFY)
{
return PB_ENCHANGE;
}
return PB_NULL;
}
For methods in your application, you can expand the object that contains it in
the System Tree, select the function or event, and select Properties from its
pop-up menu:
40 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
PBCallInfo ci;
ud->session->InitCallInfo(clz, mid, &ci);
ud->session->FreeCallInfo(&ci);
return ret == 1 ? TRUE : FALSE;
}
42 PowerBuilder Classic
CHAPTER 2 Building PowerBuilder Extensions
Debugging You cannot edit a native class in the PowerBuilder development environment,
and you cannot enter native methods in the PowerBuilder debugger because the
methods are C++ methods. You must use a C/C++ debugger to debug an
extension module.
44 PowerBuilder Classic
CH A PTE R 3 Creating Marshaler Extensions
About this chapter This chapter describes how to create marshaler extensions.
Contents
Topic Page
About marshaler extensions 45
Developing the PowerBuilder extension 46
Generating proxies for Java classes 53
Calling the Java class from PowerBuilder 54
46 PowerBuilder Classic
CHAPTER 3 Creating Marshaler Extensions
When a function of the proxy object is called in PowerScript, the PBVM calls
the InvokeRemoteMethod function on the marshaler object through the proxy
(1, 2). The marshaler object translates PowerBuilder function calls into
requests that the foreign component understands, sends the requests (3), waits
for a response, and send the results back to PowerBuilder (4).
Figure 3-2: Invoking a remote method
{
pbstring jcn = ci->pArgs->GetAt(1)->GetPBString();
if (jcn == NULL)
{
ci->returnValue->SetLong(kInvalidJavaClassName);
return PBX_OK;
}
48 PowerBuilder Classic
CHAPTER 3 Creating Marshaler Extensions
else
{
jclassName = session->GetString(jcn);
}
}
if (jcls != NULL)
{
JLocalRef lrClz(env, jcls);
{
pbstring pn = ci->pArgs->GetAt(2)->GetPBString();
if (pn == NULL)
{
ci->returnValue->SetLong(kInvalidProxyName);
return PBX_OK;
}
else
{
proxyName = session->GetString(pn);
}
}
// Create JavaMarshaler
JavaMarshaler* marshaler = new JavaMarshaler(env,
proxy, jobj);
ci->pArgs->GetAt(0)->SetObject(proxy);
ci->returnValue->SetLong(kSuccessful);
return PBX_OK;
}
50 PowerBuilder Classic
CHAPTER 3 Creating Marshaler Extensions
public:
JavaMarshaler(JNIEnv* env, pbproxyObject pbobj,
jobject ejbobj);
~JavaMarshaler();
pbulong JavaMarshaler::GetModuleHandle()
{
return g_dll_hModule;
}
//****************************************************
// JavaMarshaler
//****************************************************
JavaMarshaler::JavaMarshaler
(
JNIEnv* env,
pbproxyObject pbobj,
jobject ejbobj
)
: d_jobject(env->NewGlobalRef(ejbobj)),
d_pbobject(pbobj)
{
}
JavaMarshaler::~JavaMarshaler()
{
JNIEnv* env = JavaVMWrapper::instance()->getEnv();
PBXRESULT JavaMarshaler::InvokeRemoteMethod
(
IPB_Session* session,
pbproxyObject obj,
LPCSTR szMethodDesc,
PBCallInfo* ci
)
{
static char* eFailedToInvokeJavaMethod =
"Failed to invoke the Java method.";
try
{
if (d_jobject != NULL)
{
method.invoke(session, env, d_jobject, ci);
if (env->ExceptionCheck() == JNI_TRUE)
{
string error(eFailedToInvokeJavaMethod);
error += "\n";
// Throw exception here
52 PowerBuilder Classic
CHAPTER 3 Creating Marshaler Extensions
return PBX_E_INVALID_ARGUMENT;
}
}
}
catch(...)
{
}
return PBX_OK;
}
void JavaMarshaler::Destroy()
{
delete this;
}
forward prototypes
public:
function double dollarToYen(double ad_1) alias
for "dollarToYen,(D)D"
54 PowerBuilder Classic
CH A PTE R 4 Exchanging Data with
PowerBuilder
About this chapter This chapter describes how PBNI extensions exchange data with
PowerBuilder.
Contents
Topic Page
About exchanging data with PowerBuilder 55
Passing values between extensions and the PBVM 55
Using the IPB_Session interface 59
Saving data from IPB_Value to a local variable 61
Using variables throughout a session 63
Handling enumerated types 64
PBCallInfo structure
The PBCallInfo structure is used to hold data and return type information for
calls between extensions and the PBVM. It has three public members:
IPB_Arguments* pArgs;
IPB_Value* returnValue;
pbclass returnClass;
The following code initializes a PBCallInfo structure using the IPB_Session
InitCallInfo method. After allocating a PBCallInfo structure called ci, the
IPB_Session GetClass and GetMethodID methods are used to get the class and
method ID of the current method. Then, these parameters are used to initialize
the ci structure:
pbclass cls;
pbmethodID mid;
PBCallInfo* ci = new PBCallInfo;
IPB_Arguments interface
The IPB_Arguments interface has two methods:
• GetCount obtains the number of arguments in a method call.
• GetAt obtains the value at a specific index of the pArgs member of the
PBCallInfo structure. For each argument, GetAt returns a pointer to the
IPB_Value interface.
56 PowerBuilder Classic
CHAPTER 4 Exchanging Data with PowerBuilder
The following code fragment uses GetCount and GetAt in a FOR loop to process
different argument types. The ci-> pArgs -> GetCount()statement gets the
number of arguments, and ci -> pArgs -> GetAt(i) gets the value at the
index i. This value is a pointer to the IPB_Value interface on which IPB_Value
methods, such as IsArray and GetArray, can be called (see "IPB_Value
interface" next) :
int i;
for (i=0; i < ci-> pArgs -> GetCount();i++)
{
pbuint ArgsType;
if( ci -> pArgs -> GetAt(i) -> IsArray())
pArguments[i].array_val =
ci -> pArgs -> GetAt(i) -> GetArray();
continue;
}
IPB_Value interface
IPB_Value has three sets of methods: helper methods, set methods, and get
methods.
Helper methods The IPB_Value interface helper methods provide access to information about
variables and arguments, including the value’s class and type, whether it is an
array or simple type, whether it is set by reference, and whether the null flag is
set. There is also a method that sets the value to null:
virtual pbclass GetClass() const = 0;
virtual pbint GetType() const = 0;
virtual pbboolean IsArray() const = 0;
virtual pbboolean IsObject() const = 0;
virtual pbboolean IsByRef() const = 0;
virtual pbboolean IsNull() const = 0;
virtual PBXRESULT SetToNull() = 0;
This example shows how you can use the SetToNull method to set the
returnValue member of the PBCallInfo structure to null:
if ( ci->pArgs->GetAt(0)->IsNull() ||
ci->pArgs->GetAt(1)->IsNull() )
{
// if either of the passed arguments is null,
// return the null value
ci->returnValue->SetToNull();
Set methods The IPB_Value set methods set values in the PBCallInfo structure. There is a
set method for each PowerBuilder datatype: SetInt, SetUint, SetLong, SetUlong,
and so on. These methods automatically set the value represented by
IPB_Value to not null. The syntax is:
virtual PBXRESULT Set<type>(<pbtype> arg);
For example, the SetLong method takes an argument of type pblong.
In this example, the method has two integer arguments, set to int_val1 and
int_val2:
ci-> pArgs -> GetAt(0) -> SetInt(int_val1);
ci-> pArgs -> GetAt(1) -> SetInt(int_val2);
The IPB_Value set methods set the datatype of the value represented by
IPB_Value to a specific type. If the original type of the value is any, you can
set it to any other type. Then, because the value now has a specific type, setting
it to another type later returns the error PBX_E_MISMATCHED_DATA_TYPE. If
the argument is readonly, the error PBX_E_READONLY_ARGS is returned.
Get methods The IPB_Value get methods obtain values from the PBCallInfo structure.
There is a get method for each PowerBuilder datatype: GetInt, GetUint,
GetLong, GetUlong, and so on.The syntax is:
virtual <pbtype> Get<type>( );
For example, the GetString method returns a value of type pbstring.
The following example uses the IPB_Value GetAt method to assign the value
at the first index of the pArgs member of the PBCallInfo structure to a variable
of type IPB_Value* called pArg. If pArg is not null, the GetLong method sets
the variable longval to the value in pArg:
PBCallInfo *ci
...
58 PowerBuilder Classic
CHAPTER 4 Exchanging Data with PowerBuilder
if (!pArg->IsNull())
longval = pArg -> GetLong();
If the value is null, or if you use a get method that is expected to return one
datatype when the value is a different datatype (such as using GetLong when
the datatype is pbarray), the result returned is undetermined.
The get methods can also be used with the returnValue member of PBCallInfo:
ret_val = ci.returnValue->GetInt();
return ret_val;
if (isNull[0])
ci -> pArgs -> GetAt(0)->SetToNull();
else
ci-> pArgs -> GetAt(0) ->SetDate(*d_date);
Session->SplitDate(ci->pArgs->GetAt(0)->GetDate(),
&yy,&mm,&dd);
Session->SetDate(*d_date, yy, mm, dd);
60 PowerBuilder Classic
CHAPTER 4 Exchanging Data with PowerBuilder
Saving pointer values A pointer value does not contain data. It contains a pointer to a memory
location where the data is stored. When you call one of the IPB_Value
Get<type> methods for a pointer value, such as GetBlob or GetTime, it returns
a pointer to memory that is also pointed to by IPB_Value.
When you call FreeCallInfo, the memory to which IPB_Value points is released
and the data is deleted. Because this is the same data pointed to by the pointer
returned by the Get<type> method, that pointer can no longer be used to
represent the data.
This applies to the following pointer value datatypes, as well as to the pbarray
datatype:
pbvalue_dec
pbvalue_string
pbvalue_blob
pbvalue_date
pbvalue_time
pbvalue_datetime
If you want to save the data in a pointer value, you can use the AcquireValue,
AcquireArrayItemValue, and ReleaseValue methods to acquire and release the
data.These methods clone a new IPB_Value that is not freed until you call
ReleaseValue and reset the existing IPB_Value pointer.
The original value is reset to zero or null, so it can no longer be used. Attempts
to get or acquire the original value return zero or null until another IPB_Value
is set to the value.
If the IPB_Value acquired using AcquireValue is an array, the entire array is
acquired. To acquire only an element of the array, use AcquireArrayItemValue.
When you have finished using the data, you must free the memory using the
ReleaseValue method.
Caution
You must call the ReleaseValue method to free the data. If you do not do so, a
memory leak will occur. You must not call ReleaseValue to release a pointer
that was not acquired using AcquireValue and AcquireArrayItemValue. Doing so
might cause the PBVM to crash.
62 PowerBuilder Classic
CHAPTER 4 Exchanging Data with PowerBuilder
Saving object values Strictly speaking, object values are also pointer values, but the PBVM handles
them differently. You use the IPB_Session AddLocalRef and AddGlobalRef
methods to add a reference to the object. If there is a reference to an object, it
is not deleted when FreeCallInfo is called.
When you no longer need the object, call RemoveLocalRef or
RemoveGlobalRef to decrease the reference count for the object. If the
reference count is decreased to zero, the object is deleted automatically.
There is an important difference between AddLocalRef and AddGlobalRef. A
reference added by AddLocalRef can be deleted automatically when the local
frame is popped up. The local frame can be popped by calling PopLocalFrame
or when the current function returns. However, a reference added by
AddGlobalRef is deleted only when RemoveGlobalRef is called or the session
ends.
You must use these methods in pairs; that is, use RemoveLocalRef to remove
references created with AddLocalRef, and use RemoveGlobalRef to remove
references created with AddGlobalRef.
One way to set the value of the fields of the exception before the function
returns in a thread-safe manner is to create a new object or structure to hold the
exception information before calling NewObject. You can call SetProp to store
the structure or the object in the current IPB_Session. When
PBX_CreateNonVisualObject is called, you can call GetProp to get the structure
or object to obtain the exception information, then call RemoveProp to remove
the data you stored in the current session.
You can also use these functions when initializing and uninitializing a session.
If the extension exports the PBX_NOTIFY function, the PBVM calls PBX_Notify
immediately after an extension PBX is loaded and just before the PBX is
unloaded. You can use this function to initialize and uninitialize a session. For
example, you could create a session manager object, and store it in the IPB
session using the SetProp function. Later, you could use GetProp to obtain the
session object.
64 PowerBuilder Classic
CH A PTE R 5 Calling PowerBuilder from C++
About this chapter A third-party application or server written in C++ can load the
PowerBuilder VM, use PowerBuilder nonvisual objects, and use
PowerBuilder visual controls. This chapter uses some simple examples to
illustrate the process.
Contents
Topic Page
About calling PowerScript from C++ applications 65
Calling PowerBuilder objects from C++ 66
Accessing result sets 72
Processing PowerBuilder messages in C++ 73
More PBNI possibilities 78
The following figure illustrates the relationship between the C++ application
and the interfaces provided by the PBVM.
Figure 5-1: Embedding the PBVM in a C++ application
66 PowerBuilder Classic
CHAPTER 5 Calling PowerBuilder from C++
Getting a signature To get the signature of f_mult with pbsig125, type the following at a command
using pbsig125 prompt:
pbsig125 d:\pbls\loadpbvm.pbl
In the output of pbsig125, the comment on the last line contains the signature
to be passed as the method ID argument to GetMethodID:
PB Object Name: loadpbvm
68 PowerBuilder Classic
CHAPTER 5 Calling PowerBuilder from C++
The code for the C++ application creates an IPB_VM object using the
PB_GetVM function and loads the PowerBuilder VM:
#include "pbext.h"
#include "stdio.h"
getvm(&pbvm);
if (pbvm == NULL) return 0;
70 PowerBuilder Classic
CHAPTER 5 Calling PowerBuilder from C++
// Release session
session->Release();
return 0;
FreeLibrary(hinst);
}
72 PowerBuilder Classic
CHAPTER 5 Calling PowerBuilder from C++
ProcessPBMessage You need to make sure that the ProcessPBMessage function is called
must be called repeatedly. For most C++ applications, you can provide a message loop in the
repeatedly
main function and insert the IPB_Session ProcessPBMessage function in the
message loop. This is shown in the example that follows.
If you use Microsoft Foundation Classes (MFC), you cannot modify the
built-in message loop. To ensure that the ProcessPBMessage function is called
repeatedly, you can overload the CWnd::WindowProc function and insert
ProcessPBMessage into the overloaded function:
Examples
The following code fragments are from a C++ program that opens a window.
The window has a menu item that invokes the Open event of a PowerBuilder
application.
WNDCLASSEX wcex;
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
try
{
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
// Call to ProcessPBMessage
if (session)
session->ProcessPBMessage();
}
}
catch(...)
{
MessageBox(NULL, "Exception occurs",
"Exception", MB_OK);
}
return msg.wParam;
}
74 PowerBuilder Classic
CHAPTER 5 Calling PowerBuilder from C++
Loading the PBVM In the WndProc function, when the WM_CREATE message is passed, the
and triggering an PBVM is loaded and the library list, containing openwin.pbl, is passed to
event
CreateSession. When the user selects the menu item that opens the
PowerBuilder window, the FindGroup, FindClass, and GetMethodID functions
obtain the information needed to create a new application object, initialize the
PBCallInfo structure, and trigger the application object’s Open event:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE:
{
// Load the PBVM
hPBVMInst = ::LoadLibrary("pbvm125.dll");
P_PB_GetVM getvm = (P_PB_GetVM)
GetProcAddress(hPBVMInst,"PB_GetVM");
IPB_VM* vm = NULL;
getvm(&vm);
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_PB_VISUAL:
{
// Initialize PBCallInfo and trigger the
// application open event
try
{
pbgroup group = session->FindGroup
("openwin", pbgroup_application);
PBCallInfo ci;
session->InitCallInfo(cls, mid, &ci);
session->TriggerEvent(obj, mid, &ci);
session->FreeCallInfo(&ci);
}
catch(...)
{
MessageBox(NULL, "Exception occurs",
"Exception", MB_OK);
}
break;
}
default:
return DefWindowProc(hWnd, message, wParam,
lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
session->Release();
session = NULL;
FreeLibrary(hPBVMInst);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam,
lParam);
}
return 0;
}
76 PowerBuilder Classic
CHAPTER 5 Calling PowerBuilder from C++
Testing You can test the ProcessPBMessage function with a simple PowerBuilder
ProcessPBMessage application like this one:
1 Create a PowerBuilder application called openwin in openwin.pbl.
2 Create a main window, w_main, with three buttons.
3 Insert a window-level function, of_setcolor, that takes three integers as
arguments and has this script:
this.backcolor = rgb(red,green,blue)
4 Insert a window-level user event, ue_test, with this script:
MessageBox("ue_test", "This is a user event")
5 Provide the following scripts for the clicked events of the buttons:
//cb_1:
MessageBox("Button 1", "Clicked")
parent.of_setcolor(255, 255, 0)
//cb_2:
MessageBox("Button 2", "Clicked")
parent.PostEvent("ue_event") // not fired
parent.of_setcolor(255, 0, 0)
//cb_3:
MessageBox("Button 3", "Clicked")
cb_1.PostEvent(Clicked!) // not fired
6 Script the application’s Open event:
open (w_main)
When the ProcessPBMessage function is included in the C++ application, the
application runs from C++ as it does in PowerBuilder. The posted events in
cb_2 and cb_3 are processed.
Now try commenting out these lines in the C++ application, recompiling, and
running the application again:
if (session)
session->ProcessPBMessage();
The message boxes still display (response windows have their own message
loop) and the of_setcolor function is called, but the posted events do not fire.
Calling PowerBuilder You can combine the ability to call PowerBuilder classes from C++, as
from Java described in this chapter, with the ability to create marshaler extensions, as
described in Chapter 3, “Creating Marshaler Extensions,” to call
PowerBuilder from Java.
One way to do this is to create a Java proxy class that declares static native
methods that can be called to load the PBVM, create PowerBuilder sessions,
create PowerBuilder objects, and invoke PowerScript functions. These native
methods can call into the PBVM through PBNI. Additional Java classes that
represent the PBVM, PowerBuilder sessions, and PowerBuilder objects can be
based on the proxy class.
78 PowerBuilder Classic
CHAPTER 5 Calling PowerBuilder from C++
The Java classes call the Java native methods through JNI, whereas the Java
native methods call PowerBuilder through PBNI.
There is a sample that illustrates these techniques on the PowerBuilder
CodeXchange Web site at http://powerbuilder.codexchange.sybase.com.
80 PowerBuilder Classic
PART 2 Reference
About this chapter This chapter contains information about the datatypes, enumerated types,
and error return values used by the PowerBuilder Native Interface.
Contents
Topic Page
PowerBuilder to PBNI datatype mappings 83
Types for access to PowerBuilder data 84
PBNI enumerated types 84
Error return values 86
84 PowerBuilder Classic
CHAPTER 6 PBNI Types and Return Values
Enumerated types for The pbvalue_type enumerated types are used in methods such as the IPB_Value
PowerBuilder values GetType method and the IPB_Session NewUnboundedSimpleArray method to
identify the type of PowerBuilder data.
Table 6-4: Enumerated types for PowerBuilder values
Value PowerBuilder datatype
pbvalue_notype Undetermined datatype.
pbvalue_int Int
pbvalue_uint Uint
pbvalue_byte Byte
pbvalue_long Long
pbvalue_longlong Longlong
pbvalue_ulong Ulong
pbvalue_real Real
pbvalue_double Double
pbvalue_dec Decimal
pbvalue_string String
pbvalue_boolean Boolean
pbvalue_any Any (changed to another datatype when set explicitly)
pbvalue_blob Blob
pbvalue_date Date
pbvalue_time Time
pbvalue_datetime DateTime
pbvalue_char Char
Enumerated types for The pbrt_type enumerated types are used in IPB_Session GetMethodID calls to
PowerBuilder routines identify the type of routine required.
Table 6-5: Enumerated types for PowerBuilder routines
Value Routine type
PBRT_FUNCTION Function
PBRT_EVENT Event
86 PowerBuilder Classic
CH A PTE R 7 PBNI Interfaces, Structures, and
Methods
About this chapter This chapter contains reference information about the classes, structures,
and methods of the PowerBuilder Native Interface.
Contents
Topic Page
Header file contents 88
Class and interface summary 88
IPB_Arguments interface 90
IPB_ResultSetAccessor interface 92
IPB_RSItemData interface 95
IPB_Session interface 96
IPB_Value interface 202
IPB_VM interface 211
IPBX_Marshaler interface 215
IPBX_NonVisualObject interface 218
IPBX_UserObject interface 219
IPBX_VisualObject interface 221
PBArrayInfo structure 226
PBCallInfo structure 226
PB_DateData structure 227
PB_DateTimeData structure 227
PB_TimeData structure 227
PBX_DrawItemStruct structure 228
PBArrayAccessor template class 229
PBBoundedArrayCreator template class 232
PBBoundedObjectArrayCreator class 235
PBObjectArrayAccessor class 236
PBUnboundedArrayCreator template class 238
PBUnboundedObjectArrayCreator class 240
Exported methods 241
Method exported by PowerBuilder VM 252
88 PowerBuilder Classic
CHAPTER 7 PBNI Interfaces, Structures, and Methods
Defined
Object Description in
IPBX_Marshaler interface Used to invoke remote methods and convert PowerBuilder data pbext.h
formats to the user’s communication protocol. A marshaler
extension is a PowerBuilder extension that acts as the bridge
between PowerBuilder and other components, such as EJBs,
Java classes, CORBA objects, Web services, and so on.
IPBX_NonVisualObject interface Inherits from IPBX_UserObject and is the direct ancestor class pbext.h
of nonvisual PowerBuilder native classes.
IPBX_UserObject interface The ancestor class of PowerBuilder native classes. It has two pbext.h
functions, Destroy and Invoke.
IPBX_VisualObject interface Inherits from IPBX_UserObject and is the direct ancestor class pbext.h
of visual PowerBuilder native classes.
Exported methods Some exported methods must be implemented in PowerBuilder pbext.h
extension modules.
Method exported by PowerBuilder The PB_GetVM method is exported by the PowerBuilder VM pbni.h
VM and is used to pass the IPB_VM interface to the user.
IPB_Arguments interface
Description The IPB_Arguments and IPB_Value interfaces are used to pass values between
the PowerBuilder VM and PowerBuilder extension modules. Each argument is
represented by a pointer to the IPB_Value interface.
Methods The IPB_Arguments interface has two methods, GetAt and GetCount.
GetAt
Description Returns a pointer to the IPB_Value interface representing an argument whose
order in the list of arguments is indicated by a specified index.
Syntax GetAt ( pbint index )
Argument Description
index A valid index into the PBCallInfo structure
Examples In the following code fragment, GetAt obtains the first value in the PBCallInfo
structure. The value has been passed in from the calling function.
90 PowerBuilder Classic
CHAPTER 7 PBNI Interfaces, Structures, and Methods
PBCallInfo ci;
LPCSTR myPBNIObj = NULL;
IPB_Value* pArg0 = ci->pArgs->GetAt(0);
if (!pArg0->IsNull())
{
pbstring t = pArg0->GetString();
if (t != NULL)
myPBNIObj = session->GetString(t);
}
See also GetCount
GetCount
Description Obtains the number of arguments in an instance of PBCallInfo.
Syntax GetCount ( )
Return value pbint.
Examples This example uses GetCount in a FOR loop used to process different argument
types:
int i;
for (i=0; i < ci-> pArgs -> GetCount();i++)
{
pbuint ArgsType;
pArguments[i].array_val =
ci -> pArgs -> GetAt(i) -> GetArray();
continue;
}
IPB_ResultSetAccessor interface
Description The IPB_ResultSetAccessor interface is used to access result sets in
DataWindow and DataStore objects.
Methods The IPB_ResultSetAccessor interface has six methods:
AddRef
GetColumnCount
GetColumnMetaData
GetItemData
GetRowCount
Release
AddRef
Description When you call the CreateResultSet function of interface IPB_Session, you
need to pass an argument of type IPB_ResultSetAccessor. The AddRef function
is called on that argument and the Release function is called when the pbobject
is destroyed.
Syntax AddRef ( )
Return value None.
See also CreateResultSet
GetColumnCount
GetColumnCount
Description Obtains the number of columns.
Syntax GetColumnCount ( )
Return value Unsigned long.
Examples This statement stores the number of columns in *numCols:
*numCols = d_rsAccessor->GetColumnCount();
See also CreateResultSet
GetRowCount
92 PowerBuilder Classic
CHAPTER 7 PBNI Interfaces, Structures, and Methods
GetColumnMetaData
Description Obtains a column's metadata. The column number of the first column is 1.
Memory must be allocated for columnName before this function call. The
pointer values can be null.
Syntax GetColumnMetaData (unsigned long columnNum, LPTSTR columnName,
pbvalue_type* type, unsigned long* width )
Argument Description
columnNum The number of the column for which you want to
obtain metadata
columnName The name of the specified column
type A pointer to the type of the specified column
width A pointer to the width of the specified column
Examples This example gets the number of columns in a result set and allocates an array
to hold the types of each column:
CRsltSet::CRsltSet(IPB_ResultSetAccessor* rsAccessor)
:m_lRefCount (0), d_rsAccessor(rsAccessor)
{
rsAccessor->AddRef();
// for each column
ULONG nNumColumns = d_rsAccessor->GetColumnCount();
d_arrColTypes = new USHORT[nNumColumns + 1];
for (ULONG nColumn=1; nColumn <= nNumColumns;
++nColumn)
{
// get the column type into the array
pbvalue_type type;
d_rsAccessor->GetColumnMetaData (nColumn,
NULL, &type, NULL);
d_arrColTypes[nColumn] = (USHORT)type;
}
}
See also CreateResultSet
GetColumnCount
GetItemData
GetRowCount
GetItemData
Description Accesses the data in a cell. The first row is 1 and the first column is 1.
Syntax GetItemData(unsigned long row, unsigned long col, IPB_RSItemData* data)
Argument Description
row The row number of the cell
col The column number of the cell
data A pointer to an IPB_RSItemData structure
Examples This example stores the data in the first row and column in the
IPB_RSItemData structure sd:
d_rsAccessor->GetItemData(1, 1, &sd);
Usage If the value of data is null, this function issues the callback data->SetNull. If
the value is not null, it issues the callback data->SetData. For more
information, examine the IPB_RSItemData interface.
See also CreateResultSet
GetColumnCount
GetColumnMetaData
GetRowCount
IPB_RSItemData interface
SetData
SetNull
GetRowCount
Description Obtains the number of rows.
Syntax GetRowCount ( )
Return value Unsigned long.
94 PowerBuilder Classic
CHAPTER 7 PBNI Interfaces, Structures, and Methods
Release
Description When you call the CreateResultSet function of interface IPB_Session, you
need to pass an argument of type IPB_ResultSetAccessor. The AddRef function
is called on that argument and the Release function is called when the pbobject
is destroyed.
Syntax Release ( )
Return value None.
IPB_RSItemData interface
Description The IPB_RSItemData interface is used as an argument to the GetItemData
function of IPB_ResultSetAccessor.
Methods The IPB_RSItemData interface has two methods: SetData and SetNull.
SetData
Description Sets the data in an IPB_RSItemData structure when the GetItemData function
of IPB_ResultSetAccessor is called and the data value is not null.
Syntax SetData(unsigned long len, void* data)
Argument Description
len The length of the data
data A void pointer to the address of the data
SetNull
Description Sets the data in an IPB_RSItemData structure to null when the GetItemData
function of IPB_ResultSetAccessor is called and the data value is not null.
Syntax SetNull()
Return value None.
IPB_Session interface
Description The IPB_Session interface is used to interoperate with PowerBuilder. An
abstract interface, it defines methods for accessing PowerScript data, calling
PowerScript functions, catching and throwing PowerScript exceptions, and
setting a marshaler to convert PowerBuilder data formats to the user’s
communication protocol.
Methods This table lists functions by category. Full descriptions in alphabetic order
follow the table.
Table 7-2: IPB_Session methods by category
Purpose Method Description
Managing sessions Release Releases this IPB session. The IPB_Session
object becomes invalid after the call.
Managing object references AddGlobalRef Adds a global reference to the specified
PowerBuilder object.
AddLocalRef Adds a local reference to the specified
PowerBuilder object.
NewObject Creates a new object of the specified type.
PopLocalFrame Pops the current local reference frame from the
current native method stack frame.
96 PowerBuilder Classic
CHAPTER 7 PBNI Interfaces, Structures, and Methods
98 PowerBuilder Classic
CHAPTER 7 PBNI Interfaces, Structures, and Methods
AcquireArrayItemValue
Description Clones the data in the PBCallInfo structure in an array item and resets the
IPB_Value pointer.
Syntax AcquireArrayItemValue( pbarray array, pblong dim[ ])
Argument Description
array A valid pbarray structure.
dim A pblong array to hold the indexes of all dimensions
of the array. The size of the array must equal the
dimensions of array.
The PBVM clones a new IPB_Value and resets the existing one. If you attempt
to get or acquire the original value, the value returned is zero or null until
another IPB_Value is set to the value.
AcquireValue
Description Clones the data in the PBCallInfo structure and resets the IPB_Value pointer.
Syntax AcquireValue ( IPBValue* value )
Argument Description
value The value to be returned
If the value acquired is an array, the entire array is acquired. To acquire a single
element in an array, use the AcquireItemValue method.
When you no longer need the data, you must call the ReleaseValue method to
free the data. Failing to do so causes a memory leak.
The PBVM clones a new IPB_Value and resets the existing one. If you attempt
to get or acquire the original value, the value returned is zero or null until
another IPB_Value is set to the value.
See also AcquireArrayItemValue
ReleaseValue
Add<type>Argument
Description Adds an argument of a specific type in a variable argument PowerBuilder call.
Syntax AddArrayArgument ( PBCallInfo *ci, pbblob value, pbboolean IsNull )
AddBlobArgument ( PBCallInfo *ci, pbblob value, pbboolean IsNull )
AddBoolArgument ( PBCallInfo *ci, pbboolean value, pbboolean IsNull )
AddByteArgument ( PBCallInfo *ci, pbbyte value, pbboolean IsNull )
AddCharArgument ( PBCallInfo *ci, pbchar value, pbboolean IsNull )
AddDateArgument ( PBCallInfo *ci, pbdate value, pbboolean IsNull )
AddDateTimeArgument ( PBCallInfo *ci, pbdatetime value, pbboolean IsNull )
AddDecArgument ( PBCallInfo *ci, pbdec value, pbboolean IsNull )
AddDoubleArgument ( PBCallInfo *ci, pbdouble value, pbboolean IsNull )
AddIntArgument ( PBCallInfo *ci, pbint value, pbboolean IsNull )
AddLongArgument ( PBCallInfo *ci, pblong value, pbboolean IsNull )
AddLongLongArgument ( PBCallInfo *ci, pblonglong value, pbboolean IsNull )
AddObjectArgument ( PBCallInfo *ci, pbobject value, pbboolean IsNull )
AddPBStringArgument ( PBCallInfo *ci, pbstring value, pbboolean IsNull )
AddRealArgument ( PBCallInfo *ci, pbreal value, pbboolean IsNull )
AddStringArgument ( PBCallInfo *ci, LPCTSTR value, pbboolean IsNull )
AddTimeArgument ( PBCallInfo *ci, pbtime value, pbboolean IsNull )
AddUintArgument ( PBCallInfo *ci, pbuint value, pbboolean IsNull )
AddUlongArgument ( PBCallInfo *ci, pbulong value, pbboolean IsNull )
Argument Description
ci The PBCallInfo to which the argument is to be
added.
value The value to be added to the arguments array.
IsNull Indicates whether the argument is null. The default
is false.
session-> FreeCallInfo(ci);
delete ci;
return ret_val;
}
AddGlobalRef
Description Adds a global reference to the specified PowerBuilder object.
Syntax AddGlobalRef (pbobject obj)
Argument Description
obj A valid PowerBuilder object handle
Examples This example checks whether a return value is null, and if it is not, adds a global
reference to it to the session:
if (ci-> returnValue-> IsNull())
ret_val = 0;
else
{
ret_val = ci-> returnValue-> GetObject();
Session -> AddGlobalRef(ret_val);
}
See also RemoveGlobalRef
AddLocalRef
Description Adds a local reference to the specified PowerBuilder object.
Syntax AddLocalRef (pbobject obj)
Argument Description
obj A valid PowerBuilder object handle
Examples This example defines functions that add and remove local references:
void MyPBNIClass::reference()
{
d_session->AddLocalRef(d_pbobject);
}
void MyPBNIClass::unreference()
{
if(d_pbobject != NULL)
d_session->RemoveLocalRef(d_pbobject);
}
See also PopLocalFrame
PushLocalFrame
RemoveLocalRef
ClearException
Description Clears the current PowerBuilder exception object.
Syntax ClearException ()
Return value None.
Usage HasExceptionThrown returns false after a call to ClearException. If no exception
has been thrown, this call has no effect.
See also GetException
HasExceptionThrown
ThrowException
CreateResultSet
Description Creates a result set object using a pointer to an IPB_ResultSetAccessor object.
Syntax CreateResultSet (IPB_ResultSetAccessor* rs)
Argument Description
rs A pointer to an IPB_ResultSetAccessor object
Examples This example loads the PBVM and calls the f_ret and f_in functions in the
custom class user object n_rs in the PBL pbrs.pbl. The PowerScript for the
functions is shown after the C++ code:
#include "stdafx.h"
#include "windows.h"
#include "pbni.h"
#include "vector"
using std::vector;
getvm(&pbvm);
ll[0] = "pbrs.pbl";
session->FreeCallInfo(&ci);
session->FreeCallInfo(&ci1);
}
f_ret retrieves data from a database into a DataStore and generates a result set:
ResultSet rs
DataStore ds
Long sts
Integer li_ret
ds = Create DataStore
ds.DataObject = ""
ds.DataObject = "d_rs"
ds.SetTransObject(sqlca)
w_main.dw_1.SetTransObject(sqlca)
Return rs
f_in takes a result set, rs, as an argument and uses it to create a DataStore:
DataStore ds
Int cnt, li_ret
ds = Create DataStore
ds.CreateFrom(rs)
cnt = ds.RowCount()
messagebox("info from f_in", "row count is " +
string(cnt))
Return cnt
Usage To use the IPB_ResultSetAccessor interface, load the PBVM, obtain a result
set from a PowerBuilder application, and call GetResultSetAccessor on this
result set to get an IPB_ResultSetAccessor interface object. You can then call
the methods of this object to get information about the result set. You can also
call CreateResultSet using this object as an argument to create a result set that
you can return to PowerBuilder.
When you call CreateResultSet, the AddRef function of the
IPB_ResultSetAccessor interface is called on the rs argument implicitly to add
a reference to the interface pointer.
See also AddRef
GetResultSetAccessor
IPB_ResultSetAccessor interface
ReleaseResultSetAccessor
FindClass
Description Searches for a class with a given name within a given group.
Syntax FindClass(pbgroup group, LPCTSTR name)
Argument Description
group The handle of the group in which the class resides
name The class name in lowercase
Examples This example finds the group associated with the f_getrow function and uses the
group to find the class:
group = session->FindGroup("f_getrow",
pbgroup_function);
if ( group==NULL )
return;
cls = session->FindClass(group, "f_getrow");
if ( cls==NULL )
return;
Usage This method searches for a PowerBuilder class with the given name in the
given group. For example, in a window definition w_1, w_1 is a group, and w_1
and controls contained in it are all classes of group w_1.
See also FindGroup
NewObject
FindClassByClassID
Description Searches for a class with a given name and a given ID.
Syntax FindClass(pbgroup group, pbint classID)
Argument Description
group The handle of the group in which the class resides
classID The class name in lowercase
Usage This method searches for a PowerBuilder class with the given name and the
given ID.
See also FindGroup
NewObject
FindGroup
Description Searches for a group with a given name and group type in the current library
list.
Syntax FindGroup(LPCTSTR name, pbgroup_type type)
Argument Description
name The group name in lowercase
type An enumerated type defined in pbgroup_type
Examples This example finds the group associated with user_exception and uses the
group to find the class:
group = session-> FindGroup("user_exception",
pbgroup_userobject);
if ( group==NULL )
return;
cls = session->FindClass(group, "user_exception")
See also FindClass
NewObject
FindMatchingFunction
Description Finds a function that has the specified argument list.
Syntax FindMatchingFunction(pbclass cls, LPCTSTR methodName, PBRoutineType
rt, LPCTSTR readableSignature)
Argument Description
cls pbclass containing the method.
methodName The string name of the method in lowercase.
rt Type of the method: PBRT_FUNCTION for
function or PBRT_EVENT for event.
readableSignature A comma-separated string listing the types of the
method’s arguments. The return type of the method
is not included in the string. See the Usage section
for examples.
Examples This example returns the method ID of a function named uf_test that takes an
integer and a double as arguments:
pbclass cls;
pbmethodID mid;
PBCallInfo* ci = new PBCallInfo;
unsigned long ret_val;
FindMatchingFunction does not check the access type of the function, so you can
use it to obtain the method ID of a private function. GetMethodID cannot obtain
the method ID of a private function.
See also GetMethodID
FreeCallInfo
Description Frees memory allocated by InitCallInfo.
Syntax FreeCallInfo(PBCallInfo *ci)
Argument Description
ci A pointer to the preallocated PBCallInfo structure
Get<type>ArrayItem
Description Obtains the value of an array item of a specified type.
Syntax GetBlobArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetBoolArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetByteArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetCharArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetDateArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetDateTimeArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetDecArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetDoubleArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetIntArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull)
GetLongArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetLongLongArrayItem (pbarray array, pblonglong dim[ ], pbboolean& IsNull)
GetObjectArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
GetRealArrayItem ( pbarray array, pblong dim[ ], pbboolean& IsNull )
Argument Description
array A valid pbarray structure
dim The dimension of the array item to be obtained
IsNull Indicates whether the array item is null
dim[0] = pbl + 1;
pPBObject = session->GetObjectArrayItem(array, dim,
bIsNull);
See also GetArrayInfo
GetArrayItemType
GetArrayLength
IsArrayItemNull
NewBoundedObjectArray
NewBoundedSimpleArray
NewUnboundedObjectArray
NewUnboundedSimpleArray
ReleaseArrayInfo
SetArrayItemToNull
SetArrayItemValue
Set<type>ArrayItem
Get<type>Field
Description A set of methods that gets the value of an instance field of an object.
Syntax GetArrayField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetBlobField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetBoolField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetByteField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetCharField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetDateField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetDateTimeField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetDecField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetDoubleField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetIntField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetLongField( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetLongLongField( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetObjectField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetRealField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetStringField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetTimeField ( pbobject obj, pbfieldID fid, pbint value )
GetUintField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
GetUlongField ( pbobject obj, pbfieldID fid, pbboolean& isNull )
Argument Description
obj The handle of the object whose field is to be
accessed
fid The field ID of the specified object
isNull Indicates whether the field is null
Return value A predefined PBNI datatype that corresponds to the PowerBuilder datatype in
the method name.
Examples This example gets the value of a field of type pbstring:
pbboolean isNull;
pbstring pstr =
session->GetStringField(proxy, fid, isNull);
if (pstr != NULL)
{
myclass = session->GetString(pstr);
// process myclass
}
See also GetFieldID
GetFieldType
GetNumOfFields
IsFieldArray
IsFieldNull
IsFieldObject
SetFieldToNull
Set<type>Field
Get<type>GlobalVar
Description A set of methods that gets the value of a global variable of a specific datatype.
Syntax GetArrayGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetBlobGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetBoolGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetByteGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetCharGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetDateGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetDateTimeGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetDecGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetDoubleGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetIntGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetLongGlobalVar( pbfieldID fid, pbboolean& isNull )
GetLongLongGlobalVar( pbfieldID fid, pbboolean& isNull )
GetObjectGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetRealGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetStringGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetTimeGlobalVar ( pbfieldID fid, pbint value )
GetUintGlobalVar ( pbfieldID fid, pbboolean& isNull )
GetUlongGlobalVar ( pbfieldID fid, pbboolean& isNull )
Argument Description
fid The field ID of the global variable
isNull Indicates whether the variable is null
Return value A predefined PBNI datatype that corresponds to the PowerBuilder datatype in
the method name.
Examples This code gets the value of a global variable of datatype long using its field ID:
fid = session -> GetGlobalVarID("l_gvar");
l_val = session -> GetLongGlobalVar(fid, isNull);
session -> SetLongGlobalVar(fid, l_val + 1);
See also GetGlobalVarID
GetGlobalVarType
IsGlobalVarArray
IsGlobalVarNull
IsGlobalVarObject
SetGlobalVarToNull
Set<type>GlobalVar
Get<type>SharedVar
Description A set of methods that gets the value of a shared variable of a specific datatype.
Syntax GetArraySharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetBlobSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetBoolSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetByteSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetCharSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetDateSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetDateTimeSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetDecSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetDoubleSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetIntSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetLongSharedVar( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetLongLongSharedVar( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetObjectSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetRealSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetStringSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetTimeSharedVar ( pbgroup group, pbfieldID fid, pbint value )
GetUintSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
GetUlongSharedVar ( pbgroup group, pbfieldID fid, pbboolean& isNull )
Argument Description
group The group whose shared variable is to be accessed
fid The field ID of the shared variable
isNull Indicates whether the variable is null
Return value A predefined PBNI datatype that corresponds to the PowerBuilder datatype in
the method name.
Examples This code gets the value of a shared variable of type integer:
curGroup = session -> GetCurrGroup();
fid = session -> GetSharedVarID(curGroup, "i_svar");
if (fid == 0xffff)
{
MessageBox(NULL, "Illegal fid!", "default", MB_OK);
return;
}
i_val = session-> GetIntSharedVar(curGroup, fid,
isNull);
session-> SetIntSharedVar(curGroup, fid, i_val+1);
See also GetSharedVarID
GetSharedVarType
IsSharedVarArray
IsSharedVarNull
IsSharedVarObject
Set<type>SharedVar
SetSharedVarToNull
GetArrayInfo
Description Obtains information about an array.
Syntax GetArrayInfo(pbarray array)
Argument Description
array A valid array handle
Examples This IF-ELSE statement populates a PBArrayInfo structure if the array in the
first value of a PBCallInfo structure is not null:
if ( !(ci->pArgs->GetAt(0)->IsNull()) )
{
array = ci->pArgs->GetAt(0)->GetArray();
pArrayInfo = session->GetArrayInfo (array);
pArrayItemCount = session->GetArrayLength(array);
}
else
{
// NULL array
pArrayItemCount = 0;
}
Usage If the array is an unbounded array, the bounds information in PBArrayInfo is
undetermined. The returned PBArrayInfo must be freed later by
ReleaseArrayInfo.
See also Get<type>ArrayItem
GetArrayItemType
GetArrayLength
IsArrayItemNull
NewBoundedObjectArray
NewBoundedSimpleArray
NewUnboundedObjectArray
NewUnboundedSimpleArray
ReleaseArrayInfo
SetArrayItemToNull
SetArrayItemValue
Set<type>ArrayItem
GetArrayItemType
Description Obtains the datatype of an item in an array.
Syntax GetArrayItemType( pbarray array, pblong dim[ ])
Argument Description
array A valid pbarray structure.
dim A pblong array to hold the indexes of each
dimension of the array. The size of the array must
equal the dimensions of array.
GetArrayLength
Description Obtains the length of an array.
Syntax GetArrayLength(pbarray array)
Argument Description
array A valid array handle
Examples This IF-ELSE statement populates a PBArrayInfo structure. If the array in the
first value of a PBCallInfo structure is not null, it sets the value of the
pArrayItemCount variable to the length of the array:
if ( !(ci->pArgs->GetAt(0)->IsNull()) )
{
array = ci->pArgs->GetAt(0)->GetArray();
pArrayInfo = session->GetArrayInfo (array);
pArrayItemCount = session->GetArrayLength(array);
}
else
{
// NULL array
pArrayItemCount = 0;
}
See also Get<type>ArrayItem
GetArrayInfo
IsArrayItemNull
NewBoundedObjectArray
NewBoundedSimpleArray
NewUnboundedObjectArray
NewUnboundedSimpleArray
ReleaseArrayInfo
SetArrayItemToNull
SetArrayItemValue
Set<type>ArrayItem
GetBlob
Description Returns a pointer to the data buffer for a blob.
Syntax GetBlob(pbblob bin)
Argument Description
bin A pointer to the source buffer
GetBlobLength
Description Returns the length in bytes of blob data in a buffer.
Syntax GetBlobLength (pbblob bin)
Argument Description
bin A pointer to the source buffer
Examples In this example, the IPB_Value GetBlob function is used to get a blob value
from the PBCallInfo structure. The length of the blob is used as an argument to
the NewBlob function:
PBCallInfo* ci = new PBCallInfo;
pbblob ret_val;
pblong bloblen;
GetClass
Description Returns the class handle of a PowerBuilder object. This function is most
frequently used to obtain a class handle for use with the GetMethodID function.
Syntax GetClass (pbobject obj)
Argument Description
obj A valid PowerBuilder object handle
Examples In this example, GetClass is used to obtain the class of a variable of type
UserData so that the class can be used as an argument to the GetMethodID
function:
BOOL CALLBACK CFontEnumerator::EnumFontProc
(
LPLOGFONT lplf,
LPNEWTEXTMETRIC lpntm,
DWORD FontType,
LPVOID userData
)
{
UserData* ud = (UserData*)userData;
pbclass clz = ud->session->GetClass(ud->object);
pbmethodID mid = ud->session->GetMethodID
(clz, "onnewfont", PBRT_EVENT, "IS");
PBCallInfo ci;
ud->session->InitCallInfo(clz, mid, &ci);
GetClassName
Description Returns the name of a class in lowercase.
Syntax GetClassName(pbclass cls)
Argument Description
cls A valid class handle
Examples This example gets the name of a class and sets the size of the variable stLength
to the length of the returned string plus 1:
LPCTSTR myClassName = session->GetClassName( myClass );
size_t stLength = strlen( (LPSTR)myClassName ) + 1;
Usage When you have finished using the name, call the ReleaseString method to free
the memory acquired.
See also GetClass
ReleaseString
GetCurrGroup
Description Obtains the name of the current group.
Syntax GetCurrGroup( )
Return value pbgroup or null on failure.
Examples This example gets the name of the current group and uses it to obtain the
identifier of a shared variable, get the shared variable’s value, and reset the
shared variable’s value:
curGroup = session -> GetCurrGroup();
fid = session -> GetSharedVarID(curGroup, "i_svar");
if (fid == 0xffff)
{
MessageBox(NULL, "Illegal fid!", "default", MB_OK);
return;
}
i_val = session-> GetIntSharedVar(curGroup, fid,
isNull);
session-> SetIntSharedVar(curGroup, fid, i_val+1);
See also Get<type>SharedVar
GetSharedVarID
Set<type>SharedVar
GetDateString
Description Converts data in a pbdate object to a string.
Syntax GetDateString(pbdate date)
Argument Description
date The pbdate data object to be converted to a string.
GetDateTimeString
Description Converts data in a pbdatetime object to a string.
Syntax GetDateTimeString(pbdatetime datetime)
Argument Description
datetime The pbdatetime data object to be converted to a
string.
GetDecimalString
Description Converts decimal data in a pbdec object to a string.
Syntax GetDecimalString(pbdec dec)
Argument Description
dec The pbdec data object to be converted to a string.
Examples This code checks whether a value in the PBCallInfo structure is null. If it is not,
it sets the value in the pArguments array to the value in PBCallInfo:
case pbvalue_dec:
if (ci->pArgs->GetAt(i)->IsNull())
{
pArguments[i].dec_val = Session->NewDecimal();
Session->SetDecimal(pArguments[i].dec_val, "1.0");
}
else
pArguments[i].dec_val =
ci->pArgs->GetAt(i)->GetDecimalString();
break;
See also NewDecimal
ReleaseDecimalString
SetDecimal
GetEnumItemName
Description Obtains the name of an enumerated variable.
Syntax GetEnumItemName(LPCTSTR enumName, long enumItemValue)
Return value LPCTSTR.
Usage When you have finished using the name, call the ReleaseString method to free
the memory acquired.
See also GetEnumItemValue
ReleaseString
GetEnumItemValue
Description Obtains the value of an enumerated variable.
Syntax GetEnumItemValue(LPCTSTR enumName, LPCTSTR enumItemName)
Return value Long.
Examples This example gets the numeric value for the boolean! enumerated value, then
uses it to return the string value:
pblong lType = session->GetEnumItemValue("object",
boolean" ); // returns 138
LPCTSTR szEnum = session->GetEnumItemName( "object",
lType ); // returns "boolean"
Usage GetEnumItemValue and GetEnumItemName support enumerated types. They
allow you to convert the name of an enumerated value, a string with an
appended exclamation mark (!), to an integer value, and vice versa.
GetException
Description Obtains the current thrown exception object.
Syntax GetException ()
Return value pbobject.
Examples This code gets the current exception object, clears the exception, and gets the
class of the exception object:
pbclass cls;
pbobject ex;
...
ex = session-> GetException();
session-> ClearException();
cls = session-> GetClass(ex);
See also ClearException
HasExceptionThrown
GetFieldID
Description Obtains the internal ID of a class instance variable.
Syntax GetFieldID(pbclass cls, LPCTSTR fieldName)
Argument Description
cls The class in which the field resides
fieldName The instance member name, in lowercase
Examples This function obtains the identifier of a class’s visible field, if it exists, and uses
it to set the value of the field:
void CallBack::f_setvisible(IPB_Session* session,
pbobject dwobj)
{
pbclass cls;
IPB_Value* pv;
pbfieldID fid;
pbstring strtmp;
bool isTrue;
pbboolean isNull;
if (fid == kUndefinedFieldID)
return;
isTrue = session-> GetBoolField(dwobj, fid, isNull);
if (isTrue)
session -> SetBoolField(dwobj, fid, false);
else
session -> SetBoolField(dwobj, fid, true);
return ;
}
Usage GetFieldID is one of a set of functions that allows native code to access the
fields of Java objects and get and set their values. You use GetFieldID to retrieve
the value of a field, specifying the class name and the field name. The field ID
returned can be used as an argument to the related functions.
See also GetFieldType
Get<type>Field
GetNumOfFields
IsFieldArray
IsFieldNull
IsFieldObject
Set<type>Field
SetFieldToNull
GetFieldName
Description Obtains the name of the specified field.
Syntax GetFieldName(pbclass cls, pbfieldID fid)
Argument Description
cls The class that defines the field
fid The internal ID of the class instance variable
Return value LPCTSTR. The field name of the specified field. If an incorrect field ID is
specified, this function returns null.
Usage When you have finished using the name, call the ReleaseString method to free
the memory acquired.
See also GetFieldID
ReleaseString
GetFieldType
Description Obtains the datatype of a field declared by a class.
Syntax GetFieldType(pbclass cls, pbfieldID fid)
Argument Description
cls The class that defines the field
fid The internal ID of the class instance variable
Return value pbint. A simple datatype defined in the list of pbvalue_type enumerated types,
such as pbvalue_int. See “PBNI enumerated types” on page 84.
Examples This statement gets the type of the specified field ID:
pbint pbfieldType = session->GetFieldType(cls, fid);
See also GetFieldID
Get<type>Field
GetNumOfFields
IsFieldArray
IsFieldNull
IsFieldObject
Set<type>Field
SetFieldToNull
GetGlobalVarID
Description Returns the internal ID of a global variable.
Syntax GetGlobalVarID(LPCTSTR name)
Argument Description
name The name of the global variable in lowercase
Examples This example gets the internal identifier of a long variable and uses it to get and
set a global variable:
fid = session -> GetGlobalVarID("l_gvar");
l_val = session -> GetLongGlobalVar(fid, isNull);
session -> SetLongGlobalVar(fid, l_val + 1);
See also GetGlobalVarType
Get<type>GlobalVar
IsGlobalVarArray
IsGlobalVarNull
IsGlobalVarObject
SetGlobalVarToNull
Set<type>GlobalVar
GetGlobalVarType
Description Obtains the datatype of a global variable.
Syntax GetGlobalVarType(pbfieldID fid)
Argument Description
fid The internal ID of the class instance variable
Return value pbuint. A simple datatype defined in the list of pbvalue_type enumerated types.
Examples This code tests getting and setting a global integer variable using the field ID
fid:
fid = session -> GetGlobalVarID("i_gvar");
if (session -> GetGlobalVarType(fid) == pbvalue_int)
{
i_val=session -> GetIntGlobalVar(fid,isNull);
session -> SetIntGlobalVar(fid,i_val+1);
}
See also GetGlobalVarID
Get<type>GlobalVar
IsGlobalVarArray
IsGlobalVarNull
IsGlobalVarObject
SetGlobalVarToNull
Set<type>GlobalVar
GetMarshaler
Description Obtains the marshaler object associated with a proxy object.
Syntax GetMarshaler(pbproxyObject obj)
Argument Description
obj An object of type pbproxyObject for which you want
to find the marshaler.
// Create JavaMarshaler
JavaMarshaler* marshaler = new JavaMarshaler(env,
proxy, jobj);
return PBX_OK;
...
// Get the marshaler
IPBX_Marshaler* pIPBX_Marshaler = NULL;
pIPBX_Marshaler =(IPBX_Marshaler*)session
-> GetMarshaler(proxy);
See also SetMarshaler
GetMethodID
Description Returns the ID of the requested method.
Syntax GetMethodID(pbclass cls, LPCTSTR methodName, PBRoutineType rt,
LPCTSTR signature, pbboolean publicOnly)
Argument Description
cls pbclass containing the function.
methodName The string name of the method in lowercase.
rt Type of the method: PBRT_FUNCTION for
function or PBRT_EVENT for event.
signature Internal signature of the PowerBuilder function,
used to identify polymorphic methods in one class.
Obtained with the pbsig125 tool. If the signature is
a null string (" "), the first method found with the
name methodName is returned.
publicOnly A boolean that determines whether only public
methods are searched (true) or all methods are
searched (false). The default is true.
Examples This function uses GetMethodID to obtain the identifier (mid) of the onnewfont
function so that the identifier can be used to initialize the PBCallInfo structure
and call the function:
BOOL CALLBACK CFontEnumerator::EnumFontProc
(
LPLOGFONT lplf,
LPNEWTEXTMETRIC lpntm,
DWORD FontType,
LPVOID userData
)
{
UserData* ud = (UserData*)userData;
pbclass clz = ud->session->GetClass(ud->object);
pbmethodID mid = ud->session->GetMethodID(clz,
"onnewfont", PBRT_EVENT, "IS");
PBCallInfo ci;
ud->session->InitCallInfo(clz, mid, &ci);
pbstring str = ud->session->
NewString(lplf->lfFaceName);
ci.pArgs->GetAt(0)->SetPBString(str);
ud->session->TriggerEvent(ud->object, mid, &ci);
pbint ret = ci.returnValue->GetInt();
ud->session->FreeCallInfo(&ci);
GetMethodIDByEventID
Description Returns the ID of the method that has a given predefined PowerBuilder event
ID.
Syntax GetMethodIDByEventID(pbclass cls, LPCTSTR eventID)
Argument Description
cls pbclass containing the method
eventID A PowerBuilder predefined event string, such as
pbm_bnclicked
Examples This statement obtains the ID of the event identified by the name
pbm_lbuttonup:
pbmethodID mid = d_session->GetMethodIDByEventID(clz,
"pbm_lbuttonup");
See also GetMethodID
GetNativeInterface
Description Obtains a pointer to the interface of a native class.
Syntax GetNativeInterface(pbobject obj)
Argument Description
obj A valid object handle
GetNumOfFields
Description Returns the number of fields in the specified class.
Syntax GetNumOfFields(pbclass cls)
Argument Description
cls A valid class handle for the class whose field is to be
accessed
Examples This code gets the numbers of fields in the class clz:
pbclass clz = d_session->GetClass(d_pbobj);
pbulong nf = d_session->GetNumOfFields(clz);
See also GetFieldID
Get<type>Field
IsFieldArray
IsFieldNull
IsFieldObject
SetFieldToNull
Set<type>Field
GetPBAnyArrayItem
Description Obtains the value of a global variable of type Any.
Syntax GetPBAnyArrayItem( pbarray array, pblong dim[], pbboolean& isNull )
Argument Description
array A valid pbarray structure.
dim A pblong array to hold the indexes of each
dimension of the array. The size of the array must
equal the dimensions of array.
isNull Indicates whether the variable is null
GetPBAnyField
Description Obtains the value of a variable of type Any.
Syntax GetPBAnyField( pbobject obj, pbfieldID fid, pbboolean& isNull )
Argument Description
obj A valid object handle for the object whose value is
to be obtained
fid The field ID of the variable
isNull Indicates whether the variable is null
Examples This example tests all the functions used to get the value of variables of type
Any, using PushLocalFrame and PopLocalFrame to simulate the scope of a
function call:
session->PushLocalFrame();
pbgroup vgroup = session->FindGroup("n_test",
pbgroup_userobject);
pbclass vcls = session->FindClass(vgroup, "n_test");
pbobject vobj = session->NewObject(vcls);
pbboolean isNull;
vfid = session->GetGlobalVarID("g_a");
value = session->GetPBAnyGlobalVar(vfid, isNull);
//Get the actual value here.
long dim = 1;
value = session->GetPBAnyArrayItem(arr, &dim, isNull);
//Get the actual value here.
session->PopLocalFrame();
Usage The value you retrieve must be of datatype Any to use this function; that is, the
variable associated with the function must be declared as a variable of type Any
in the development environment. If it is not, the function returns a null pointer
and the value of isNull is set to true.
This function returns a pointer to an IPB_Value instance. When it is called,
memory is allocated for the returned IPB_Value instance, and the pointer is
recorded in the current local frame. The pointer is deleted automatically when
the current local frame is popped, which occurs when the current local function
returns (you can also call PopLocalFrame to force the frame to be popped).
If you want to use the value returned, you must save the value pointed to by the
IPB_Value instance (not the IPB_Value instance itself) before the frame is
popped. If you save the pointer itself, the value is only valid until the original
value is destroyed.
You can use the AcquireValue function to save the value, or one of the
IPB_Value Get<type> functions. For example, the following code saves the
string value in the IPB_Value instance ivalue into the string str. The value in
str can be used after the local frame is popped and ivalue is deleted:
IPB_Value* ivalue = session->GetPBAnyField(vobj, vfid,
isNull);
pbstring str = ivalue->GetString();
If you do not know the actual datatype of the Any variable, use the IPB_Value
GetType function to get its datatype first, then use the appropriate get function
to get its value.
GetPBAnyGlobalVar
Description Obtains the value of a global variable of type Any.
Syntax GetPBAnyGlobalVar( pbfieldID fid, pbboolean& isNull )
Argument Description
fid The field ID of the variable
isNull Indicates whether the variable is null
GetPBAnySharedVar
Description Obtains the value of a shared variable of type Any.
Syntax GetPBAnySharedVar( pbgroup group, pbfieldID fid, pbboolean& isNull )
Argument Description
group The group to which the variable belongs
fid The field ID of the variable
isNull Indicates whether the variable is null
GetProp
Description Retrieves a pointer to the data value of a variable that has been registered as a
shared property for the current IPB session.
Syntax GetProp(LPCTSTR name)
Argument Description
name The name of the variable whose value is to be
retrieved.
Return value Void*. If the variable does not exist, returns null.
Examples See SetProp.
Usage The variable’s name must first be registered with the session using the SetProp
function.
See also RemoveProp
SetProp
GetResultSetAccessor
Description Obtains an interface through which you can read data from a result set.
Syntax GetResultSetAccessor (pbobject rs)
Argument Description
rs A pbobject holding a result set obtained using
CreateResultSet
GetSharedVarID
Description Returns the internal ID of a shared variable.
Syntax GettSharedVarID(pbgroup group, LPCTSTR fieldname)
Argument Description
group The group to which the shared variable belongs
fieldname The name of the field that contains the shared
variable, in lowercase
Examples This code uses GetSharedVarID to obtain the field ID of a shared variable, then
uses that ID to obtain the value of the variable:
curGroup = session -> GetCurrGroup();
fid = session -> GetSharedVarID(curGroup,"i_svar");
if (fid == 0xffff)
{
MessageBox(NULL, "Illegal fid!", "default", MB_OK);
return;
}
i_val = session -> GetIntSharedVar(curGroup, fid,
isNull);
See also Get<type>SharedVar
GetSharedVarType
IsSharedVarArray
IsSharedVarNull
IsSharedVarObject
Set<type>SharedVar
SetSharedVarToNull
GetSharedVarType
Description Obtains the datatype of the specified shared variable.
Syntax GetSharedVarType ( pbgroup group, pbfieldID fid )
Argument Description
group The group to which the shared variable belongs
fid The internal field ID of the shared variable
Return value pbuint. A simple datatype defined in the list of pbvalue_type enumerated types.
Examples This example gets the field ID of a shared variable, then uses that ID to get the
type of the shared variable:
pbuint pbvaltype;
curGroup = session -> GetCurrGroup();
fid = session -> GetSharedVarID(curGroup,"i_svar");
pbvaltype = session -> GetSharedVarType(curGroup, fid);
See also Get<type>SharedVar
GetSharedVarID
IsSharedVarArray
IsSharedVarNull
IsSharedVarObject
Set<type>SharedVar
SetSharedVarToNull
GetString
Description Returns a pointer to the string passed in as an argument.
Syntax GetString (pbstring* string)
Argument Description
string A pointer to a pbstring
Examples This example uses the IPB_Value GetString function to obtain a string value
from the PBCallInfo structure. If the string is not null, the IPB_Session
GetString function sets the value of the proxyname string to a pointer to the
returned value:
string proxyName;
{
pbstring pn = ci->pArgs->GetAt(2)->GetString();
if (pn == NULL)
{
ci->returnValue->SetLong(kInvalidProxyName);
return PBX_OK;
}
else
{
proxyName = session->GetString(pn);
}
}
Usage When you have finished using the string, call the ReleaseString method to free
the memory acquired.
See also GetStringLength
NewString
ReleaseString
SetString
GetStringLength
Description Returns the length of a string in bytes without the terminator.
Syntax GetStringLength (pbstring string)
Argument Description
string The pbstring whose length is to be determined
Examples These statements set the value of a pblong variable to the length of a string:
pblong long_val;
pbstring str_val;
long_val = session-> GetStringLength( str_val );
See also GetString
NewString
SetString
GetSuperClass
Description Returns the ancestor class of the specified class, if any.
Syntax GetSuperClass(pbclass cls)
Argument Description
cls A valid class handle for the descendent class
Examples These statements get the class of an object in the PBCallInfo structure, the
ancestor class of that class, and then the name of the ancestor class:
pbclass cls, cls_parent;
LPCSTR clsname;
GetSystemClass
Description Returns the first system class that the input class inherits from.
Syntax GetSystemClass (pbclass cls)
Argument Description
cls A descendent class whose ancestor system class is
to be determined
GetSystemGroup
Description Returns a PowerBuilder internal system group.
Syntax GetSystemGroup()
Return value pbclass or null on error.
GetTimeString
Description Converts data in a pbtime object to a string.
Syntax GetTimeString(pbtime time)
Argument Description
time The pbtime data object to be converted to a string.
HasExceptionThrown
Description Checks for the existence of an exception that has been thrown but not cleared.
Syntax HasExceptionThrown()
Return value pbboolean. Returns true if a PowerBuilder exception has been thrown but not
cleared.
Examples This example tests whether an exception has been thrown so it can be handled
and cleared:
try
{
session->InvokeObjectFunction(pbobj, mid, &ci);
// Was PB exception thrown?
if (session-> HasExceptionThrown())
{
// Handle PB exception
session-> ClearException();
}
}
See also ClearException
GetException
ThrowException
HasPBVisualObject
Description Determines whether any PowerBuilder windows, visible or hidden, are still in
existence.
Syntax HasPBVisualObject()
Return value pbboolean. Returns true if any PowerBuilder windows are still alive. If any
windows that are not response windows are still alive, the PowerBuilder
application returns immediately unless you manually add a message loop.
Examples This example is similar to the example for RestartRequested, but it includes a
call to HasPBVisualObject that opens a message loop if the return value is true:
PBXRESULT PB_MyWinAppRunner::RunApplication()
{
PBXRESULT res;
pbboolean restart = FALSE;
do
{
res = StartApplication();
if (res == PBX_OK)
// Process message dispatch
{
if ( GetSession()->HasPBVisualObject() )
{
MSG msg;
while ( GetMessage(&msg, 0, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if ( !GetSession()->HasPBVisualObject() )
break;
}
}
}
else
break;
restart = GetSession()->RestartRequested();
if (restart)
RecreateSession();
} while (restart);
return CleanApplication();
}
InitCallInfo
Description Initializes the PBCallInfo structure.
Syntax InitCallInfo(pbclass cls, pbmethodID mid, PBCallInfo *ci)
Argument Description
cls The pbclass containing the method
mid The pbMethodID returned by GetMethodID
ci A pointer to a preallocated PBCallInfo structure
PBCallInfo ci;
d_session->InitCallInfo(clz, mid, &ci);
d_session->TriggerEvent(d_pbobj, mid, &ci);
d_session->FreeCallInfo(&ci);
}
Usage On return, this method allocates enough space for the arguments, and then
initializes the arguments and return value. You must set appropriate values in
the PBCallInfo structure. Note that the structure itself must have been allocated
before the call.
See also FreeCallInfo
InvokeClassFunction
Description Invokes system or user global functions.
Syntax InvokeClassFunction(pbclass cls, pbmethodID mid, PBCallInfo *ci)
Argument Description
cls The class that contains the global function. If this is
a system function, cls is obtained with
GetSystemFunctionsClass; otherwise, it is
obtained with FindGroup and FindClass, with the
function name as the group/class name.
mid The pbMethodID returned by GetMethodID.
ci A pointer to a preallocated PBCallInfo structure.
Return value PBXRESULT. Returns PBX_OK for success, or one of the following for
failure:
PBX_E_INVALID_ARGUMENT
PBX_E_INVOKE_METHOD_INACCESSABLE
PBX_E_INVOKE_WRONG_NUM_ARGS
PBX_E_INVOKE_REFARG_ERROR
PBX_E_INVOKE_METHOD_AMBIGUOUS
PBX_E_INVOKE_FAILURE
PBX_E_INVOKE_FAILURE
Examples This example gets the PowerBuilder system class and uses it to invoke the
double function:
InvokeObjectFunction
Description Invokes a class member method.
Syntax InvokeObjectFunction(pbobject obj, pbmethodID mid, PBCallInfo *ci)
Argument Description
obj The pbobject containing the method
mid The pbMethodID returned by GetMethodID
ci A pointer to a preallocated PBCallInfo structure
Return value PBXRESULT. Returns PBX_OK for success, or one of the following for
failure:
PBX_E_INVALID_ARGUMENT
PBX_E_INVOKE_METHOD_INACCESSABLE
PBX_E_INVOKE_WRONG_NUM_ARGS
PBX_E_INVOKE_REFARG_ERROR
PBX_E_INVOKE_METHOD_AMBIGUOUS
PBX_E_INVOKE_FAILURE
PBX_E_INVOKE_FAILURE
Examples This code invokes the DataWindow Update function and returns its integer
return value:
pbclass cls;
pbmethodID mid;
PBCallInfo* ci = new PBCallInfo;
pbint ret_val;
cls = session->GetClass(dwobj);
mid = session->GetMethodID
(cls, "Update", PBRT_FUNCTION, "I");
session->InitCallInfo(cls, mid, ci);
ret_val = ci.returnValue->GetInt();
session->FreeCallInfo(ci);
delete ci;
return ret_val;
See also InvokeClassFunction
IsArrayItemNull
Description Returns true if the array item contains a null value; otherwise it returns false.
Syntax IsArrayItemNull( pbarray array, pblong dim[ ])
Argument Description
array A valid pbarray structure that you want to check for
a null-valued array item.
dim A pblong array to hold the indexes of each
dimension of the array. The size of the array must
equal the dimensions of array.
IsAutoInstantiate
Description Returns true if the specified class is an autoinstantiated class; otherwise it
returns false.
Syntax IsAutoInstantiate(pbclass)
Argument Description
cls A valid class handle or structure
IsFieldArray
Description Returns true if the field of the specified object is an array; otherwise it returns
false.
Argument Description
cls A valid class handle for the class whose field is to be
accessed
fid The field ID of the specified object
Examples This code tests whether the field identified by fid is an array, and if so, gets the
array value:
fid = session->GetFieldID(cls, "arr_val");
if (session->IsFieldArray(cls, fid))
{
arr_val=session->GetArrayField(myobj, fid, isNull);
...
See also GetFieldID
GetFieldType
Get<type>Field
GetNumOfFields
IsFieldNull
IsFieldObject
SetFieldToNull
Set<type>Field
IsFieldNull
Description Returns true if the field of the specified object is a null value; otherwise it
returns false.
Syntax IsFieldNull(pbobject obj, pbfield fid)
Argument Description
obj A valid object handle for the object whose field is to
be accessed
fid The field ID of the specified object
Examples These statements test whether the field identified by fid is null:
fid = session -> GetFieldID(cls, "i_val");
if (session -> IsFieldNull(myobj, fid))
See also GetFieldID
GetFieldType
Get<type>Field
GetNumOfFields
IsFieldArray
IsFieldObject
SetFieldToNull
Set<type>Field
IsFieldObject
Description Returns true if the field of the specified object is an object; otherwise it returns
false.
Argument Description
cls A valid class handle for the class whose field is to be
accessed
fid The field ID of the specified object
Examples These statements test whether the field identified by fid is an object:
fid = session -> GetFieldID(cls, "obj_val");
if (session -> IsFieldObject(myobj, fid))
See also GetFieldID
GetFieldType
Get<type>Field
GetNumOfFields
IsFieldArray
IsFieldNull
SetFieldToNull
Set<type>Field
IsGlobalVarArray
Description Returns true if the global variable contains an array; otherwise it returns false.
Syntax IsGlobalVarArray(pbfield fid)
Argument Description
fid The field ID of the global variable
IsGlobalVarNull
Description Returns true if the global variable contains a null value; otherwise it returns
false.
Argument Description
fid The field ID of the global variable
Examples These statements test whether the field identified by fid is a global variable
array:
fid = session -> GetGlobalVarID("arr_gvar");
if (session -> IsGlobalVarArray(fid))
{
arr_val=session -> GetArrayGlobalVar(fid, isNull);
...
See also GetGlobalVarID
GetGlobalVarType
Get<type>GlobalVar
IsGlobalVarArray
IsGlobalVarObject
SetGlobalVarToNull
Set<type>GlobalVar
IsGlobalVarObject
Description Returns true if the global variable contains an object; otherwise it returns false.
Syntax IsGlobalVarObject( pbfield fid)
Argument Description
fid The field ID of the global variable
Examples These statements test whether the field identified by fid is a global variable
object. If it is, its value is set to another global variable object:
fid = session -> GetGlobalVarID("obj2_gvar");
if (session -> IsGlobalVarObject(fid))
{
obj_val = session -> GetObjectGlobalVar(fid,
isNull);
cls = session -> GetClass(obj_val);
fid = session -> GetFieldID(cls, "text");
s_val = session -> GetStringField(obj_val, fid,
isNull);
mystr = session -> GetString(s_val);
// Set the value of obj2_gvar to obj1_gvar
fid = session -> GetGlobalVarID("obj1_gvar");
session -> SetObjectGlobalVar(fid, obj_val);
}
See also GetGlobalVarID
GetGlobalVarType
Get<type>GlobalVar
IsGlobalVarArray
IsGlobalVarNull
SetGlobalVarToNull
Set<type>GlobalVar
IsNativeObject
Description Determines whether a pbobject is an instance of a native class.
Syntax IsNativeObject(pbobject obj)
Argument Description
obj A valid object handle
IsSharedVarArray
Description Returns true if the shared variable contains an array; otherwise it returns false.
Syntax IsSharedVarArray(pbgroup group, pbfield fid)
Argument Description
group The group whose shared variable is to be accessed
fid The field ID of the shared variable
IsSharedVarNull
Description Returns true if the shared variable contains a null value; otherwise it returns
false.
Argument Description
group The group whose shared variable is to be accessed
fid The field ID of the shared variable
IsSharedVarObject
Description Returns true if the shared variable contains an object; otherwise it returns false.
Syntax IsSharedVarObject(pbgroup group, pbfield fid)
Argument Description
group The group whose shared variable is to be accessed
fid The field ID of the shared variable
NewBlob
Description Creates a new blob and duplicates a buffer for the new blob data.
Syntax NewBlob (const void* bin, pblong len)
Argument Description
bin A void pointer that points to the source buffer
len The length in bytes of the data in the buffer
NewBoundedObjectArray
Description Creates a bounded PowerBuilder object or structure array.
Syntax NewBoundedObjectArray(pbclass cls, pbuint dimension,
PBArrayInfo::ArrayBound* bounds)
Argument Description
cls A valid class handle of the type of PowerBuilder
object or structure array to be created
dimension A number greater than one that indicates the
dimension of the array to be created
bounds An array containing the upper and lower boundaries
of the array to be created
size = sizeof(PBArrayInfo) +
sizeof(PBArrayInfo::ArrayBound);
ai = (PBArrayInfo*)malloc(size);
ai-> bounds[0].upperBound=2;
ai-> bounds[0].lowerBound=1;
ai-> bounds[1].upperBound=2;
ai-> bounds[1].lowerBound=1;
ai-> numDimensions=2;
IsArrayItemNull
NewBoundedSimpleArray
NewUnboundedObjectArray
NewUnboundedSimpleArray
ReleaseArrayInfo
Set<type>ArrayItem
SetArrayItemToNull
SetArrayItemValue
NewBoundedSimpleArray
Description Creates a bounded simple data array.
Syntax NewBoundedSimpleArray(pbuint type, pbuint dimension,
PBArrayInfo::ArrayBound* bounds)
Argument Description
type An enumerated variable of type pbvalue_*
indicating the type of simple unbounded array to be
created
dimension A number greater than one that indicates the
dimension of the array to be created
bounds An array containing the upper and lower boundaries
of the array to be created
NewDate
Description Creates a new pbdate data object.
Syntax NewDate()
Return value pbdate.
Examples This example tests whether a date value exists, and, if it does not, it creates a
new pbdate object and sets its value to the first day in January, 1900:
if (ci->pArgs->GetAt(0)->IsNull())
{
pArguments[i].date_val = Session->NewDate();
Session->SetDate(pArguments[i].date_val,
1900,1,1); // Date: 1900-01-01
isNull[i]=true;
}
else
{
pArguments[i].date_val =
ci->pArgs->GetAt(i)->GetDate();
isNull[i]=false;
}
Usage The initial value is 1900-1-1.
See also SetDate
SplitDate
NewDateTime
Description Creates a new pbdatetime data object.
Syntax NewDateTime()
Return value pbdatetime.
Examples This example tests whether a date/time value exists, and, if it does not, it
creates a new pbdate object and sets its value to the beginning of January, 1900:
if (ci->pArgs->GetAt(i)->IsNull())
{
pArguments[i].datetime_val=Session->NewDateTime();
Session->SetDateTime(pArguments[i].datetime_val,
1900, 1 , 1, 1, 1, 1); // Datetime:
// 1900-01-01 01:01:01
}
else
{
pArguments[i].datetime_val =
ci->pArgs->GetAt(i)->GetDateTime();
}
Usage The initial value is 1900-1-1 0:0:0.0.
See also SetDateTime
SplitDateTime
NewDecimal
Description Allocates resources for a new decimal data object.
Syntax NewDecimal( )
Return value pbdec or null on failure.
Examples if (ci->pArgs->GetAt(i)->IsNull())
{
pArguments[i].dec_val=Session->NewDecimal();
Session->SetDecimal(pArguments[i].dec_val,"1.0");
}
else
pArguments[i].dec_val =
ci->pArgs->GetAt(i)->GetDecimal();
See also GetDecimalString
ReleaseDecimalString
SetDecimal
NewObject
Description Creates a new object of the specified type.
Syntax NewObject(pbclass cls)
Argument Description
cls The type of object or structure instance to be created
NewProxyObject
Description Creates a proxy for a remote object. The proxy is used to extend the network
protocol in PowerBuilder.
Syntax NewProxyObject(pbclass cls)
Argument Description
cls The type of object or structure instance to be created
Examples This example creates a new proxy object, creates a marshaler, and associates
the marshaler with the proxy object:
pbproxyObject proxy = session->NewProxyObject(cls);
if (proxy == NULL)
{
ci->returnValue->SetLong(kFailToCreateProxy);
return PBX_OK;
}
// Create MyMarshaler
MyMarshaler* marshaler = new MyMarshaler(env,
proxy, obj);
ci->pArgs->GetAt(0)->SetObject(proxy);
ci->returnValue->SetLong(kSuccessful);
return PBX_OK;
See also GetMarshaler
SetMarshaler
NewString
Description Creates a new string.
Syntax NewString(LPCTSTR)
Return value pbstring.
cls = session->GetSystemFunctionsClass();
if( cls == NULL )
{
ret_val = session->NewString("null");
return ret_val;
}
Usage The returned string is destroyed when PopLocalFrame is called.
See also SetString
NewTime
Description Creates a new pbtime data object.
Syntax NewTime()
Return value pbtime.
Examples These statements split a time into hours, minutes, and seconds, and then use the
resulting values to set the value of a new time object:
Session->SplitTime(ci.returnValue->GetTime(), &hh,
&mm, &ss);
ret_val = Session-> NewTime();
Session-> SetTime(ret_val, hh, mm, ss);
Usage The initial value is 0:0:0.0.
See also SetTime
SplitTime
NewUnboundedObjectArray
Description Creates an unbounded PowerBuilder object or structure data array.
Syntax NewUnboundedObjectArray(pbclass cls)
Argument Description
cls A valid class handle of the type of PowerBuilder
object or structure array to be created
NewUnboundedSimpleArray
Description Creates an unbounded simple data array.
Syntax NewUnboundedSimpleArray(pbuint type)
Argument Description
type An enumerated variable of type pbvalue_*
indicating the type of simple unbounded array to be
created
Examples This example creates an unbounded simple data array of the type returned by
the getDataType method, which returns a string of the form dt_type. Most of
the case statements have been removed for the sake of brevity:
if (d_returnType.isArray())
{
returnValue.l = env->CallObjectMethodA(obj,
mid, values.get());
pbarray v;
switch(d_returnType.getDataType())
{
case dt_boolean:
v = session->NewUnboundedSimpleArray
(pbvalue_boolean);
break;
case dt_short:
v = session->NewUnboundedSimpleArray
(pbvalue_int);
break;
// CASE statements omitted
...
default:
v = session->NewUnboundedSimpleArray
(pbvalue_any);
break;
}
ci->returnValue->SetArray(v);
Usage An unbounded array can have only one dimension, so no dimension
information is needed.
PopLocalFrame
Description Pops the current local reference frame from the current native method stack
frame, removing all local references to the objects added in that local frame.
All the pbobject, pbstring, and pbdecimal variables created by calling
NewDecimal, NewObject, or NewString in the current frame are destroyed
automatically.
Syntax PopLocalFrame()
Return value None.
See also AddLocalRef
PushLocalFrame
RemoveLocalRef
ProcessPBMessage
Description Checks the PowerBuilder message queue and, if there is a message in the
queue, attempts to process it.
Syntax ProcessPBMessage()
Return value pbboolean. Returns true if a PowerBuilder message was processed, and false
otherwise.
// Call to ProcessPBMessage
if (session)
session->ProcessPBMessage();
}
This overloaded WindowProc function in an MFC application processes a
PowerBuilder message:
LRESULT CCallPBVCtrl::WindowProc(UINT message,
WPARAM wParam, LPARAM lParam)
{
d_session->ProcessPBMessage();
return CDialog::WindowProc(message, wParam, lParam);
}
Usage Each time this function is called, it attempts to retrieve a message from the
PowerBuilder message queue and process it. It is similar to the PowerBuilder
Yield function; however, ProcessPBMessage processes only one message at a
time, and it processes only PowerBuilder messages. The Yield function also
processes Windows messages.
Use this function when PowerBuilder windows or visual controls are called
from C++ applications or from extensions to ensure that events posted to the
PowerBuilder message queue are processed.
If the function is not inserted in the C++ application in a way that results in it
being called repeatedly, posted events are not processed in the PowerBuilder
application.
For most applications, ProcessPBMessage can be inserted in a message loop in
the WinMain function. If you use Microsoft Foundation Classes (MFC), you
cannot modify the built-in message loop. To ensure that the
ProcessPBMessage function is called repeatedly, you can overload the
CWnd::WindowProc function and insert ProcessPBMessage into the overloaded
function.
PushLocalFrame
Description Pushes a local reference frame onto the current native method stack frame. A
local frame is analogous to a scope in C++.
Syntax PushLocalFrame()
Return value None.
See also PopLocalFrame
RemoveLocalRef
Release
Description Releases the current IPB_Session. The IPB_Session object becomes invalid
after the call.
Syntax Release()
Return value None.
Examples This example shows a call to Release. The example checks whether there is a
valid session object before attempting to release it:
if (pIPB_ObjectFactory)
{
pIPB_ObjectFactory->Release();
pIPB_ObjectFactory = NULL;
}
ReleaseArrayInfo
Description Releases memory returned by GetArrayInfo.
Syntax ReleaseArrayInfo(PBArrayInfo* pbarrayinfo)
Argument Description
pbarrayinfo A valid PBArrayInfo handle
ReleaseDateString
Description Frees the memory acquired using GetDateString.
Syntax ReleaseDateString(LPCTSTR string)
Argument Description
string The string to be released from memory
ReleaseDateTimeString
Description Frees the memory acquired using GetDateTimeString.
Syntax ReleaseDateTimeString(LPCTSTR string)
Argument Description
string The string to be released from memory
ReleaseDecimalString
Description Frees the memory acquired using GetDecimalString.
Syntax ReleaseDecimalString(LPCTSTR string)
Argument Description
string The string to be released from memory
ReleaseResultSetAccessor
Description Releases the pointer obtained using GetResultSetAccessor.
Syntax ReleaseResultSetAccessor (IPB_ResultSetAccessor* rs)
Argument Description
rs A pointer to the IPB_ResultSetAccessor object to be
released
ReleaseString
Description Frees the memory acquired using GetString, GetClassName, GetFieldName, or
GetEnumItemName.
Argument Description
string The string to be released from memory
pStr1=session-> GetString(arg1);
pStr2=session-> GetString(arg2);
_tcscpy(tmp,pStr1);
_tcscat(tmp,pStr2);
ret = session -> NewString(tmp);
session-> ReleaseString(pStr1);
session-> ReleaseString(pStr2);
return ret ;
}
Usage Do not use this function to release a string obtained using GetDateString,
GetTimeString, GetDateTimeString, or GetDecimalString. Each of these Get
methods has a corresponding Release method.
See also GetClassName
GetEnumItemName
GetFieldName
GetString
ReleaseTimeString
Description Frees the memory acquired using GetTimeString.
Syntax ReleaseTimeString(LPCTSTR string)
Argument Description
string The string to be released from memory
ReleaseValue
Description Frees the IPB_Value acquired using AcquireValue or AcquireArrayItemValue.
Syntax ReleaseValue(IPB_Value* value)
Argument Description
value The string to be released from memory
Usage When you no longer need the data acquired using the AcquireValue or
AcquireArrayItemValue method, you must call the ReleaseValue method to free
the data. Failing to do so causes a memory leak.
Warning! Do not use ReleaseValue to release a value that was not acquired
using AcquireValue or AcquireArrayItemValue. If you do, the PowerBuilder VM
might crash.
RemoveGlobalRef
Description Removes a global reference to the specified PowerBuilder object.
Syntax RemoveGlobalRef (pbobject obj)
Argument Description
obj A valid PowerBuilder object handle
void MyPBNIClass::unreference()
{
if(d_pbobject != NULL)
d_session -> RemoveGlobalRef(d_pbobject);
}
See also AddGlobalRef
RemoveLocalRef
Description Removes a local reference to the specified PowerBuilder object.
Syntax RemoveLocalRef (pbobject obj)
Argument Description
obj A valid PowerBuilder object handle
RemoveProp
Description Removes the specified variable from the list of properties of the current IPB
session. You must free the memory to which the property points.
Syntax RemoveProp(LPCTSTR name)
Argument Description
name The name of the variable to be removed
RestartRequested
Description Determines whether the PowerBuilder system function Restart has been called.
Syntax HasPBVisualObject()
Return value pbboolean. Returns true when the PowerBuilder system function Restart is
called. When RestartRequested returns true, you should destroy the existing
IPB_Session object and create a new one to restart the application.
Examples In the following example, StartApplication, RecreateSession, and
CleanApplication are functions of the PB_MyConsoleAppRunner class.
StartApplication is similar to the IP_VM RunApplication function, but it uses an
existing session. RecreateSession releases the current session and creates a
new one. CleanApplication triggers the application’s Close event and releases
resources. In the example, RestartRequested is called in a DO loop to test
whether the PowerBuilder Restart function has been called. If it has, the
RecreateSession function is called:
PBXRESULT PB_MyConsoleAppRunner::RunApplication()
{
PBXRESULT res;
pbboolean restart = FALSE;
do
{
res = StartApplication();
if (res != PBX_OK)
break;
restart = GetSession()->RestartRequested();
if (restart)
RecreateSession();
} while (restart);
return CleanApplication();
}
Usage RestartRequested and HasVisualPBObject are used in the implementation of the
IPB_VM RunApplication function. You no longer need to use an external
message loop to check for Windows messages when you call the
RunApplication function as you did in versions of PBNI prior to PowerBuilder
10.5.
See also HasPBVisualObject
RunApplication
Set<type>ArrayItem
Description Assigns a value to an array item of a specific type.
Syntax SetBlobArrayItem ( pbarray array, pblong dim[ ], pbblob value )
SetBoolArrayItem ( pbarray array, pblong dim[ ], pbboolean value )
SetByteArrayItem ( pbarray array, pblong dim[ ], pbbyte value )
SetCharArrayItem ( pbarray array, pblong dim[ ], pbchar value )
SetDateArrayItem ( pbarray array, pblong dim[ ], pbdate value )
SetDateTimeArrayItem ( pbarray array, pblong dim[ ], pbdatetime value )
SetDecArrayItem ( pbarray array, pblong dim[ ], pbdec value )
SetDoubleArrayItem ( pbarray array, pblong dim[ ], pbdouble value )
SetIntArrayItem ( pbarray array, pblong dim[ ], pbint value )
SetLongArrayItem ( pbarray array, pblong dim[ ], pblong value )
SetLongLongArrayItem ( pbarray array, pblonglong dim[ ], pblong value )
SetObjectArrayItem ( pbarray array, pblong dim[ ], pbobject obj )
SetPBStringArrayItem ( pbarray array, pblong dim[ ], pbstring value )
SetRealArrayItem ( pbarray array, pblong dim[ ], pbreal value )
SetStringArrayItem ( pbarray array, pblong dim[ ], LPCTSTR value )
SetTimeArrayItem ( pbarray array, pblong dim[ ], pbtime value )
SetUintArrayItem ( pbarray array, pblong dim[ ], pbuint value )
SetUlongArrayItem ( pbarray array, pblong dim[ ], pbulong value )
Argument Description
array A valid pbarray handle.
dim A pblong array to hold indexes of each dimension.
The number of dimensions must equal the number
of dimensions of the array.
value The new value of the array item.
pblong dim[1];
char * cstr;
pbuint numDimensions = 1;
PBArrayInfo::ArrayBound bound;
bound.lowerBound = 1;
bound.upperBound = size;
d_pbarray = d_session->NewBoundedSimpleArray
(pbvalue_string, numDimensions, &bound);
delete [] cstr;
}
pbv.SetArray(d_pbarray);
Usage This method assigns the IPB_Value pointed to by the value argument to the
array item in the same way that the IPB_Value Set<type> method sets a value.
See also Get<type>ArrayItem
GetArrayInfo
GetArrayItemType
GetArrayLength
IsArrayItemNull
NewBoundedObjectArray
NewBoundedSimpleArray
NewUnboundedObjectArray
NewUnboundedSimpleArray
ReleaseArrayInfo
SetArrayItemToNull
SetArrayItemValue
Set<type>Field
Description A set of methods that set a new value in an instance field of an object.
Syntax SetArrayField ( pbobject obj, pbfieldID fid, pbarray value )
SetBlobField ( pbobject obj, pbfieldID fid, pbblob value )
SetBoolField ( pbobject obj, pbfieldID fid, pbboolean value )
SetByteField ( pbobject obj, pbfieldID fid, pbbyte value )
SetCharField ( pbobject obj, pbfieldID fid, pbchar value )
SetDateField ( pbobject obj, pbfieldID fid, pbdate value )
SetDateTimeField ( pbobject obj, pbfieldID fid, pbdatetime value )
SetDecField ( pbobject obj, pbfieldID fid, pbdec value )
SetDoubleField ( pbobject obj, pbfieldID fid, pbdouble value )
SetIntField ( pbobject obj, pbfieldID fid, pbint value )
SetLongField ( pbobject obj, pbfieldID fid, pblong value )
SetLongLongField ( pbobject obj, pbfieldID fid, pblonglong value )
SetObjectField ( pbobject obj, pbfieldID fid, pbobject value )
SetPBStringField ( pbobject obj, pbfieldID fid, pbstring value )
SetRealField ( pbobject obj, pbfieldID fid, pbreal value )
SetStringField ( pbobject obj, pbfieldID fid, LPCTSTR value )
SetTimeField ( pbobject obj, pbfieldID fid, pbtime value )
SetUintField ( pbobject obj, pbfieldID fid, pbuint value )
SetUlongField ( pbobject obj, pbfieldID fid, pbulong value )
Argument Description
obj The handle of the object whose field is to be
accessed
fid The field ID of the specified object
value The value to be set
Usage When you change any visual property of a PowerBuilder object by calling
Set<type>field functions, the property is changed but the property is not
refreshed in the graphical user interface. UpdateField refreshes the visual
properties of PowerBuilder objects. You must call UpdateField explicitly when
changing any visual property with the Set<type>field functions.
See also GetFieldID
GetFieldType
Get<type>Field
GetNumOfFields
IsFieldArray
IsFieldNull
IsFieldObject
SetFieldToNull
UpdateField
Set<type>GlobalVar
Description A set of methods that set the value of a global variable of a specific datatype.
Syntax SetArrayGlobalVar ( pbfieldID fid, pbarray value )
SetBlobGlobalVar ( pbfieldID fid, pbblob value )
SetBoolGlobalVar ( pbfieldID fid, pbboolean value )
SetByteGlobalVar ( pbfieldID fid, pbbyte value )
SetCharGlobalVar ( pbfieldID fid, pbchar value )
SetDateGlobalVar ( pbfieldID fid, pbdate value )
SetDateTimeGlobalVar ( pbfieldID fid, pbdatetime value )
SetDecGlobalVar ( pbfieldID fid, pbdec value )
SetDoubleGlobalVar ( pbfieldID fid, pbdouble value )
SetIntGlobalVar ( pbfieldID fid, pbint value )
SetLongGlobalVar( pbfieldID fid, pblong value )
SetLongLongGlobalVar( pbfieldID fid, pblonglong value )
SetObjectGlobalVar ( pbfieldID fid, pbobject value )
SetPBStringGlobalVar ( pbfieldID fid, pbstring value )
SetRealGlobalVar ( pbfieldID fid, pbreal value )
SetStringGlobalVar ( pbfieldID fid, LPCTSTR value )
SetTimeGlobalVar ( pbfieldID fid, pbtime value )
SetUintGlobalVar ( pbfieldID fid, pbuint value )
SetUlongGlobalVar ( pbfieldID fid, pbulong value )
Argument Description
fid The field ID of the global variable
value The value to be set
Set<type>SharedVar
Description A set of methods that set the value of a shared variable of a specific datatype.
Syntax SetArraySharedVar ( pbgroup group, pbfieldID fid, pbarray value )
SetBlobSharedVar ( pbgroup group, pbfieldID fid, pbblob value )
SetBoolSharedVar ( pbgroup group, pbfieldID fid, pbboolean value )
SetByteSharedVar ( pbgroup group, pbfieldID fid, pbbyte value )
SetCharSharedVar ( pbgroup group, pbfieldID fid, pbchar value )
SetDateSharedVar ( pbgroup group, pbfieldID fid, pbdate value )
SetDateTimeSharedVar ( pbgroup group, pbfieldID fid, pbdatetime value )
SetDecSharedVar ( pbgroup group, pbfieldID fid, pbdec value )
SetDoubleSharedVar ( pbgroup group, pbfieldID fid, pbdouble value )
SetIntSharedVar ( pbgroup group, pbfieldID fid, pbint value )
SetLongSharedVar( pbgroup group, pbfieldID fid, pblong value )
SetLongLongSharedVar( pbgroup group, pbfieldID fid, pblonglong value )
SetObjectSharedVar ( pbgroup group, pbfieldID fid, pbobject value )
SetPBStringSharedVar ( pbgroup group, pbfieldID fid, pbstring value )
SetRealSharedVar ( pbgroup group, pbfieldID fid, pbreal value )
SetStringSharedVar ( pbgroup group, pbfieldID fid, LPCTSTR value )
SetTimeSharedVar ( pbgroup group, pbfieldID fid, pbtime value )
SetUintSharedVar ( pbgroup group, pbfieldID fid, pbuint value )
SetUlongSharedVar ( pbgroup group, pbfieldID fid, pbulong value )
Argument Description
group The group whose shared variable is to be accessed
fid The field ID of the shared variable
value The value to be set
SetArrayItemToNull
Description Sets the value of an array item to a null value.
Syntax SetArrayItemToNull( pbarray array, pblong dim[ ])
Argument Description
array A valid pbarray structure in which you want to set
an array item to null.
dim A pblong array to hold the indexes of each
dimension of the array. The size of the array must
equal the dimensions of array.
SetArrayItemValue
Description Sets the value of an array item to the value of an IPB_Value.
Syntax SetArrayItemValue( pbarray array, pblong dim[ ], IPB_Value* src)
Argument Description
array A valid pbarray structure in which you want to set
an array item to null.
dim A pblong array to hold the indexes of each
dimension of the array. The size of the array must
equal the dimensions of array.
src The value to which the array item is to be changed.
SetBlob
Description Destroys the existing data in a blob and copies data into it from a buffer.
Syntax SetBlob (pbblob blb, const void* bin, pblong len)
Argument Description
blb A valid pbblob object whose value is to be reset
bin A pointer to the source buffer
len The length in bytes of the data in the buffer
SetDate
Description Resets the value of the specified pbdate object.
Syntax SetDate (pbdate date, pbint year, pbint month, pbint day)
Argument Description
date The pbdate object to be reset
year A year in the range 1000 to 3000
month A month in the range 1 to 12
day A day in the range 1 to 31
SetDateTime
Description Resets the value of the specified pbdatetime object.
Syntax SetDate (pbdatetime dt, pbint year, pbint month, pbint day, pbint hour, pbint
minute, pbdouble second)
Argument Description
dt The pbdatetime object to be reset
year A year in the range 1000 to 3000
month A month in the range 1 to 12
day A day in the range 1 to 31
hour An hour in the range 0 to 23
minute A minute in the range 0 to 59
second A second in the range 0 to 59.999999
SetDecimal
Description Sets the value of a decimal variable to decimal data in a string.
Syntax SetDecimal(pbdec dec, LPCTSTR dec_str)
Argument Description
dec The decimal data object to be set
dec_str The string containing the data to be converted to a
decimal
...
pbdecRet = session -> NewDecimal();
session -> SetDecimal( pbdecRet,
(LPCTSTR)lpDecValueToReturn);
ci -> returnValue -> SetDecimal(pbdecRet);
Usage If the string contains invalid data, the decimal value is set to 0.0.
See also GetDecimalString
NewDecimal
ReleaseDecimalString
SetFieldToNull
Description Sets the value of the specified field to null.
Syntax SetFieldToNull(pbobject obj, pbfield fid)
Argument Description
obj A valid object handle
fid The field ID of the specified object
SetGlobalVarToNull
Description Sets the value of the specified global variable to null.
Syntax SetGlobalVarToNull(pbobject obj, pbfield fid)
Argument Description
fid The field ID of the global variable
SetMarshaler
Description Sets a marshaler that will be used to invoke remote methods and convert
PowerBuilder data formats to the user’s communication protocol.
Syntax SetMarshaler(pbproxyObject obj, IPBX_Marshaler* marshaler)
Argument Description
obj An object of type pbproxyObject to be used as a
proxy for a remote object that was created using
NewProxyObject
marshaler A class inherited from IPBX_Marshaler
ci->pArgs->GetAt(0)->SetObject(proxy);
ci->returnValue->SetLong(kSuccessful);
return PBX_OK;
Usage The SetMarshaler function associates an object of type IPBX_Marshaler with
a PBProxy object. It is possible to associate multiple marshaler objects with a
single proxy object. It is also possible to associate one marshaler object with
multiple proxy objects. Neither of these is good coding practice and should be
avoided.
Before calling SetMarshaler, you can call the IPB_Session GetMarshaler
function to obtain an existing marshaler object associated with a given proxy
object, and then destroy the existing marshaler object before associating a new
marshaler with the proxy.
When a proxy object is destroyed, it calls the associated marshaler object's
Destroy method. If multiple proxy objects are associated with a single
marshaler object, you need to implement some form of reference counting.
Otherwise, the marshaler object is destroyed when the first associated proxy
object is destroyed, and subsequent calls to the marshaler object's Destroy
method, when other associated proxy objects are destroyed, will throw
exceptions.
SetProp
Description Adds a new variable to the list of properties of the current session or changes
the value of an existing variable.
Syntax SetProp(LPCTSTR name, void* data)
Argument Description
name The name of the property to be set
data A pointer to the data buffer where the variable’s
value resides
if (mid == mid_SetProp)
{
*SetValue = ci -> pArgs -> GetAt(0) -> GetInt();
session -> SetProp(prop_name, SetVal);
}
When the f_getprop function is called, the following code uses GetProp to set
the GetValue pointer to point to the value associated with prop_name, and then
sets the return value to *GetValue:
if (mid == mid_GetProp)
{
int* GetVal;
GetValue = (int *)session -> GetProp(prop_name);
ci -> returnValue -> SetInt(*GetVal);
}
Usage SetProp enables you to use a variable value throughout an IPB session without
using a global variable, which is susceptible to namespace conflicts with other
sessions. SetProp is one of a set of three functions:
• Use SetProp to register a new variable with the session or to change the
value of an existing variable.
• Use GetProp to access the variable.
• Use RemoveProp to remove the variable from the list of variables
associated with the session when it is no longer needed.
This set of functions is particularly useful for working with multiple threads of
execution in EAServer.
Suppose you want to throw an exception from within a PBNI extension and the
exception itself is also defined by the PBNI extension. You call the
IPB_Session NewObject function to create an instance of the exception,
causing the PBX_CreateNonVisualObject function to be called.
One way to set the value of the fields of the exception before the function
returns in a thread-safe manner is to create a new object or structure to hold the
exception information before calling NewObject. You can call SetProp to store
the structure or the object in the current IPB_Session. When
PBX_CreateNonVisualObject is called, you can call GetProp to get the structure
or object to obtain the exception information, then call RemoveProp to remove
the data you stored in the current session.
See also GetProp
RemoveProp
SetSharedVarToNull
Description Sets the value of the specified shared variable to null.
Syntax SetSharedVarToNull(pbgroup group, pbfield fid)
Argument Description
group The group to which the shared variable belongs
fid The field ID of the shared variable
SetString
Description Frees an existing string and assigns a new string value to it by performing a
deep copy.
Syntax SetString (pbstring string, LPCTSTR src)
Argument Description
string A valid pbstring variable whose value is to be
replaced
src The string to be assigned to string
Examples This example uses the IPB_Session SetString method to set the ret_val string to
the return value in the PBCallInfo structure. It also uses the IPB_Value
SetPBString method to set values in PBCallInfo:
pbclass cls;
pbmethodID mid;
PBCallInfo* ci = new PBCallInfo;
pbstring ret_val;
LPCTSTR pStr;
SetTime
Description Resets the value of the specified pbtime object.
Syntax SetTime (pbtime time, pbint hour, pbint minute, pbdouble second)
Argument Description
time The pbtime object to be reset
hour An hour in the range 0 to 23
minute A minute in the range 0 to 59
second A second in the range 0 to 59.999999
SetValue
Description Sets the value of one IPB_Value object to the value of another IPB_Value
object.
Syntax SetValue( IPB_Value* dest, IPB_Value* src)
Argument Description
dest The value to be replaced
src The value to which dest is to be changed
SplitDate
Description Splits the specified pbdate object into a year, month, and day.
Syntax SplitDate (pbdate date, pbint *year, pbint *month, pbint *day)
Argument Description
date The pbdate object to be split
year A year in the range 1000 to 3000
month A month in the range 1 to 12
day A day in the range 1 to 31
SplitDateTime
Description Splits the specified pbdatetime object into a year, month, day, hour, minute, and
second.
Syntax SplitDateTime(pbdatetime dt, pbint *year, pbint *month, pbint *day, pbint
*hour, pbint *minute, pbdouble *second)
Argument Description
dt The pbdatetime object to be split
year A year in the range 1000 to 3000
month A month in the range 1 to 12
day A day in the range 1 to 31
hour An hour in the range 0 to 23
minute A minute in the range 0 to 59
second A second in the range 0 to 59.999999
SplitTime
Description Splits the specified time object into an hour, minute, and second.
Syntax SplitTime(pbtime time, pbint *hour, pbint *minute, pbdouble *second)
Argument Description
time The pbtime object to be split
hour An hour in the range 0 to 23
minute A minute in the range 0 to 59
second A second in the range 0 to 59.999999
ThrowException
Description Throws a PowerBuilder exception or inherited exception, and replaces the
existing exception if there is one.
Syntax ThrowException (pbobject ex)
Argument Description
ex The exception to be thrown. The exception must
first be created with NewObject.
// Throw exception
group = session-> FindGroup("user_exception_pspp",
pbgroup_userobject);
if (group==NULL)
return;
cls = session->FindClass(group, "user_exception_pspp");
if (group==NULL)
return;
ex = session -> NewObject(cls);
mid = session-> GetMethodID(cls,
"setmessage", PBRT_FUNCTION, "QS");
session-> InitCallInfo(cls,mid,ci);
TriggerEvent
Description Triggers a PowerBuilder event.
Syntax TriggerEvent(pbobject obj, pbmethodID mid, PBCallInfo *ci)
Argument Description
obj The pbobject containing the method
mid The pbMethodID returned by GetMethodID
ci A pointer to a preallocated PBCallInfo structure
Return value PBXRESULT. Returns PBX_OK for success, or one of the following for
failure:
PBX_E_INVALID_ARGUMENT
PBX_E_INVOKE_METHOD_INACCESSABLE
PBX_E_INVOKE_WRONG_NUM_ARGS
PBX_E_INVOKE_REFARG_ERROR
PBX_E_INVOKE_METHOD_AMBIGUOUS
PBX_E_INVOKE_FAILURE
Examples This code triggers the clicked event on a DataWindow object:
cls = session->GetClass(dwobj);
mid = session->GetMethodID
(cls, "clicked", PBRT_EVENT, "LIILCdwobject.");
session->InitCallInfo(cls, mid, ci);
session->TriggerEvent(dwobj, mid, ci);
...
See also GetClass
GetMethodID
UpdateField
Description Refreshes a visual property of a PowerBuilder object.
Syntax UpdateField(pbobject obj, pbfieldID fid)
Argument Description
obj The pbobject whose user interface property needs to
be changed
fid The field ID of the object
pbclass cls;
pbfieldID fid;
cls=session->GetClass(dwobj);
fid=session->GetFieldID(cls, "title");
if (fid==kUndefinedFieldID)
return;
session -> SetPBStringField(dwobj,fid,str_val);
session -> UpdateField(dwobj,fid);
return ;
}
Usage When you change any visual property of a PowerBuilder object by calling
Set<type>field functions, the property is changed but the property is not
refreshed in the graphical user interface. UpdateField refreshes the visual
properties of PowerBuilder objects. You must call this function explicitly when
changing any visual property with the Set<type>field functions.
See also Set<type>Field
IPB_Value interface
Description The IPB_Arguments and IPB_Value interfaces pass values between the
PowerBuilder VM and PowerBuilder extension modules. Through the
IPB_Value interface, you can access information about each variable,
including its type, null flag, access privileges, array or simple type, and
reference type.
Methods Table 7-4: IPB_Value methods
Method Description
Get<type> Set of datatype-specific methods that return a pointer to
the data in IPB_Value
GetClass Returns the class handle of a PowerBuilder object
GetType Returns the datatype of a single data item or array
IsArray Returns true if the IPB_Value instance contains an array,
otherwise returns false
IsByRef Returns true if the IPB_Value instance is passed by
reference
IsEnum Returns true if the IPB_Value instance contains a null
value, otherwise returns false
IsObject Returns true if the IPB_Value instance contains an object
or object array, otherwise returns false
SetToNull Used to set the data contained in the IPB_Value instance
to null so that data can be reset
Set<type> Set of datatype-specific methods that set the value of the
IPB_Value instance
Get<type>
Description A set of datatype-specific methods that return a pointer to the data in
IPB_Value.
Syntax GetArray ( )
GetBlob( )
GetBool ( )
GetByte ( )
GetChar ( )
GetDate ( )
GetDateTime( )
GetDecimal ( )
GetDouble ( )
GetInt ( )
GetLong( )
GetLongLong( )
GetObject ( )
GetReal( )
GetString ( )
GetTime( )
GetUint( )
GetUlong ( )
Return value A predefined PBNI datatype that corresponds to the PowerBuilder datatype in
the method name.
Examples This statement gets the date in the first value in the PBCallInfo structure and
splits it into year, month, and day:
Session -> SplitDate(ci-> pArgs -> GetAt(0) ->
GetDate(),&yy,&mm,&dd);
Usage If IPB_Value contains a null value, or if you are trying to get a specific datatype
from an IPB_Value instance of another datatype, the data retrieved is
undetermined. If the datatype is string, blob, decimal, time, date, datetime, array,
or object, the return value points to the same address pointed to by IPB_Value.
As a result, changing either the variable that holds the return value or the value
of the IPB_Value instance affects the other.
See also Set<type>
GetClass
Description Returns the class handle of a PowerBuilder object.
Syntax GetClass( )
Return value pbclass or null on error.
GetType
Description Returns the datatype of a single data item or array.
Syntax GetType()
Return value pbuint
IsArray
Description Returns true if the IPB_Value instance contains an array; otherwise, returns
false.
Syntax IsArray( )
Return value pbboolean
Examples This example tests whether an IPB_Value instance is an array before obtaining
the array:
if(ci->pArgs->GetAt(i)->IsArray())
{
pArguments[i].array_val =
ci->pArgs->GetAt(i)->GetArray();
continue;
}
See also IsByRef
IsEnum
IsObject
IsByRef
Description Returns true if the IPB_Value instance contains a by reference argument;
otherwise it returns false.
Syntax IsByRef()
Return value pbboolean
Examples This example shows how you would use IsByRef to test whether an argument
is obtained by reference:
if(ci->pArgs->GetAt(i)->IsByRef())
...
See also IsArray
IsEnum
IsObject
IsEnum
Description Returns true if the IPB_Value instance contains an enumerated value;
otherwise it returns false.
Syntax IsEnum( )
Return value pbboolean
IsNull
Description Returns true if the IPB_Value instance contains a null value; otherwise, it
returns false.
Syntax IsNull( )
Return value pbboolean
Examples This example tests whether an IPB_Value instance contains a null value before
attempting to obtain its value:
if(ci->pArgs->GetAt(i)->IsObject())
{
if (ci->pArgs->GetAt(i)->IsNull())
pArguments[i].obj_val=0;
else
pArguments[i].obj_val =
ci->pArgs->GetAt(i)->GetObject();
continue;
}
...
See also IsArray
IsByRef
IsObject
SetToNull
IsObject
Description Returns true if the IPB_Value instance contains an object or object array;
otherwise it returns false.
Syntax IsObject( )
Return value pbboolean
Examples This example tests whether an IPB_Value instance contains an object before
attempting to obtain the object:
if( ci->pArgs->GetAt(i)->IsObject())
{
if (ci->pArgs->GetAt(i)->IsNull())
pArguments[i].obj_val = 0;
else
pArguments[i].obj_val =
ci->pArgs->GetAt(i)->GetObject();
continue;
}
...
See also IsArray
IsByRef
IsEnum
Set<type>
Description Set of datatype-specific methods that set the value of the IPB_Value instance.
Syntax SetArray ( pbarray array )
SetBlob( pbblob blob )
SetBool ( pbboolean boolean )
SetByte ( pbbyte byte )
SetChar ( pbchar char )
SetDate ( pbdate date )
SetDateTime( pbdatetime datetime )
SetDecimal ( pbdecimal dec)
SetDouble ( pbdouble double)
SetInt ( pbint int )
SetLong( pblong long )
SetLongLong( pblonglong longlong )
SetObject ( pbobject object )
SetPBString ( pbstring string)
SetReal( pbreal real )
SetString ( LPCTSTR string)
SetTime( pbtime time )
SetUint( pbuint uint )
SetUlong ( pbulong ulong )
Return value PBXRESULT.
Examples This example uses the IPB_Value SetPBString method to set values in
PBCallInfo. It also uses the IPB_Session SetString method to set the ret_val
string to the return value in the PBCallInfo structure:
pbclass cls;
pbmethodID mid;
PBCallInfo* ci = new PBCallInfo;
pbstring ret_val;
LPCTSTR pStr;
if (pStr != 0)
{
if (strcmp(pStr, "null") == 0 )
ci-> pArgs -> GetAt(3) -> SetToNull();
else
ci-> pArgs -> GetAt(3) -> SetPBString(s_null);
}
Usage These methods automatically set the value of IPB_Value to not null and return
an error if the datatype to be set does not match the existing datatype. The error
code is PBX_E_MISMATCHED_DATA_TYPE. If the value is a read-only
argument, it returns the error PBX_E_READONLY_ARGS. If the datatype is
string or blob, a deep copy is performed. The existing value is destroyed first,
and then the contents of the argument are copied into a new value.
See also Get<type>
SetToNull
Description Sets the data contained in the IPB_Value instance to null so the data can be
reset.
Syntax SetToNull( )
Return value PBXRESULT. If the value is a read-only argument, the error
PBX_E_READONLY_ARGS is returned.
Examples This example shows the use of SetToNull when a null blob value is returned:
case pbvalue_blob:
pStr=(LPCTSTR)Session-> GetBlob(retVal.blob_val);
if (strncmp(pStr, "null", 4)==0 )
ci->returnValue->SetToNull();
else
ci->returnValue->SetBlob(retVal.blob_val);
break;
...
See also IsEnum
IPB_VM interface
Description The IPB_VM interface loads PowerBuilder applications in third-party
applications and interoperates with the PowerBuilder virtual machine
(PBVM).
Methods IPB_VM has two methods:
CreateSession
RunApplication
CreateSession
Description Creates an IPB_Session object that can be used to call PowerBuilder functions.
Syntax CreateSession(LPCTSTR applicationName, LPCTSTR* libraryList, pbuint
numLibs, IPB_Session** session)
Argument Description
applicationName The name of the current application object in
lowercase
libraryList The library list of the PowerBuilder application that
contains the objects and functions to be called
numLibs The number of libraries in the library list
session A pointer to IPB_Session*, which will return the
current IPB_Session pointer after the call
Examples This example creates an IPB_Session with the simple library list mydemo.pbl:
IPB_Session* session;
IPB_VM* vm = NULL;
fstream out;
ifstream in;
PBXRESULT ret;
HINSTANCE hinst=LoadLibrary("pbvm125.dll");
if ( hinst== NULL) return 0;
getvm(&vm);
if (vm == NULL) return 0;
RunApplication
Description Runs the specified application.
Syntax RunApplication(LPCTSTR applicationName, LPCTSTR* libraryList, pbuint
numLibs, LPCSTR commandLine, IPB_Session** session)
Argument Description
applicationName The name of the application object to be run, in
lowercase
libraryList The library list of the application
numLibs The number of libraries in the library list
commandLine Parameters to be passed to the application object
session A pointer to IPB_Session*, which will return the
current IPB_Session pointer after the call
switch (message)
{
case WM_CREATE:
{
hPBVMInst = ::LoadLibrary("pbvm125.dll");
IPB_VM* vm = NULL;
getvm(&vm);
vm->RunApplication("runapp", liblist, 1,
szcommandline, &session);
break;
}
See also CreateSession
IPBX_Marshaler interface
Description The IPBX_Marshaler interface is used to invoke remote methods and convert
PowerBuilder data formats to the user’s communication protocol. A marshaler
extension is a PowerBuilder extension that acts as the bridge between
PowerBuilder and other components, such as EJBs, Java classes, CORBA
objects, Web services, and so on.
Methods Table 7-5: IPBX_Marshaler methods
Method Description
Destroy Destroys an instance of an object inherited from the
IPBX_Marshaler structure
GetModuleHandle Returns the handle of the PBX that contains the native
class
InvokeRemoteMethod Used in PowerBuilder marshaler native classes to call
remote methods
Destroy
Description Use the Destroy method to destroy instances of objects inherited from the
IPBX_Marshaler structure.
Syntax Destroy( )
Return value None.
Examples This code destroys the current instance of the SampleMarshaler structure:
void SampleMarshaler::Destroy()
{
delete this;
}
Usage You must implement this method in the marshaler native class after creating an
instance of a marshaler structure and invoking remote methods.
See also GetModuleHandle
InvokeRemoteMethod
GetModuleHandle
Description Returns the handle of the PBX that contains the native class. This method is
required to allow the PowerBuilder VM to determine which PBXs can be
unloaded.
Syntax GetModuleHandle( )
Return value pbulong
Examples This code in the implementation of a marshaler class returns the handle of the
PBX:
extern pbulong thisModuleHandle;
pbulong SampleMarshaler::GetModuleHandle()
{
return thisModuleHandle;
}
The handle is set in the main module:
pbulong thisModuleHandle = 0;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Usage You must implement this method in the marshaler native class.
See also Destroy
InvokeRemoteMethod
InvokeRemoteMethod
Description Used in PowerBuilder marshaler native classes to call remote methods.
Syntax InvokeRemoteMethod(IPB_Session *session, pbproxyobject obj, LPCTSTR
methodDesc, PBCallInfo *ci)
Argument Description
session This IPB session
obj The proxy object for the remote object
methodDesc An arbitrary string stored as an alias name for the
remote method in the proxy, for example:
function int foo(int a) alias "This is
a method in remote BizTalk"
ci The parameters and return value setting for the call
private:
void myMethod(string arg1);
public:
SampleMarshaler(
string myString,
long mylong
);
~SampleMarshaler();
IPBX_NonVisualObject interface
Description The IPBX_NonVisualObject interface inherits from IPBX_UserObject and is
the direct ancestor class of nonvisual PowerBuilder native classes.
Methods IPBX_NonVisualObject inherits two methods from the IPBX_UserObject
interface:Destroy and Invoke.
IPBX_UserObject interface
Description The IPBX_UserObject interface is the ancestor class of the PowerBuilder
native classes.
Methods IPBX_UserObject has two methods:Destroy and Invoke
Destroy
Description Destroys the current instance of a PowerBuilder native class that inherits from
IPBX_UserObject.
Syntax Destroy( )
Return value None.
Examples This example shows how you would call Destroy for the class MyPBNIClass:
void MyPBNIClass::Destroy()
{
delete this;
}
Usage You must implement this method in the native class after creating an instance
of the class and invoking remote methods.
See also Invoke
Invoke
Description Calls methods in PowerBuilder native classes.
Syntax Invoke(IPB_Session * session, pbobject obj, pbmethodID mid, PBCallInfo *ci)
Argument Description
session This IPB session
obj The PowerBuilder extension object to be invoked
mid The pbMethodID returned by GetMethodID
ci The parameters and return value setting for the call
switch (mid)
{
case mFuncA:
result = FuncA(session, obj, ci);
break;
case mFuncB:
result = FuncB(session, obj, ci);
break;
case mFuncC:
result = FuncC(session, obj, ci);
break;
default:
result = PBX_E_INVOKE_FAILURE;
break;
}
return PBX_OK;
}
See also GetMethodID
IPBX_VisualObject interface
Description The IPBX_VisualObject interface inherits from IPBX_UserObject and is the
direct ancestor class of visual PowerBuilder native classes.
Methods IPBX_VisualObject has three direct methods:
CreateControl
GetEventID
GetWindowClassName.
CreateControl
Description Creates a window control and returns its handle to the PowerBuilder VM.
Syntax CreateControl(DWORD dwExStyle, LPCTSTR lpWindowName, DWORD
dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent,
HINSTANCE hInstance)
Argument Description
dwExStyle The extended window style
lpWindowName The window name
dwStyle The window style
x The horizontal position of the window
y The vertical position of the window
nWidth The window’s width
nHeight The window’s height
hWndParent The handle of the parent or owner window
hInstance The handle of the application instance
HWND CVisualExt::CreateControl
(
DWORD dwExStyle, // extended window style
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HINSTANCE hInstance // handle to application
instance
)
{
d_hwnd = CreateWindowEx(dwExStyle, s_className,
lpWindowName, dwStyle, x, y, nWidth, nHeight,
hWndParent, NULL, hInstance, NULL);
return d_hwnd;
}
Usage The window must be registered before you call CreateControl.
See also GetEventID
GetWindowClassName
GetEventID
Description Returns the identifier of an event when the window’s parent is notified that the
event occurred.
Syntax GetEventID(HWND hWnd, uint iMsg, WPARAM wParam, LPARAM lParam)
Argument Description
hWnd The handle of the parent window.
iMsg The message sent to the parent.
wParam The word parameter of the message.
For WM_COMMAND, the high-order word
specifies:
• The notification code if the message is from a
control
• 1 if the message is from an accelerator
• 0 if the message is from a menu.
The low-order word specifies the identifier of the
control, accelerator, or menu.
For WM_NOTIFY, this parameter contains the
identifier of the control sending the message.
lParam The long parameter of the message.
For WM_COMMAND, this parameter contains the
handle of the control sending the message if the
message is from a control. Otherwise, this
parameter is null.
For WM_NOTIFY, this parameter contains a pointer
to a structure.
Examples In this example, the GetEventID function returns the identifier PB_BNCLICKED
if a WM_COMMAND message with the notification code BN_CLICKED was
sent. It returns the identifier PB_ENCHANGE if a WM_NOTIFY message was
sent; otherwise it returns PB_NULL.
TCHAR CVisualExt::s_className[] = "PBVisualExt";
LPCTSTR CVisualExt::GetWindowClassName()
{
return s_className;
}
HWND CVisualExt::CreateControl
(
return d_hwnd;
}
int CVisualExt::GetEventID(
HWND hWnd, /* Handle of parent window */
UINT iMsg, /* Message sent to parent window*/
WPARAM wParam, /* Word parameter of message*/
LPARAM lParam /* Long parameter of message*/
)
{
if (iMsg == WM_COMMAND)
{
if ((HWND)lParam == d_hwnd)
{
switch(HIWORD(wParam))
{
case BN_CLICKED:
return PB_BNCLICKED;
break;
}
}
}
if (iMsg == WM_NOTIFY)
{
return PB_ENCHANGE;
}
return PB_NULL;
}
GetWindowClassName
Description Returns the name of the window.
Syntax GetWindowClassName()
Return value LPCTSTR.
Examples The string returned by GetWindowClassName is passed as an argument to the
CreateControl method:
LPCTSTR CVisualExt::GetWindowClassName()
{
return s_className;
}
Usage The window must be registered before you call GetWindowClassName.
See also CreateControl
GetEventID
PBArrayInfo structure
Description PBArrayInfo is a C++ structure used to hold information about arrays.
Properties Table 7-6: PBArrayInfo members
Member Type Description
ArrayBound Local struct Structure of type pblong containing the
declaration boundaries (upperBound, lowerBound) of a
dimension.
BoundedArray Enum data Used in arrayType to identify that the array
is a bounded array.
UnboundedArray Enum data Used in arrayType to identify that the array
is an unbounded array.
arrayType Enum type Used in IPB_Session::GetArrayInfo to
identify the datatype of the array. Do not set
this variable manually.
valueType pbuint The datatype of array items. Set it to
pbvalue_type if it is a simple type, or
pbobject if the item is a class or structure.
numDimensions pbuint Number of dimensions of the array. An
unbounded array can have only one
dimension. The lower bound is one.
bounds ArrayBound[] Array bounds declaration array, used in a
bounded array.
PBCallInfo structure
Description PBCallInfo is a C++ structure used to hold arguments and return type
information in function calls between PBNI and PowerBuilder.
Table 7-7: PBCallInfo members
Member Type Description
pArgs IPB_Arguments* Interface used to access arguments
returnValue IPB_Value Holds return data after the call
returnClass pbclass Holds return class after the call
PB_DateData structure
Description The PB_DateData structure is used to pass data of type Date in the SetData
function in the IPB_RSItemData interface.
Table 7-8: PB_DateData members
Field Description
year A short identifying the year
month A short identifying the month
day A short identifying the day
filler A short used for structure alignment only
PB_DateTimeData structure
Description The PB_DateTimeData structure is used to pass data of type DateTime in the
SetData function in the IPB_RSItemData interface.
Table 7-9: PB_DateTimeData members
Field Description
date A PB_DateData structure identifying the date
time A PB_TimeData structure identifying the time
PB_TimeData structure
Description The PB_TimeData structure is used to pass data of type Time in the SetData
function in the IPB_RSItemData interface.
Table 7-10: PB_DateData members
Field Description
hour A short identifying the hour
minute A short identifying the minute
second A short identifying the second
filler A short used for structure alignment only
PBX_DrawItemStruct structure
Description The PBX_DrawItemStruct structure contains the properties of an external
visual control that you want to draw using the PBX_DrawVisualObject function.
Table 7-11: PBX_DrawItemStruct members
Field Description
x X coordinate of the visual control relative to its parent
control (for example, the window that contains it).
y Y coordinate of the visual control relative to its parent
control.
width Width of the visual control.
height Height of the visual control.
objectName The name of the visual object, for example: uo_1.
tag Field to be used to pass any value at the user’s discretion.
enabled Whether the visual control is enabled. Possible values are
true and false.
visible Whether the visual control is visible. Possible values are
true and false. In the development environment,
PowerBuilder does not call the PBX_DrawVisualObject
function if this field is set to false and the Design>Show
Invisibles menu item is not selected.
borderstyle Border style of the visual control. A value of the
pbborder_style enumerated variable. Possible values are:
• 0 – none
• 1 – shadowbox
• 2 – box
• 5 – lowered
• 6 – raised
backColor Background color of the visual control. You can obtain
the RGB value of the background color using the
Windows API functions GetRValue, GetGValue, and
GetBValue.
GetAt
Description Obtains the array item at the specified dimension.
Syntax GetAt(pblong dim[])
Return value ValueType (defined in pbtraits.h).
Argument Description
dim The dimension of the array item to be obtained
IsNull
Description Returns true if the array item contains a null value, otherwise returns false.
Syntax IsNull(pblong dim[ ])
Argument Description
dim The dimension of the array item to be tested
SetAt
Description Sets the array item at the specified dimension.
Syntax For arrays of a specified ValueType:
SetAt(pblong dim[ ], ValueType v)
For string arrays:
SetAt(pblong dim[ ], LPCTSTR string)
SetAt(pblong dim[ ], pbstring string)
Argument Description
dim The dimension of the array item to be set
v A ValueType defined in pbtraits.h
string A string of type pbstring or LPCTSTR
T *iarg, oarg;
in >> itemcount1;
iarg = new T[itemcount1];
// Create unbounded integer array
{
PBUnboundedArrayCreator<I> ac(session);
out_array = ac.GetArray();
PBArrayAccessor<I> aa(session, out_array);
for(i=0; i<itemcount1; i++)
in >> iarg[i];
for (i=0; i<itemcount1; i++)
{
dim[0]=i+1;
aa.SetAt(dim, iarg[i]);
}
itemcount2 = session->GetArrayItemCount(out_array);
out <<"The array item count is "<< itemcount2 <<
endl;
for (i=0; i<itemcount2; i++)
{
dim[0]=i+1;
oarg=aa.GetAt(dim);
if (oarg != iarg[i])
out << "*** ERROR"<< endl;
else
out << oarg << " ";
}
}
delete []iarg;
out << endl;
return;
}
See also GetAt
SetToNull
Description Sets the value of the specified array item to null.
Syntax SetToNull(pblong dim[ ])
Argument Description
dim The dimension of the array item to be set
GetArray
Description Obtains an array that has been created.
Syntax GetArray()
Return value pbarray.
Examples This example sets up an array, reads in values, and then obtains the values in
the array:
LPCTSTR *ostr_a;
char **sp;
int i;
pbarray out_array;
arrayBounds* bounds;
pbuint dim1, dim2, current_dim;
pblong itemcount1, itemcount2;
PBXRESULT ret;
PBArrayInfo* ai;
pbstring *iarg, *oarg;
typedef PBBoundedArrayCreator<pbvalue_string>
BoundedStringArrayCreator;
in >> dim1;
// allocate memory for pointer bounds
bounds = (arrayBounds*)malloc(dim1*sizeof
(PBArrayInfo::ArrayBound));
bounds = new arrayBounds[dim1];
// read in lowerbound and upperbound for each dimension
// and calculate the array item count
itemcount1 = 1;
for (i=0;i<dim1;i++)
{
in >> bounds[i].lowerBound >> bounds[i].upperBound;
itemcount1 = itemcount1*
(bounds[i].upperBound - bounds[i].lowerBound +1);
}
sp = new char*[itemcount1];
ostr_a = new LPCTSTR[itemcount1];
iarg = new pbstring[itemcount1];
// Read in array items
for (i=0; i<itemcount1; i++)
{
sp[i] = new char[20];
in >> sp[i];
iarg[i]= session->NewString(sp[i]);
}
// create bounded simple array and set iarg[i] to it
{
BoundedStringArrayCreator ac(session, dim1, bounds);
current_dim = 1;
BoundedArrayItem<pbstring, pbvalue_string,
BoundedStringArrayCreator>::f_set_arrayitem
(session, ac, dim1, bounds, iarg, current_dim);
BoundedArrayItem<pbstring, pbvalue_string,
BoundedStringArrayCreator>::array_itemcount = 0;
out_array = ac.GetArray();
}
See also SetAt
SetAt
Description Sets a value or string to the array item at the specified dimension.
Syntax For arrays of a specified ValueType:
SetAt(pblong dim[], ValueType v)
For string arrays:
SetAt(pblong dim[], LPCTSTR string)
SetAt(pblong dim[], pbstring string)
Argument Description
dim The dimension of the array item to be set
v A ValueType defined in pbtraits.h
string A string of type pbstring or LPCTSTR
PBBoundedObjectArrayCreator class
Description The PBBoundedObjectArrayCreator class is used to create an object array.
Methods PBBoundedObjectArrayCreator has two methods:
GetArray
SetAt
GetArray
Description Obtains an array that has been created.
Syntax GetArray()
Return value pbarray.
Examples This example sets the values in an array and then uses GetArray to obtain the
array:
PBBoundedObjectArrayCreator<pbvalue_string>
ac(session);
for (i=0;i<itemcount1;i++)
{
ac.SetAt(i+1,iarg[i]);
}
out_array = ac.GetArray();
See also SetAt
SetAt
Description Sets the array item at the specified dimension.
Syntax For arrays of a specified ValueType:
SetAt(pblong dim[], ValueType v)
For string arrays:
SetAt(pblong dim[], LPCTSTR string)
SetAt(pblong dim[], pbstring string)
Argument Description
dim The dimension of the array item to be set
v A ValueType defined in pbtraits.h
string A string of type pbstring or LPCTSTR
PBObjectArrayAccessor class
Description The PBObjectArrayAccessor class is used to access the items in an object
array.
Methods PBObjectArrayAccessor has two methods:
GetAt
SetAt
GetAt
Description Obtains the array item at the specified dimension.
Syntax GetAt(pblong dim[])
Return value pbobject.
Argument Description
dim The dimension of the array item to be set
SetAt
Description Sets the array item at the specified dimension.
Syntax SetAt(pblong dim[], pbobject obj)
Argument Description
dim The dimension of the array item to be set
obj A valid object handle
GetArray
Description Obtains an array that has been created.
Syntax GetArray()
Return value pbarray.
Examples This example sets the values in an array and then uses GetArray to obtain the
array:
PBUnboundedArrayCreator<pbvalue_string> ac(session);
for (i=0; i<itemcount1; i++)
{
ac.SetAt(i+1,iarg[i]);
}
out_array = ac.GetArray();
See also SetAt
SetAt
Description Sets the array item at the specified position.
Syntax For arrays of a specified ValueType:
SetAt(pblong pos, ValueType v)
For string arrays:
SetAt(pblong pos, LPCTSTR string)
SetAt(pblong pos, pbstring string)
Argument Description
pos A pblong identifying a position in the array
v A ValueType defined in pbtraits.h
string A string of type pbstring or LPCTSTR
PBUnboundedObjectArrayCreator class
Description The PBUnboundedObjectArrayCreator class is used to create an object array.
Methods PBUnboundedObjectArrayCreator has two methods:
GetArray
SetAt
GetArray
Description Obtains an array that has been created.
Syntax GetArray( )
Return value pbarray.
See also SetAt
SetAt
Description Sets the array item at the specified dimension.
Syntax For arrays of a specified ValueType:
SetAt( pblong pos, ValueType v )
For string arrays:
SetAt( pblong pos, LPCTSTR string )
SetAt( pblong pos, pbstring string )
Argument Description
pos A pblong identifying a position in the array
v A ValueType defined in pbtraits.h
string A string of type pbstring or LPCTSTR
Exported methods
Description The following table lists methods that must be implemented in the
PowerBuilder extension module when the conditions shown in the table apply.
The methods are described after the table. The PBX_GetVersion method is used
by PowerBuilder to determine whether the compiler macro UNICODE or
_UNICODE has been set. It is for internal use only.
Methods Table 7-12: Methods that must be exported by all extensions
Method Required
PBX_CreateNonVisualObject When the extension contains nonvisual native
classes
PBX_CreateVisualObject When the extension contains visual native
classes
PBX_DrawVisualObject When you want to be able to draw a visual
representation of the visual object in the
PowerBuilder development environment
PBX_GetDescription In all extensions
PBX_InvokeGlobalFunction When the extension contains global functions
PBX_Notify When you need to initialize and uninitialize a
session
PBX_CreateNonVisualObject
Description Creates a new instance of a nonvisual PowerBuilder extension object.
Syntax PBX_CreateNonVisualObject(IPB_Session* pbsession, pbobject pbobj,
LPCTSTR xtraName, IPBX_NonVisualObject **obj)·
Argument Description
pbsession This IPB session
pbobj The name of a pbobject corresponding to the
PowerBuilder extension object to be created
xtraname The name of the PowerBuilder native class in
lowercase
obj The PowerBuilder extension object to be created
Examples In this example, the extension contains several classes. The object created
depends on the string value of the class name passed in.
PBXEXPORT PBXRESULT PBXCALL PBX_CreateNonVisualObject
(
IPB_Session* pbsession,
pbobject pbobj,
LPCTSTR xtraName,
IPBX_NonVisualObject **obj
)
{
PBXRESULT result = PBX_OK;
string cn(className);
if (cn.compare("class_a") == 0)
{
*obj = new class_a(pbobj);
}
else if (cn.compare("class_b") == 0)
{
*obj = new class_b(pbobj);
}
else if (cn.compare("class_c") == 0)
{
*obj = new class_b(pbobj);
else
{
*obj = NULL;
result = PBX_E_NO_SUCH_CLASS;
}
return PBX_OK;
};
Usage You must implement this method in every PowerBuilder extension module that
contains nonvisual classes. When you use the CREATE statement in
PowerScript to create a new PowerBuilder extension object, the PBVM calls
this method.
See also PBX_GetDescription
PBX_CreateVisualObject
Description Creates a new instance of a visual PowerBuilder extension object.
Syntax PBX_CreateVisualObject(IPB_Session* pbsession, pbobject pbobj,
LPCTSTR xtraName, IPBX_NonVisualObject **obj)·
Argument Description
pbsession This IPB session
pbobj The name of a pbobject corresponding to the
PowerBuilder extension object to be created
xtraname The name of the PowerBuilder native class in
lowercase
obj The PowerBuilder extension object to be created
string cn(className);
if (cn.compare("visualext") == 0)
{
*obj = new CVisualExt(pbsession, pbobj);
}
else
{
*obj = NULL;
result = PBX_FAIL;
}
return PBX_OK;
};
Usage You must implement this method in every PowerBuilder extension module that
contains visual classes. When you use a visual extension in a PowerBuilder
application, the PBVM calls this method.
See also PBX_GetDescription
PBX_DrawVisualObject
Description Draws a visual object in the PowerBuilder development environment.
Syntax PBX_DrawVisualObject(HDC hDC, LPCTSTR className, const
PBX_DrawItemStruct& property)·
Argument Description
hDC A handle to the device context of the object
classname The name of the visual extension object to be drawn
property A PBX_DrawItemStruct structure specifying the
display properties of the object
Return value PBXRESULT. The return value of this function is currently ignored.
Examples This is an extension of a sample that is available on the PowerBuilder
CodeXchange Web site at http://powerbuilder.codexchange.sybase.com. It draws
a representation of a light-emitting diode (LED) and uses Microsoft
Foundation Classes (MFC):
PBXEXPORT PBXRESULT PBXCALL PBX_DrawVisualObject
(
HDC hDC,
LPCTSTR xtraName,
const PBX_DrawItemStruct& property
)
{
// If this PBX is dynamically linked against the MFC
// DLLs, any functions exported from this PBX that
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
AFX_MANAGE_STATE( AfxGetStaticModuleState() );
//done
delete myLed;
}
return PBX_OK;
}
Usage In a visual extension, export this function if you want the visual control to be
drawn in the development environment. If you do not export the function, you
need to run the application to see the appearance of the visual control.
See also PBX_CreateVisualObject
PBX_DrawItemStruct structure
PBX_GetDescription
Description Passes a description of all the classes and methods in the PowerBuilder
extension module to PowerBuilder.
Syntax PBX_GetDescription ( )
Return value LPCTSTR containing the description of the module.
Examples The following extension module contains three classes:
PBXEXPORT LPCTSTR PBXCALL PBX_GetDescription()
{
static const TCHAR desc[] = {
"class class_a from nonvisualobject\n"
"function long meth1(string classpath)\n"
"function string meth2()\n"
"end class\n"
return desc;
}
The following module contains a visual class that has two subroutines
(functions that do not return values), two events that require that Windows
messages be captured in the extension (onclick and ondoubleclick), and one
event that maps a Windows message directly to a PowerBuilder event
(testmouse). The module also contains two global functions, funca and funcb.
PBXEXPORT LPCTSTR PBXCALL PBX_GetDescription()
{
static const TCHAR desc[] = {
"class visualext from userobject\n"
"event int onclick()\n"
"event int ondoubleclick()\n"
"subroutine setcolor(int r, int g, int b)\n"
"subroutine settext(string txt)\n"
"event testmouse pbm_mousemove \n"
"end class\n"
"globalfunctions\n"
"function int funca(int a, int b)\n"
"function int funcb(int a, int b)\n"
"end globalfunctions\n"
};
return desc;
}
Usage You must implement this method in every PowerBuilder extension module.
The method is exported from the PowerBuilder extension module and is used
by PowerBuilder to display the prototype of each class, function, and event in
the module.
The syntax of the description follows:
Multiple instances
A syntax element with an asterisk indicates that multiple instances of that
element can appear in a description. For example, [Desc]* indicates that one
description can contain multiple classes, global functions, and forward
declarations.
Desc ::=
class_desc | globalfunc_desc | forward_desc | [Desc]*
class_desc ::=
class className from parentClass newline
[methods_desc]* end class newline
globalfunc_desc :=
globalfunctions newLine [func_desc]* end globalfunctions
forward_desc :=
forward newLine [forwardtype_desc]* end forward
forwardtype_desc :=
class className from parentClass newline
className ::=
a PowerBuilder token (cannot duplicate an existing group name)
parentClass ::=
any class inherited from NonVisualObject or UserObject
newline ::=
a newline character
methods_desc ::=
method_desc [methods_desc]*
method_desc ::=
func_desc | sub_desc | event_desc
func_desc ::=
function returnType funcName(args_desc) newline
returnType :: =
pbType
pbType ::=
any PowerBuilder type | previous declared PBNI class
funcName ::=
a PowerBuilder token
args_desc ::=
None | arg_desc, [args_desc]*
arg_desc ::=
[ ref | readonly ] pbType argName [array_desc]
argName ::=
a PowerBuilder token
array_desc ::=
array declaration of PowerBuilder
sub_desc ::=
subroutine subName(args_desc) newline
event_desc ::=
event returnType eventName(args_desc) newline
| event eventName pbevent_token newline
pbevent_token :: =
string
This syntax for event_desc allows you to map a Windows message directly to
a PowerBuilder event:
event eventName pbevent_token newline
For more information, see “Event processing in visual extensions” on page 34.
See also PBX_CreateNonVisualObject
PBX_CreateVisualObject
PBX_InvokeGlobalFunction
PBX_InvokeGlobalFunction
Description Contains the implementation of one or more global functions used in the
PowerBuilder extension module.
Syntax PBX_InvokeGlobalFunction(IPB_Session* pbsession, LPCTSTR
functionname, PBCallinfo* ci);
Argument Description
pbsession This IPB session
functionname The name of the global function
ci A pointer to a preallocated PBCallInfo structure
containing the parameters and return value setting
for the function
return desc;
}
The PBX_InvokeGlobalFunction call contains the implementation of the
functions:
PBXEXPORT PBXRESULT PBXCALL PBX_InvokeGlobalFunction
(
IPB_Session* pbsession,
LPCTSTR functionName,
PBCallInfo* ci
)
{
if (stricmp(functionName, "bitand") == 0)
{
ci->returnValue->SetInt(arg1 & arg2);
}else if (strcmp(functionName, "bitor") == 0)
{
ci->returnValue->SetInt(arg1 | arg2);
}else if (strcmp(functionName, "bitxor") == 0)
{
ci->returnValue->SetInt(arg1 ^ arg2);
}else
{
return PBX_FAIL;
}
return pbrResult;
}
Usage Use this function in a PowerBuilder native class that uses global functions. The
function is exported from the PowerBuilder extension module and is used to
identify global functions included in the module. Like global functions in
PowerScript, global functions in PowerBuilder extensions cannot be
overloaded.
See also PBX_GetDescription
PBX_Notify
Description Used to initialize and uninitialize a session.
Syntax PBXEXPORT PBXRESULT PBXCALL PBX_Notify(IPB_Session*
pbsession, pbint reasonForCall)
Return value PBXRESULT
Examples This sample shows code that exports PBX_Notify and displays a message box
after the PBX is loaded and before it is unloaded:
PBXEXPORT PBXRESULT PBXCALL PBX_Notify
(
IPB_Session* pbsession,
pbint reasonForCall
)
{
switch(reasonForCall)
{
case kAfterDllLoaded:
MessageBox(NULL, "After PBX loading", "",
MB_OK);
break;
case kBeforeDllUnloaded:
MessageBox(NULL, "Before PBX unloading", "",
MB_OK);
break;
}
return PBX_OK;
}
Usage If PBX_NOTIFY is exported, the PBVM calls PBX_Notify immediately after an
extension PBX is loaded and just before the PBX is unloaded. You can use this
function to initialize and uninitialize a session. For example, you could create
a session manager object, and store it in the IPB session using the SetProp
function. Later, you could use GetProp to obtain the session object.
PB_GetVM
Description Passes the IPB_VM interface to the user.
Syntax PB_GetVM (IPB_VM** vm)
Examples This example loads the PowerBuilder VM and calls the f_getrowcount function
on the nvo_dw custom class user object:
#include <pbext.h>
#include <iostream.h>
typedef PBXEXPORT PBXRESULT (*P_PB_GetVM)(IPB_VM** vm);
class LibraryLoader
{
public:
LibraryLoader(LPCSTR libname)
{
d_hinst = LoadLibrary(libname);
}
~LibraryLoader()
{
FreeLibrary(d_hinst);
}
operator HINSTANCE()
{
return d_hinst;
}
private:
HINSTANCE d_hinst;
};
int main()
{
int int_rowcount;
PBXRESULT ret;
LibraryLoader loader("pbvm125.dll");
IPB_VM* vm = NULL;
getvm(&vm);
if (vm == NULL) return 0;
About this chapter This chapter describes two tools provided with the PBNI SDK:
• The pbsig125 tool gets the internal signature of a PowerBuilder
function from a PBL name.
• The pbx2pbd125 tool generates a PBD from a PBX.
When you install PowerBuilder, these tools are installed in the SDK
subdirectory of your PowerBuilder 12.5 directory and in
Shared\PowerBuilder.
Contents
Topic Page
pbsig125 255
pbx2pbd125 259
pbsig125
Description The PowerBuilder function signature is the internal signature of a
PowerBuilder function that is used to identify polymorphism functions in
a class. The pbsig125 tool obtains these function signatures from a PBL.
Inherited functions
You can also obtain a signature by selecting the function in the System
Tree or Browser and selecting Properties from its pop-up menu. The
pbsig125 tool does not report the signature of functions that are inherited
from an ancestor object unless they are extended in the descendant. For
such functions, you must use the Properties dialog box to obtain the
signature. The Properties dialog box in the Browser also allows you to
obtain the signature of PowerBuilder system functions.
Examples This command extracts function signatures from one of the PBLs in the Code
Examples sample application:
pbsig125 pbexamw1.pbl
Here is some of the output from the previous command:
PB Object Name: w_date_sort
public subroutine of_sort (string as_Column,
string as_Order)
/* QSS */
Usage The pbsig125 tool generates a string that represents the declaration and
signature of all the functions and events in the PBL, including argument types,
return types, and passing style. Each function and event is followed by a
commented string. You pass the commented string, for example, QSS in the
first comment in the previous example, as the last argument to the GetMethodID
method.
For example, the following output indicates that the function returns an integer
and has a single integer argument passed by reference:
/* IRI */
PowerBuilder arrays PowerBuilder arrays are indicated with a pair of square
brackets [ ] as a suffix. For bounded arrays, the brackets enclose the bounds.
/* IRCdatastore.RS[]SS */
PowerBuilder system or custom class Additional letter codes represent a
PowerBuilder system class or a custom class. The letter C followed by the
name of a PowerBuilder object or enumerated class and a period (Cname.)
represents an argument or return value of that type.
The following table shows how the output from pbsig125 maps to datatypes
and other entities.
Table 8-1: Return value and argument representation in pbsig125
output
Output Datatype
[] array
A any
B boolean
C class
D double
E byte
F real
G basictype
H character
I integer
J cursor
K longlong
L long
M decimal
N unsigned integer (uint)
O blob
Output Datatype
P dbproc
Q No type (subroutine)
S string
T time
U unsigned long (ulong)
W datetime
Y date
Z objhandle
pbx2pbd125
Description The pbx2pbd125 tool generates a PowerBuilder dynamic library (PBD) file
from a PowerBuilder extension PBX. The generated PBD can be added to the
library list of any PowerBuilder application target that will use the objects and
methods in the PowerBuilder extension.
Syntax pbx2pbd125 [+] des.pbd src1.pbx [ src2.pbx src3.pbx ...srcn.pbx ]
Examples This example generates a new PBD test.pbd from test.pbx. The input and
output files are in the current directory:
pbx2pbd125 test.pbd test.pbx
This example appends generated information from C:\myproject\src.pbx to
C:\mypbds\des.pbd. (If des.pbd does not exist, it is created.)
pbx2pbd125 + C:\mypbds\des.pbd C:\myproject\src.pbx
This example generates a new PBD D:\pbds\test.pbd from all the PBX files in
the C:\myproject directory:
pbx2pbd125 D:\pbds\test.pbd C:\myproject\*.pbx
This example generates PBD information from all the PBX files in the C:\temp
and D:\temp directories and appends the information to the existing generated
PBD file D:\pbds\test.pbd:
pbx2pbd125 + D:\pbds\test.pbd c:\temp\*.pbx
d:\temp\*.pbx
Usage You can import an extension into a PowerBuilder library using the Import PB
Extension pop-up menu item for the library in the PowerBuilder System Tree.
Prior to PowerBuilder 11.5, you had to use the pbx2pbdnnn tool to create a PBD
file from a PBX file, then add the PBD to the library list of your PowerScript
target. The tool is still available in this release.
You can include multiple PBXs in a single PBD file. If you want to add
additional PBXs to an existing PBD, use the plus (+) sign before the name of
the PBD.
The pbx2pbd125 tool is installed in the system PATH in the
Shared\PowerBuilder directory so you can invoke it in the directory where the
PBXs reside.
If you specify an absolute path for the PBX file when you generate the PBD,
the PowerBuilder application searches for the PBX only in the specified path.
If you do not specify the path for the PBX file, the PowerBuilder application
searches the system path for the PBX.
About this appendix If you use Visual Studio .NET 2002 or 2003 or Visual Studio 2005, you
can use a wizard to create a PBNI extension project. The wizard creates a
project with .cpp and .h files that contain required code as well as template
code to help you get started.
Check for wizard updates in the PBNI section of the PowerBuilder
CodeXchange Web site at http://powerbuilder.codeXchange.sybase.com/.
Contents
Topic Page
Where the wizards are installed 263
Generating a PBNI project 265
Setting project options 266
Building and using the PBX 266
If Visual Studio is not already installed when you install PowerBuilder, see the
install.txt file in the PBNI\wizards\VCWizards\PBNIWizard directory for how
to install the wizard later.
To check whether the wizard is installed in Visual Studio, select
File>New>Project from the menu bar , select Visual C++ Projects, and scroll
the Templates pane to see the PBNI wizard.
A conventions xi
CreateControl function (IPBX_VisualObject) 221
AcquireArrayItemValue function (IPB_Session) 102
using 33
AcquireValue function (IPB_Session)
CreateResultSet function (IPB_Session) 108
description 103
CreateSession function (IPB_VM) 211
using 62
AddArrayArgument function (IPB_Session) 104
AddBlobArgument function (IPB_Session) 104
AddBoolArgument function (IPB_Session) 104 D
AddByteArgument function (IPB_Session) 104
data
AddCharArgument function (IPB_Session) 104
exchanging 55
AddDateArgument function (IPB_Session) 104
saving values 61
AddDateTimeArgument function (IPB_Session) 104
datatypes
AddDecArgument function (IPB_Session) 104
for PowerBuilder data access 84
AddDoubleArgument function (IPB_Session) 104
PowerBuilder to PBNI mapping 83
AddGlobalRef function (IPB_Session) 106
debugging 43
AddIntArgument function (IPB_Session) 104
Destroy function (IPBX_Marshaler) 215
AddLocalRef function (IPB_Session) 107
Destroy function (IPBX_UserObject) 219
AddLongArgument function (IPB_Session) 104
AddLongLongArgument function (IPB_Session)
104
AddObjectArgument function (IPB_Session) 104 E
AddPBStringArgument function (IPB_Session) 104
AddRealArgument function (IPB_Session) 104 enumerated types
AddRef function (IPB_ResultSetAccessor interface) pbgroup 84
92, 95 pbroutine 85
AddStringArgument function (IPB_Session) 104 pbvalue 85
AddTimeArgument function (IPB_Session) 104 support for 64, 129
AddUintArgument function (IPB_Session) 104 event IDs, and triggering events 37
AddUlongArgument function (IPB_Session) 104 event processing, in visual extensions 34
examples
calling PowerBuilder functions 42
nonvisual extension 11
C on the Web 3
exception handling 43
C++
exchanging data with PowerBuilder 55
calling PowerBuilder from 65
exported methods 241
coding extensions 12
exporting methods 24
calling PowerScript from an extension 39
extensions
ClearException function (IPB_Session) 107
creating 17, 28
code samples, on Web site 3
marshaler, about 6
T
ThrowException function (IPB_Session) 199
TriggerEvent function (IPB_Session) 200
triggering events 37
typographical conventions xi
U
UpdateField function (IPB_Session) 201
V
variables, using throughout a session 63
Visual C++ wizard 263
visual classes
creating instances 31
declaring 29
defining 29
describing 19
exporting methods 29
implementing 29
message processing 34
registering 32
visual extensions
about 5
building 28
creating instances 31
event processing 34
planning 28
using 30
Visual Studio wizards 263
W
WindowProc, in visual extensions 34
Windows messages
capturing 35
processing 38
wizard, for Visual C++ 263
wizards, for Visual Studio 263