python调用window dll和linux so例子

时间:2022-12-12 14:27:08

#!/usr/bin/python
# -*- coding: UTF-8 -*-
#python dll.py
import win32api
# 打开记事本程序,在后台运行,即显示记事本程序的窗口
win32api.ShellExecute(0, 'open', 'notepad.exe', '','',1)
import win32process
win32process.CreateProcess('c:\\windows\\notepad.exe', '',
None , None , 0 ,win32process. CREATE_NO_WINDOW , None , None ,
win32process.STARTUPINFO())

handle = win32process.CreateProcess('c:\\windows\\notepad.exe',
'', None , None , 0 ,win32process. CREATE_NO_WINDOW , None , None ,
win32process.STARTUPINFO())
# 使用TerminateProcess函数终止记事本程序
win32process.TerminateProcess(handle[0],0)

from ctypes import *
user32 = windll.LoadLibrary('user32.dll') # 加载动态链接库
user32.MessageBoxA(0, 'Ctypes is cool!', 'Ctypes', 0)
# 调用MessageBoxA函数.

#!/usr/bin/python
# -*- coding: UTF-8 -*-
#python so.py
from ctypes import *
libc = cdll.LoadLibrary('/lib/i386-linux-gnu/libc.so.6') # 加载动态链接库
# 调用 printf 函数.
libc.printf('Ctypes is cool! %s\n', 'Ctypes')

libc.printf('pid=%d uid=%d\n', libc.getpid(),libc.getuid())

libc.printf('time=%d\n', libc.time(0))
libc.system("ping wwww.baidu.com -c 2")

---------------------
作者:yunshouhu
来源:CSDN
原文:https://blog.csdn.net/earbao/article/details/54287567
版权声明:本文为博主原创文章,转载请附上博文链接!