本文介绍了NetShareAdd的哪些argtypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

win32函数NetShareDel具有三个参数LPCWSTR LPCWSTR和DWORD.

The win32 function NetShareDel takes three arguments, LPCWSTR LPCWSTR and DWORD.

因此,我将以下列表用于argtypes:

So I use the following list for argtypes:

C.windll.Netapi32.NetShareDel.argtypes = [LPCWSTR, LPCWSTR, c_int]
C.windll.Netapi32.NetShareDel.restype = c_int

C.windll.Netapi32.NetShareDel(server, shareName, 0)

这很好,但是我无法弄清楚NetShareAdd使用什么,尤其是NET_SHARE_INFO结构的字节数组和最后一个byref(c_int)参数.

That works fine, but I can't figure out what to use for NetShareAdd, especialle the byte array for NET_SHARE_INFO struct and the last byref(c_int) argument.

代码如下:

def Share(server, shareName, dir):
    info = SHARE_INFO_2()

    STYPE_DISKTREE = 0

    info.shi2_netname = shareName
    info.shi2_path = dir
    info.shi2_type = STYPE_DISKTREE
    info.shi2_remark = "Shared: " + time.strftime("%Y%m%d-%H:%M")
    info.shi2_max_uses = -1
    info.shi2_passwd = ""
    info.shi2_current_uses = 0
    info.shi2_permissions = 0xFFFFFFFF

    i = c_int()

    bytearray = buffer(info)[:]

    windll.Netapi32.NetShareAdd.argtypes = [LPCWSTR, c_int, ????, ????]

    windll.Netapi32.NetShareAdd(server, 2, bytearray, C.byref(i))

NetShareAdd的正确argtypes列表是什么?

What would be the correct argtypes list for NetShareAdd?

推荐答案

让它终于可以工作

第一行

bytearray = buffer(info)[:]

已更改为字节指针类型

byteptr = C.POINTER(C.wintypes.BYTE)(info)

,然后argtypes和call当然也将成为POINTER(BYTE):

and then the argtypes and call will become POINTER(BYTE) too of course:

C.windll.Netapi32.NetShareAdd.argtypes = [LPCWSTR, c_int, C.POINTER(C.wintypes.BYTE), C.POINTER(c_int)]
C.windll.Netapi32.NetShareAdd.restype = c_int

windll.Netapi32.NetShareAdd(server, 2, byteptr, C.byref(i))

这篇关于NetShareAdd的哪些argtypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 00:20