祝愿大家身体健康!

 站点注册  找回密码
 站点注册

QQ登录

只需一步,快速开始

查看: 3509|回复: 0

[PB idea] PowerBuilder (pb)的扩展DLL开发(超级篇)(二)

[复制链接]

[PB idea] PowerBuilder (pb)的扩展DLL开发(超级篇)(二)

[复制链接]
ehxz

主题

0

回帖

57万

积分

管理员

积分
570604
贡献
在线时间
小时
2022-9-17 21:33:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?站点注册

×
FROM:https://blog.csdn.net/lxbin2003/ ... 1001.2014.3001.5502
原创:lxbin2003

PB的扩展DLL开发(超级篇)(二)

(PB史上第一次开放的开发技术)

上一章(PowerBuilder (pb)的扩展DLL开发(超级篇)(一)
https://www.sybasebbs.com/forum. ... 90013&fromuid=6)里,我们说到system library 里的函数声明为下面这样的方式。

  1. __declspec(dllexport) DWORD __stdcall FuncName(POB_THIS obThis,int nArgCount)
  2. {
  3.          BOOL isnull;
  4.          return 1;
  5. }
复制代码

其中第一个参数POB_THIS obThis 是每个函数的核心,本篇重点介绍一下核心结构OB_THIS,它是每个函数的第一个参数。这个结构有点大,通常我们不需要直接访问成员结构,但了解了这个结构的成员,有时候可以很方便地访问一些全局的内容。

  1. typedef struct ob_this              {
  2. void* __vtbl;
  3.     POB_THIS                            obthis;                           // 兼容性指针
  4.     POB_THIS                            rtthis;                //兼容性指针
  5.     PSH_DBG_THIS             dbgthis;                               //调试时使用
  6.     ppbstg_anchor                stgthis;                                // 指向内存分配的锚,有些函数需要用到它,比如pbstg_alloc
  7.     UINT                                curr_pcode;                                 // Current pcode Instruction
  8.     BOOL                     pcode_done;             // End of pcode block indicator.
  9.     PSHLIST                     pBreakPointList;        // 指向断点列表
  10.     INT                         bStep;                  // Processing step mode
  11.     RT_BREAK_PROC                    rtBreakCallback[PD_SIZE]; // Debugger call back function
  12.     PVOID                     pUserData;              // 给用户使用,存放用户数据。
  13.     PSHLIST                            pTransactionList;              // 事务列表
  14.     BOOL                     bIgnoreErrors;          // Ignore runtime error flag
  15.     BOOL                     bTerminateRuntime;                 // Terminate runtime flag
  16.     OB_CLASS_HNDL                     clshndl;                // Current class handle
  17.     OB_CLASS_HNDL                     appclshndl;             // Application class handle
  18.     OB_EVT_ID                 event_id;               // Event ID
  19.     OB_INST_ID                 appinst;                // Application实例对象
  20.     pbstg_subpool                subpool;                               //指向内存分配的池,有些函数需要用到它,比如pbstg_alloc
  21.     RT_MODE                          mode;                   // 模式,比如编译状态、EXE运行状态、调试状态等
  22.     PVOID                     smthis;                 // Semantic this pointer
  23.     OB_MODE                         obMode;                 // Object manager mode
  24.     UINT                      iPCodeCounter;          // PCode execution counter
  25.     RT_OPT_MODE                       opt_mode;                                   // Optimization mode
  26.     PSHLIST                            pDllList;                               //已经加入的外部DLL列表,即程序里那些声明DLL函数用到的DLL
  27.     PVOID                               curr_pcode_blk;                          // Current pcode block
  28.     UINT                                 iContextCount;                           // Number of run contexts
  29.                                                                                                            //     only valid in primary rtthis
  30.     BOOL                                bHaltClose;                                  // Halt close processing flag
  31.     BOOL                                bDontTerminate;                        // Dont terminate after error
  32.     UINT                                     curr_line_block_loc;         // Current line_block loc.
  33.     UINT                                     last_break_line_no;                   // Last line numbers...
  34.     UINT                                     last_pcode_line_no;                  // ...
  35.     PVOID FAR* pThreadStart;                         // Points to start of thread
  36.     PVOID FAR* pThreadNode;                        // Points to cur. thread node
  37.     UINT                                     halt_close_nest;               // Count of nested halt close
  38.     PCM_THIS                           cmthis;                                          // Current compiler context
  39.     PSHLIST                      pLibraryList;           //库列表,SetLibraryList 函数就是设置此列表
  40.     PSHLIST                      pNameList;              // Library entry name list
  41.     PVOID                      pGroupList;             // Pointer to group list nodes
  42.     PVOID                      pLookSymKeyFunction;    // Group name hash key function
  43.     PVOID                      scnthis;                // Scanner this pointer
  44.     UINT                        iGroupListIncr;         // Group list increment
  45.     UINT                        iGroupListPos;          // Group list position
  46.     UINT                        iGroupListSize;         // Group list size
  47.     pbstg_subpool       client_subpool;         // Client subpool
  48.     pbstg_subpool                perm_subpool;           // Permanent subpool
  49.     pbstg_subpool                result_subpool;         // Intermediate results
  50.     pbstg_subpool                temp_subpool;           // Temporary subpool
  51.     PSHLIST                      group_stack;                      // List of groups ids currently in use
  52.     PVOID                      curr_obj_group;
  53.     PVOID                      sys_typedef_group;
  54.     PVOID                      curr_routnode;
  55.     OB_INST_ID                  curr_obinst;  //当前对象实例,比如 json.Set(…)调用时,Set函数里的当前对象就指向json这个实例。
  56.     PVOID                      lib_handle;
  57.     PSHLIST                      run_stack;                                    // Used to maintain Runtime Call Stack
  58.     PVOID                         rtinst_stack;                       // Used to maintain instance list
  59.     LPTSTR                     def_appl_groupname; //创建 target 时指定的 application名称
  60.     LPTSTR                     def_appl_libname; //创建 target 时指定的pbl ,通常名称与 application一样,但后缀名是 .pbl
  61.     PVOID                      appl_group;
  62.     BOOL                       bInRuntime;
  63.     UINT                        appl_filter;
  64.     PVOID                      hExecutable;
  65.     UINT                        iExeGroupCounter;
  66.     PSHLIST                      pExeGroupList;                           // No longer used
  67.     PVOID                      pExeResourceHash;       // Resource list for build .EXE
  68.     POT_EVAL_NODE                    expr_stack;                                  // maintain params and vars used by pcodes
  69.     UINT                        expr_stack_size;               // size of expression (data) stack
  70.     POT_EVAL_NODE          expr_stack_ptr;                          // current stack entry
  71.     PSHLIST                      arglist_stack;                     // NOT USED
  72.     PSHLIST                      error_list;                                     // list of errors during application build
  73.     BOOL                       bGotLinkError;
  74.     pbstg_subpool                lvalue_subpool;         // Lvalues
  75.     BOOL                       bNoDuplicateSymbols;
  76.     PSHLIST                      unused;                          // UNUSED
  77.     OB_CLASS_HNDL             curr_class_hndl;
  78.     OB_ARRAY_ID                   curr_array_inst;              // Current array inst id.
  79.     UINT                                  ErrorCode;
  80.     BOOL                                 set_return_called;
  81.     OB_GROUP_HNDL                   sys_group_hndl;
  82.     PVOID                      pSavedGroupList;        // Pointer to saved group list nodes
  83.     PVOID                                  lmithis;                               // Ptr to Lib Mgr anchor
  84.     PVOID                                  curr_runstk_node;        // Ptr to runtime stack node.
  85.     ULONG                                 ps_options;                                  // PS executable options
  86.     OB_EXE_CODE_TYPE       exe_code_type;                          // CCode or PCode
  87.     LPTSTR                                 pExecutableName;       // current executable
  88.     PVOID                                  evaled_arglist;                            // 每个函数调用时,这里是实际参数数组指针,可用ot_get_....arg(…) 系列函数来取具体参数,也可以 for(int i=0;i来循环直接取参数
  89.                                                                                                            //   from expr_stack and converted as necessary
  90.     PVOID                                  lvalue_info;
  91.     UINT                curr_arg_pos; //保留取当前参数的位置。函数开始时,此变量为0,用ot_get_....arg(…)每取走一个参数时,此变量会增加。如果取参数的次数大于实际参数个数,会导致程序崩溃。因此取参数时最好要判断此变量不大于参数个数 nArgCount。
  92.     POT_EVAL_NODE              return_value;                     //
  93.     POT_EVAL_NODE              called_return_value;        //函数调用结束,实际返回值存放在这里。通常用 ot_set_return_val(…) 来设置,或者 ot_no_ret_val(obThis) 来表明无返回值。
  94.     PVOID                                  p_error_info;                      // Error information for CCode
  95.     LONG                                    routine_level;                     // the routine level for CCode
  96.     ULONG                                 ulDServFlags;                     // Flags for distributed PB
  97.     PVOID                                  working_group;                          // Current working group
  98.     PVOID                                  callback_data;                   // Used to store pointer for
  99.                                                                                                            // callback functions.
  100.     PVOID                                  callback_data2;                          // 2nd instance
  101.     POB_THIS                            parentObThis;                    // The obthis that was cloned to
  102.     BOOL                check_for_locked_menu;  // used by 'obinst.cpp' - Currently only used in local object create.
  103.                                                                                                            // can be easily removed
  104.     //***************************************************************************
  105.     // file I/O buffers
  106.     //***************************************************************************
  107.     LPTSTR                                 pEntryBuffer;
  108.     TCHAR HUGEPTR* pHugeEntryBuffer;
  109.     LONG                                    lEntryPos;
  110.     LONG                                    lEntrySize;
  111.     //***************************************************************************
  112.     // Multi-Tasking, Transaction Pooling, Miscellaneous
  113.     //***************************************************************************
  114.     PVOID                                  pTransPool;                             // Transaction Pool
  115.     // this growblock is used as an array of groupId's to enable the codegen
  116.     // routines to be thread safe and still be able to load the context.
  117.     PSH_GROWBLOCK            pGroupIdArray;
  118.     PVOID                                  criticalSection;                   // general purpose critical section
  119.     PVOID               pCmCompilerError;                   // so we can decouple compiler dll
  120.     ULONG                                 GeneralFlags;
  121.     PVOID               unused_2;                              // some free bytes for the taking ...
  122.     BOOL                                    bIgnoreLinkErrors;            // ignore link errors.
  123.     UINT                                new_next_pcode;                      // User set pcode Instruction
  124.     PVOID               pSharedObjMgr;          // shared object manager inte**ce
  125.     // trace facility
  126.     LPVOID                                traceStruct;                        // tracing structure
  127.     BOOL                                    bTracing;                             // global trace enable flag
  128.     // debugger facility
  129.     PSHLIST                     pWatchPointList;        // Pointer to watchpoint list
  130.     PSHLIST                      dbg_callstk;                        // Stack for walking up call stack
  131.     UINT                                     bStepLine;                                    // Line number for step to cursor
  132.     INT                                        bStepRoutineLevel;          // Depth step command started at
  133.     // secure runtime session
  134.     ULONG                                 SecureRuntimeSession;   // flags for apps downloaded over the Web.
  135.     // garbage collection
  136.     DWORD                               lGCTimeLimit;                    // the min time between garbage collection runs
  137.     DWORD                               lLastGCTime;                     // the time of the end of the last GC run
  138.     BOOL                                    bGarbageCollecting;                 // if we are in the process of garbage collecting
  139.     // object manager request queue
  140.     PVOID                                  pRequestQueue;                        // a pointer to the obj_mgr request queue
  141.     // pointer to error callback function for handling runtime errors
  142.     PVOID                                  pErrorCallback;
  143.     // windows dispatch handler
  144.     PVOID                                  pWndDispatchHndlr;                 // a pointer to the dispatch handler
  145.     // these should all be protected by ob_enter_critical_section()!!
  146.     DWORD                               idOwnerThread;                         // the handle the of thread that owns the OBTHIS
  147.     BOOL                                    bActiveSession;                           // indicate that this obthis is an active session
  148.     BOOL                                    bIsAsyncCall;                      // indicates if root of call is async
  149.     PVOID                                  pLocalSession;
  150.     PVOID                                  local_variables;                 // Current local variables to routine
  151.     UINT                                     num_variables;                           // Number of local variables.
  152.     UINT                                     curr_stack_bias;               // Current stack bias. Used for gc.
  153.     BOOL                                    bDeferredDelete;             // indicates if we are deferring the delete
  154.                                                                                                            // of an active session until after all requests
  155.                                                                                                            // have completed processing.
  156.     // Context Feature OB_ICONTEXT pointers
  157.     PVOID                                  pSessOB_ICONTEXT;
  158.     PVOID                                  pDefltOB_ICONTEXT;
  159.     // Class Definition (a.k.a. metaclass) local session list
  160.     PSHLIST                     pSessionList;
  161.     LPTSTR                                 lpstrTypdefPblName;                 // if we want to ignore the default of "pbtypvm70.dll"
  162.     BOOL                                    bNoMessageBoxForError;       // TRUE if we don't want the message box to come up.
  163.     BOOL                                    bInSystemError;                         // TRUE if we are already executing the system error event.
  164.     PVOID                                  last_break_routine;                   // Last routine a breakpoint was processed in.
  165.     BOOL                                    bInitDebugMode;                       // Are we in the debugger and NOT running from within it.
  166.     PVOID                                  pContextObject;                // The context object
  167.     // remote debugger facility
  168.     PVOID                                  pLocalDebugSession;       // If non-NULL, the local debug session for Remote debugging
  169.     ULONG                                 breakpointId;                     // unique id for breakpoints
  170.     // GroupLoader stuff.
  171.     PVOID                                  pGroupLoader;
  172.     //Resulset Marshaling
  173.     PVOID                                  pResultsetInfo;
  174.     // pointer to error callback state information for functions handling runtime errors
  175.     PVOID                                  pErrorCallbackState;
  176.     // Exception Handling
  177.     PSHLIST                      exception_stack;               // stack containing the checked exception list
  178.     PVOID                                  thrown_exception;           // pointer to thrown exception object,
  179.                                                                                                            //      NULL if none pending
  180.     PVOID                                  curr_exception;                          // pointer to currently handled exception object,
  181.                                                                                                            //  NULL if not currently handling one
  182.     PSHLIST                      gosub_stack;                // stack containing the list of gosub return locations
  183.     struct ResponseWindowStack
  184.     {
  185.              ResponseWindowStackNode* stack;
  186.              UINT capacity;
  187.               UINT count;
  188.     } response_window_stack;
  189.     PSHLIST                      objects_creating;              // A list object being created.
  190.     PVOID                                  pb_session;                                  // To be used for PSPP
  191.     PVOID                                  pMetaObject;                    // A pointer to the meta object created by a func call
  192.                                                                                                            // and need to be free in the next sf_dot call.
  193.     // PB Accessibility service
  194.     /*这部分 pb9 没有
  195.     PVOID                                  pACCService;
  196.     BOOL                isInOrcaBootStrap;
  197.     LPTSTR                                 pCurrMissedTypeWhenOrcaBootStrap;
  198.     BOOL                                    bInNewBuild;
  199.     PVOID              pb_sessionA;
  200.     BOOL                bJITStart;
  201.     BOOL                                    bJITOption;
  202.     */
  203. } OB_THIS;
复制代码


OB_THIS这个结构比较复杂,有必要对它进行一些研究和了解。

如果你对system library相关开发方式感兴趣,可到QQ群624409252共享里大自在的专用目录下下载DEMO。
————————————————
版权声明:本文为CSDN博主「lxbin2003」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lxbin2003/article/details/118214878
共享共进共赢Sharing And Win-win Results
SYBASEBBS - 免责申明1、欢迎访问“SYBASEBBS.COM”,本文内容及相关资源来源于网络,版权归版权方所有!本站原创内容版权归本站所有,请勿转载!
2、本文内容仅代表作者观点,不代表本站立场,作者自负,本站资源仅供学习研究,请勿非法使用,否则后果自负!请下载后24小时内删除!
3、本文内容,包括但不限于源码、文字、图片等,仅供参考。本站不对其安全性,正确性等作出保证。但本站会尽量审核会员发表的内容。
4、如本帖侵犯到任何版权问题,请立即告知本站 ,本站将及时删除并致以最深的歉意!客服邮箱:admin@sybasebbs.com
您需要登录后才可以回帖 登录 | 站点注册

本版积分规则

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com

QQ|Archiver|PowerBuilder(PB)BBS社区 ( 鲁ICP备2021027222号-1 )

GMT+8, 2024-4-24 19:52 , Processed in 0.052450 second(s), 9 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表