使用C++;用Python编写带有ctypes的代码 我有以下C++,这两个函数返回int 0,表示成功。< /P> #include "stdafx.h" #include <iostream> #include "scapi.h" int main() { int ret; ret = sc_LoginByLogon(L"hostname.domain.ltd", L"admin", L"pass"); std::cout << "LoginByLogon: " << ret << std::endl; void* out_p; ret = sc_GetUserInfoByUserLogon(L"username", &out_p); std::cout << "GetUserInfoByUserLogon: " << ret << std::endl; }

使用C++;用Python编写带有ctypes的代码 我有以下C++,这两个函数返回int 0,表示成功。< /P> #include "stdafx.h" #include <iostream> #include "scapi.h" int main() { int ret; ret = sc_LoginByLogon(L"hostname.domain.ltd", L"admin", L"pass"); std::cout << "LoginByLogon: " << ret << std::endl; void* out_p; ret = sc_GetUserInfoByUserLogon(L"username", &out_p); std::cout << "GetUserInfoByUserLogon: " << ret << std::endl; },python,c++,ctypes,Python,C++,Ctypes,代码应该可以工作,但在Python中,只有sc_LoginByLogon返回0,而sc_GetUserInfoByUserLogon失败(1)。只说“1=一般故障”,所以我被卡住了 如果您有任何明显的想法,我们将不胜感激。多亏了Mark Tolonen,在调用之前明确定义了登录函数之后,它现在可以工作了。我不认为我必须这样做,因为它已经返回int 0,这表示成功 #include "stdafx.h" #include <iostream> #include "scapi.h"

代码应该可以工作,但在Python中,只有sc_LoginByLogon返回0,而sc_GetUserInfoByUserLogon失败(1)。只说“1=一般故障”,所以我被卡住了


如果您有任何明显的想法,我们将不胜感激。

多亏了Mark Tolonen,在调用之前明确定义了登录函数之后,它现在可以工作了。我不认为我必须这样做,因为它已经返回int 0,这表示成功

#include "stdafx.h"
#include <iostream>
#include "scapi.h"


int main() {

    int ret;

    ret = sc_LoginByLogon(L"hostname.domain.ltd", L"admin", L"pass");
    std::cout << "LoginByLogon: " << ret << std::endl;

    void* out_p;

    ret = sc_GetUserInfoByUserLogon(L"username", &out_p);
    std::cout << "GetUserInfoByUserLogon: " << ret << std::endl;
}
唯一的问题是,所有属性(如“m_wzFullName”)由于某种原因都会跳过第一个字符

编辑: 由于以下线程,我解决了最后一个bug:


您不应该将指针(c\u void\u p)传递给该方法吗?看起来你传递的是另一种类型,我试着把out p改为out p=POINTER(c\u void\u p)(),但结果是一样的。它仍然失败。out\u p=pointer(c\u void\u p())?引发“TypeError:必须是ctypes类型”异常。我很确定定义是正确的……如果没有为
sc_LoginByLogon
定义
argtypes
,Python 2传递的字节字符串将不会隐式编码为Unicode字符串。我预计第一次呼叫会失败。第二个调用看起来声明正确,但可能由于第一个调用出现问题而失败。
# sc_LoginByLogon
sc_LoginByLogon = lib.sc_LoginByLogon
sc_LoginByLogon.argtypes = [c_wchar_p, c_wchar_p, c_wchar_p]
sc_LoginByLogon.restype = c_int