#include "stdio.h"
void display(char* msg){
printf("%sn",msg);
}
int add(int a,int b){
return a+b;
}
#!/usr/bin/python
from ctypes import *
import os
//参数为生成的.so文件所在的绝对路径
libtest = cdll.LoadLibrary(os.getcwd() + '/linuxany.so')
//直接用方法名进行调用
print
libtest.display('Hello,I am linuxany.com')
print libtest.add(2,2010)
Hello,I am linuxany.com 2012
import ctypes dll = ctypes.windll.LoadLibrary( 'test.dll' )
import ctypes dll = ctypes.WinDll( 'test.dll' )
import ctypes
dll = ctypes.cdll.LoadLibrary( 'test.dll' )
##注:一般在linux下为test.o文件,同样可以使用如下的方法:
## dll = ctypes.cdll.LoadLibrary('test.o')
import ctypes dll = ctypes.CDll( 'test.dll' )
# define ADD_EXPORT Q_DECL_EXPORT
extern "C" ADD_EXPORT int addnum(int num1,int num2)
{
return num1+num2;
}
extern "C" ADD_EXPORT void get_path(char *path){
memcpy(path,"hello",sizeof("hello"));
}
dll=ctypes.CDLL("add.dll")
add=dll.addnum
add.argtypes=[ctypes.c_int,ctypes.c_int] #参数类型
add.restypes=ctypes.c_int #返回值类型
print add(1,2)
get_path=dll.get_path
get_path.argtypes=[ctypes.c_char_p]
path=create_string_buffer(100)
get_path(path)
print path.value
GetSystemDirectory = windll.kernel32.GetSystemDirectoryA buf = create_string_buffer(100) GetSystemDirectory(buf,100) print buf.value MessageBox = windll.user32.MessageBoxW MessageBox(None, u"Hello World", u"Hi", 0)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有