Bruce Armstrong TeamSybase
Techniques PowerBuilder 11 and beyond only Referencing.Net assemblies directly within Conditional Code blocks in PowerScript Any version of PowerBuilder.Net Interop via COM Callable Wrappers
Referencing.Net Assemblies Currently only non-visual assemblies Visual assemblies is a release milestone for PowerBuilder 12 Conditional Code blocks AutoScript is not supported (errors are reported at compile time) Syntax is neither PowerScript or C# but a mix of them (PowerScript#)
.Net Interop Runtime Callable Wrapper COM Callable Wrapper
Allows a.Net application to use a Win32 COM object Runtime Callable Wrapper COM Object Runtime Callable Wrapper.Net Application
Allows a Win32 application to use a.Net object via COM COM Callable Wrapper.Net Object COM Callable Wrapper Win32 Application
COM Callable Wrapper Assembly has to be COM-Visible Assembly can be marked such at compile time FxCop can be used to determine if marked ILSASM/ILASM can be used (in some cases) to change the marking
COM Callable Wrapper Marking the Assembly COM-Visible in Visual Studio
Using FxCop Examining the COM-Visible attribute using Microsoft’s FxCop
ILDASM ILASM (IL Assembler) is part of the.Net runtime Typical location: C:\WINDOWS\Microsoft.NET\Framework\v In the System Path ILDASM (IL Disassembler) is part of the.Net SDK Typical Location: C:\Program Files\Microsoft.NET\SDK\v2.0\Bin May not be in the System Path
Using ILDASM Examining the COM-Visible attribute in the disassembled IL
REGASM .Net Assembly Registration Utility Used to create COM registry entries for.Net component Syntax: RegAsm AssemblyName [Options] Options: /unregister /regfile[:FileName] /codebase
REGASM Output With regfile option but without codebase option
REGASM Output With regfile option and codebase option
Registry Free COM Not.Net specific, can be used for any COM components Supported on Windows version XP and later (e.g., 2003, Vista, 2008) us/library/ms aspx us/library/ms aspx
How Registry Free COM Works Client App Client App.Manifest Dependant Assembly (COM Component) Dependant Assembly.Manifest
GenMan32 Useful utility for generating manifest files for Registry Free COM Syntax: GenMan32 AssemblyName [Options] Options: /add /out:filename generate-sxs-manifest-for-managed-assembly-for-registration-free-com-net- interop.aspx generate-sxs-manifest-for-managed-assembly-for-registration-free-com-net- interop.aspx
GenMan32 Output
CCW Limitations Types, methods, properties, fields and events must all be public Methods must not be static Types must have a public default constructor Overloaded methods should be avoided Late binding clients can’t retrieve error information from.Net exceptions PowerBuilder Specific: Events
Avoid Overloaded Methods.Net Class foo ( int a ) foo ( string a ) foo ( long a ) COM Wrapper foo (int a ) foo_2 ( string a ) foo_3 ( long a )
Why error information gets lost PowerBuilder Client CCW.Net Assembly IDispatch Exception 3. Exception Thrown 4.SetErrorInfo 5. GetErrorInfo 1. COM Call 2..Net Call 6. Return from call
What we can do about it Managed Exception Logger Exception Publisher Event Log Debug Window Managed Exception Queue CCW IDispatch Exception
Further Reading Microsoft’s Exception Handling Application Block us/library/cc aspx Get Seamless.NET Exception Logging From COM Clients Without Modifying Your Code us/magazine/cc aspx
Interop Forms Toolkit 2.0 Not just forms, but controls as well us/vbasic/bb aspx us/vbasic/bb aspx Can be used in the Express versions of Visual Studio with some limitations C# implementation available on CodeProject -_C__Interop_Form.aspx -_C__Interop_Form.aspx
Supporting Events Create a Interface of type ComInterfaceType.InterfaceIsIDispatch with the defined events Provide a GUID for the interface Assign a unique DispID for each event Add a ComSourceInterfaces attribute to the control Define the events within the control Call those events from within the user control
Event Declaration Interface
Implementing Events
Events exposed in PowerBuilder
Questions