我正在为某人编写一个 Python3 脚本,该脚本通过 ctypes 使用 advapi dll 及其 LogonUserW 函数。
运行代码时
在__init__函数中
dll_location = find_library("advapi32");
if (dll_location == None):
raise FileNotFoundError
adv_dll = WinDLL(dll_location);
#gets the pointer to the function
logonUser = adv_dll.LogonUserW;
self.logonUser = logonUser
在 login(username, domain, password) 函数中
#Sets the parameters to call the DLL
loginType = DWORD(2)
loginProvider = DWORD(0)
handle = PHANDLE()
user = LPCSTR(username.encode());
pw = LPCSTR(password.encode());
dom = LPCSTR(domain.encode());
rescode = self.logonUser(user, dom, pw, loginType, loginProvider, handle);
它提出了OSError: exception: access violation writing 0x0000000000000000
知道什么可能导致错误以及如何解决吗?
PS:是的,我知道我没有遵循 PEP 8 的变量名,我通常是一名 java 程序员。