|
楼主 |
发表于 2012-5-6 15:26:04
|
显示全部楼层
用C语言生成一个简单的dll
- #include "stdafx.h"
- extern "C" _declspec(dllexport)int sum(int a, int b)
- {
- return a+b;
- }
复制代码 在pygtk中调用这个C函数- # coding=gbk
- import pygtk
- pygtk.require('2.0')
- import gtk
- import random
- from ctypes import *;
- dll=CDLL('dd.dll')
- #dll.sum(1,2)
- greetings = ["Hello World", "Witaj wiecie", u"世界に今日は",u"你好,世界"]
- def choose_greeting (greets):
- return greets[random.randint (0, len(greets) - 1)]
- def cb_clicked( button,label):
- label.set_text(choose_greeting(greetings))
- def cb2_clicked(button2 ):
- label.set_text(str(dll.sum(2,3)))
- window = gtk.Window ()
- window.set_default_size(200, 200)
- vbox = gtk.VBox ()
- button = gtk.Button("Hello World")
- label = gtk.Label (choose_greeting (greetings))
- button2 = gtk.Button("3+2=")
- window.add(vbox)
- vbox.add(label)
- vbox.pack_start(button, False, False)
- vbox.pack_start(button2, False, False)
- window.connect("delete-event", lambda a,b: gtk.main_quit())
- button.connect("clicked", cb_clicked, label)
- button2.connect("clicked", cb2_clicked)
- window.show_all()
- gtk.main()
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?马上加入
x
|