11.07.2015 Views

in PowerBuilder - sys-con.com's archive of magazines - SYS-CON ...

in PowerBuilder - sys-con.com's archive of magazines - SYS-CON ...

in PowerBuilder - sys-con.com's archive of magazines - SYS-CON ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PBNIWRITTEN BYDAVID HUOCall<strong>in</strong>g <strong>PowerBuilder</strong>NVOs <strong>in</strong> C#PBNI answers the callHow can we reuse Power-Builder NVOs <strong>in</strong> .NET applications?Before <strong>PowerBuilder</strong>9.0, the answer was Power-Builder automation or a three-tiersolution.In the latter case that meant host<strong>in</strong>gall the NVOs <strong>in</strong> EAServer as middle-tiercomponents. Beg<strong>in</strong>n<strong>in</strong>g with version 9,<strong>PowerBuilder</strong> <strong>of</strong>fers a new <strong>in</strong>terface to<strong>in</strong>teract with the <strong>PowerBuilder</strong> VM – the<strong>PowerBuilder</strong> Native Interface (PBNI).In this article I will expla<strong>in</strong> how to usePBNI <strong>in</strong> unmanaged C++ code and marshalthe parameters to C# managedcode so that you can <strong>in</strong>voke Power-Builder NVOs from C#.FIGURE 1 |Java-based applications can use JNIto <strong>in</strong>voke <strong>PowerBuilder</strong> via PBNI.• Many <strong>PowerBuilder</strong> built-<strong>in</strong> featurescan be moved to <strong>PowerBuilder</strong> extensionsso that the <strong>PowerBuilder</strong> corecan be very small and the deploymentsize can vary depend<strong>in</strong>g onwhich features the user needs.us<strong>in</strong>g the <strong>PowerBuilder</strong> librarypa<strong>in</strong>ter. Right-click the method <strong>in</strong> theNVO and select “Properties”. The signaturestr<strong>in</strong>g is shown <strong>in</strong> the “Signature”text field (see Figure 2). Anotherway to do it is us<strong>in</strong>g pbsig100.exe,which is a command-l<strong>in</strong>e toolshipped with PBNI SDK:AUTHOR BIODavid Huo works forthe Sybase Waterloo<strong>con</strong>sultant team.Introduc<strong>in</strong>g PBNI (Power-Builder Native Interface)PBNI is a new feature <strong>in</strong>troducedwith <strong>PowerBuilder</strong> 9.0. It is only available<strong>in</strong> the enterprise versions and is<strong>in</strong>stalled under %<strong>PowerBuilder</strong><strong>in</strong>stall%\ SDK\PBNI. You can f<strong>in</strong>d allthe required header files to use PBNIunder the <strong>in</strong>clude directory.PBNI is a standard programm<strong>in</strong>g<strong>in</strong>terface that enables developers toextend the functionality <strong>of</strong> <strong>PowerBuilder</strong>.Us<strong>in</strong>g PBNI, you can create visual andnonvisual extensions to <strong>PowerBuilder</strong>(<strong>in</strong>clud<strong>in</strong>g marshaler extensions) andalso embed the <strong>PowerBuilder</strong> virtualmach<strong>in</strong>e (PBVM) <strong>in</strong>to C++ applications.Compared with <strong>PowerBuilder</strong> automation,PBNI has many advantages:• It is not just reus<strong>in</strong>g exist<strong>in</strong>g NVOs.<strong>PowerBuilder</strong> can be extended us<strong>in</strong>gPBNI to provide capabilities such asXML pars<strong>in</strong>g and Web service <strong>in</strong>tegration.• The solution is not COM-based,therefore no registry sett<strong>in</strong>gs arerequired and it can be deployed tonon-W<strong>in</strong>dows platforms.• More languages can reuse Power-Builder components; for example,How It WorksPBNI provides predef<strong>in</strong>ed C++ <strong>in</strong>terfacesto allow the PBVM <strong>in</strong>teract to withother languages (see Figure 1). Table 1describes some important <strong>in</strong>terfaces.Call<strong>in</strong>g <strong>PowerBuilder</strong> NVOfrom Unmanaged CodeTo <strong>in</strong>voke a <strong>PowerBuilder</strong> NVO us<strong>in</strong>gPBNI, you need to follow these steps:1. Identify the required <strong>PowerBuilder</strong>library files and the method signaturestr<strong>in</strong>g <strong>in</strong> the NVO. This can be donepbsig100 .Here is a sample output <strong>of</strong>pbsig100.exe show<strong>in</strong>g the methods’signature str<strong>in</strong>gs <strong>of</strong> NVO n_automation:PB Object Name: automationPB Object Name: n_automationpublic function str<strong>in</strong>g fn_barcode(str<strong>in</strong>g specimenid, str<strong>in</strong>gInterfaceDescriptionsIPB_VMUsed to load <strong>PowerBuilder</strong> objects <strong>in</strong> third-party applications and<strong>in</strong>teroperate with the <strong>PowerBuilder</strong> virtual mach<strong>in</strong>e (PBVM).IPB_Session <strong>in</strong>terface An abstract <strong>in</strong>terface that def<strong>in</strong>es methods for perform<strong>in</strong>g variousactions such as access<strong>in</strong>g PowerScript data, creat<strong>in</strong>g <strong>PowerBuilder</strong>objects, and call<strong>in</strong>g PowerScript functions.IPB_ValueRepresents a <strong>PowerBuilder</strong> value, which could be one <strong>of</strong> the Power-Builder standard datatypes such as <strong>in</strong>teger, long, str<strong>in</strong>g, and so forth.It provides <strong>in</strong>formation about each variable, <strong>in</strong>clud<strong>in</strong>g its type, nullflag, access privileges, array or simple type, and reference type.IPB_Arguments Represents the arguments passed to a PowerScript function andused to access the data.PBCallInfo (structure) Used to hold data and return type <strong>in</strong>formation for calls betweenextensions and the PBVM.TABLE 1 |24 PBDJ volume12 issue11pbdj.<strong>sys</strong>-<strong>con</strong>.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!