您的位置:程序门 -> vc/mfc -> 进程/线程/dll



duplicatehandle的作用是什么?》


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


duplicatehandle的作用是什么?》
发表于:2007-07-13 19:22:45 楼主
duplicatehandle妙用无穷啊。      
    duplicatehandle(getcurrentprocess(),getcurrentprocess(),          
    getcurrentprocess(),&hreaddup,      
    0,       false,duplicate_same_access)      
    的用处就不小:)

谁能解释下上面代码的用处?
发表于:2007-07-13 20:38:561楼 得分:0
查msdn:用法如下      
    the       duplicatehandle       function       duplicates       an       object       handle.          
       
    bool       duplicatehandle(      
            handle       hsourceprocesshandle,           //       handle       to       the       source       process      
            handle       hsourcehandle,                                       //       handle       to       duplicate      
            handle       htargetprocesshandle,           //       handle       to       process       to       duplicate       to      
            lphandle       lptargethandle,           //       pointer       to       duplicate       handle      
            dword       dwdesiredaccess,                   //       access       for       duplicate       handle      
            bool       binherithandle,                           //       handle       inheritance       flag      
            dword       dwoptions                                               //       optional       actions      
    );      
           
    parameters      
    hsourceprocesshandle          
    handle       to       the       process       with       the       handle       to       duplicate.          
    windows       nt:       the       handle       must       have       process_dup_handle       access.          
       
    hsourcehandle          
    handle       to       duplicate.       this       is       an       open       object       handle       that       is       valid       in       the       context       of       the       source       process.       for       a       list       of       objects       whose       handles       can       be       duplicated,       see       the       following       remarks       section.          
    htargetprocesshandle          
    handle       to       the       process       that       is       to       receive       the       duplicated       handle.       the       handle       must       have       process_dup_handle       access.          
    lptargethandle          
    pointer       to       a       variable       receiving       the       value       of       the       duplicate       handle.       this       handle       value       is       valid       in       the       context       of       the       target       process.          
    if       lptargethandle       is       null,       the       function       duplicates       the       handle,       but       does       not       return       the       duplicate       handle       value       to       the       caller.       this       behavior       exists       only       for       backward       compatibility       with       previous       versions       of       this       function.       you       should       not       use       this       feature,       as       you       will       lose       system       resources       until       the       target       process       terminates.          
       
    dwdesiredaccess          
    specifies       the       access       requested       for       the       new       handle.       this       parameter       is       ignored       if       the       dwoptions       parameter       specifies       the       duplicate_same_access       flag.       otherwise,       the       flags       that       can       be       specified       depend       on       the       type       of       object       whose       handle       is       being       duplicated.       for       the       flags       that       can       be       specified       for       each       object       type,       see       the       following       remarks       section.       note       that       the       new       handle       can       have       more       access       than       the       original       handle.          
    binherithandle          
    indicates       whether       the       handle       is       inheritable.       if       true,       the       duplicate       handle       can       be       inherited       by       new       processes       created       by       the       target       process.       if       false,       the       new       handle       cannot       be       inherited.          
    dwoptions          
    specifies       optional       actions.       this       parameter       can       be       zero,       or       any       combination       of       the       following       flags:       value       meaning          
    duplicate_close_source       closes       the       source       handle.       this       occurs       regardless       of       any       error       status       returned.          
    duplicate_same_access       ignores       the       dwdesiredaccess       parameter.       the       duplicate       handle       has       the       same       access       as       the       source       handle.          
       
       
    return       values      
    if       the       function       succeeds,       the       return       value       is       nonzero.      
       
    if       the       function       fails,       the       return       value       is       zero.       to       get       extended       error       information,       call       getlasterror.
发表于:2007-07-13 20:47:142楼 得分:0
汗`
发表于:2007-07-13 22:15:483楼 得分:0
极有可能为了跨进程共享handle(kernel   object)
发表于:2007-07-13 23:28:074楼 得分:0
复制句柄的目的主要是对句柄权限赋值和修改。
发表于:2007-07-14 10:16:055楼 得分:0
复制句柄
有一个用途是:
若要得到一个线程的退出码,则可以用duplicatehandle在创建此线程后来复制线程的句柄,
这样在线程退出后,可以使用这个复制出来的线程句柄来得到原线程的退出码(因为这个时候原线程已经退出,他本身的句柄已经失效了,而这个复制出来的句柄却可以继续使用。)
发表于:2007-07-17 13:54:476楼 得分:0
复制一个对象句柄!


快速检索

最新资讯
热门点击