PBInvoke quick start guide

PBInvoke library documetation > General > Quick Start Guide

Add PBInvoke library to your project

  • Unpack PbInvoke.PBL and libPbInvoke.DLL for your PowerBuilder version (or closest older version) to your project folder.
  • Add PbInvoke.PBL to application's library list.
  • Make a migration.
  • Make a full build.

    Initialize PBInvoke

    If libPbInvoke.DLL is not in the PATH nor in the current directory then you'll need to specify the path to it in application's open event before any other call to the library:

    n_pi_loader lnv_loader  // autoinstantiated

    Note, you can change the path only, and not the DLL name because it is hard-coded in the external function declarations.

    Declare DLL function

    This code can be placed in any convenient script. Usually it's executed once per application session and its results are cached somewhere (e.g. in instance/shared variables).

    n_pi_core lnv_core
    n_pi_library lnv_user32
    n_pi_method lnv_SendMessage
    lnv_user32 = lnv_core.of_declare_library("user32.dll")
    lnv_SendMessage = lnv_user32.of_declare_method(&
    	"LRESULT WINAPI SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) ")

    Note, that the declaration is a C function prototype which can be directly copied from C header files or from documentation such as MSDN.

    HWND, UINT etc. are Windows types. Many such types are predefined in PBInvoke. But if you get "Type 'XXXX' not found" error message, then you'll need to define the type yourself before using it in declarations.

    n_pi_core lnv_core
    lnv_core.of_declare("typedef int NEWTYPE"); // this is just an example; for real typedef you'll need to 
                                                // see the documentation or header files for DLL you call.

    Call DLL function

    long ll_result
    ll_result = lnv_SendMessage.of_invoke(Handle(w_somewin), n_pi_winapi.WM_KEYDOWN, 9 /*Tab*/, 0) 

    n_pi_winapi provides some WinAPI constants.

    More samples

    See the Samples folder in the archive for more complex examples with structures, callbacks etc.

    See also

  • Calling DLL functions using PBInvoke
  • Handling strings (char*, wchar_t*)
  • WinAPI constants and types
  • Working with C/C++ structures/unions
  • Working with callbacks