python 报reading location 0x00000000

由于对python不太熟悉,需用python调用dll;
现有dll接口函数:business_handle(char in, char * out)
下面代码cmd正常运行,打包后报:Access violation reading location 0x00000000
outputData=ctypes.create_string_buffer('/0'*100)

business_handle = self._libc.BUSINESS_HANDLE

business_handle.argtypes=[ctypes.c_char_p,ctypes.c_char_p]
business_handle.restype=ctypes.c_int

business_handle(inputData,outputData)

有哪位大神帮忙写个能正常调用的例子!

找了个例子,可以执行

 import platform
from ctypes import *

if platform.system() == 'Windows':
    libc = cdll.LoadLibrary('msvcrt.dll')
elif platform.system() =='Linux':
    libc = cdll.LoadLibrary('libc.so.6')

libc.printf('Hello ctypes!\n')

结果

 C:\Users\BJWUYBDNW\Desktop>python a.py
Hello ctypes!

C:\Users\BJWUYBDNW\Desktop>

C代码 生成 csdndll1.dll

#include <windows.h>
int GenNChar(char c, int N,char* out, int out_len)
{
    if (N > out_len)
    {
        return 1;
    }
    int i;
    for (i = 0; i < N; i++)
    {
        out[i] = c;
    }
    out[i] = 0;
    return 0;
}
BOOL WINAPI DllMain(_In_ HANDLE _HDllHandle, _In_ DWORD _Reason, _In_opt_ LPVOID _Reserved)
{
    return TRUE;
}

python代码a.py:

import platform
from ctypes import *

if platform.system() == 'Windows':
    libc = cdll.LoadLibrary('msvcrt.dll')
    mylib = cdll.LoadLibrary('E:/ronggf/develop/cpp/csdndll1/x64/Release/csdndll1.dll')
    s = create_string_buffer('\000' * 32)
    mylib.GenNChar(c_char('a'),10,s,32)
    libc.printf("result=%s\n",s)

输出结果:

C:\Users\BJWUYBDNW\Desktop>python a.py
result=aaaaaaaaaa

C:\Users\BJWUYBDNW\Desktop>

这样就OK

import platform
from ctypes import *

if platform.system() == 'Windows':
libc = cdll.LoadLibrary('msvcrt.dll')
elif platform.system() =='Linux':
libc = cdll.LoadLibrary('libc.so.6')

libc.printf('Hello ctypes!\n')
结果

C:\Users\BJWUYBDNW\Desktop>python a.py
Hello ctypes!

C:\Users\BJWUYBDNW\Desktop>