2 Nov 2004 00:41
RE: ctypes
Andrew MacIntyre <Andrew.MacIntyre <at> aba.gov.au>
2004-11-01 23:41:13 GMT
2004-11-01 23:41:13 GMT
You're
creating a pointer to the string
"OSVERSIONINFO".
Instead pass the
structure's address with byref():
f.GetVersionExA(byref(x))
-----------------------------------------------------------------------
Andrew MacIntyre \ E-mail: andrew.macintyre <at> aba.gov.au
Planning & Licensing Branch \ Tel: +61 2 6256 2812
Australian Broadcasting Authority \ Fax: +61 2 6253 3277
-> "These thoughts are mine alone!" <----------------------------------
Andrew MacIntyre \ E-mail: andrew.macintyre <at> aba.gov.au
Planning & Licensing Branch \ Tel: +61 2 6256 2812
Australian Broadcasting Authority \ Fax: +61 2 6253 3277
-> "These thoughts are mine alone!" <----------------------------------
-----Original Message-----
From: Goran [mailto:gblankendal <at> curlink.com]
Sent: Monday, 1 November 2004 7:20 AM
To: ctypes-users <at> lists.sourceforge.net
Subject: [ctypes-users] ctypes
Hi,I'm trying to get the os version info, but I get an error.
What is wrong with my script?from ctypes import *
import ctypes#According to the msdn we need to define an OSVERSIONINFO Structure:class OSVERSIONINFO(Structure):
_fields_ = [("dwOSVersionInfoSize",c_long),
("dwMajorVersion", c_long),
("dwMinorVersion", c_long),
("dwBuildNumber", c_long),
("dwPlatformId", c_long),
("szCSDVersion", c_char_p*128)]lpOSVERSIONINFO = POINTER("OSVERSIONINFO")x=OSVERSIONINFO()
x.dwOSVersionInfoSize=ctypes.sizeof(OSVERSIONINFO)
f=windll.kernel32
f.GetVersionExA(lpOSVERSIONINFO)print "Version number: " + str(x.dwMajorVersion) + "." + str(x.dwMinorVersion)
print "Build number: " + str(x.dwBuildNumber)
print "Platform Id: " + str(x.dwPlatformId)
for pt in x.szCSDVersion:
print pt,Traceback (most recent call last):
File "E:\PYTHON24\LIB\SITE-PACKAGES\PYTHONWIN\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "E:\Python24\Projects\OsVersionInfo.py", line 17, in ?
f.GetVersionExA(lpOSVERSIONINFO)
ArgumentError: argument 1: exceptions.TypeError: Don't know how to convert parameter 1
"""
# A couple of example debug output lines:
# [Iexplore] # Unimplemented (NavigateComplete2 ('(9)', '(16396)'))
# [Iexplore] url (16396)
import sys
import _winreg
from ctypes import *
from ctypes.com import IUnknown, PIUnknown, REFIID, GUID, STDMETHOD, HRESULT, \
COMObject
from ctypes.com.automation import IDispatch, BSTR, VARIANT, \
dispinterface, DISPMETHOD
from ctypes.com.register import Registrar
from ctypes.com.connectionpoints import dispinterface_EventReceiver, \
GetConnectionPoint
from ctypes.com.hresult import S_OK, E_FAIL
import ie6 # module generated by ctypes/com/tools/readtlb.py
HKLM = _winreg.HKEY_LOCAL_MACHINE
BHO_KEY = ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\"
"Browser Helper Objects\\")
class MyRegistrar(Registrar):
def build_table(self):
table = Registrar.build_table(self)
table.extend([(HKLM, BHO_KEY+self._reg_clsid_, "", None)])
return table
class IObjectWithSite(IUnknown):
_iid_ = GUID("{FC4801A3-2BA9-11CF-A229-00AA003D7352}")
_methods_ = IUnknown._methods_ + [
(STDMETHOD(HRESULT, "SetSite", POINTER(IUnknown))),
(STDMETHOD(HRESULT, "GetSite", REFIID, POINTER(POINTER(IUnknown))))]
class PythonBHO(COMObject):
_reg_clsid_ = "{693D1AC0-2D77-11D8-9B9E-FB41F7E93A45}"
_reg_progid_ = "PythonBHO"
_com_interfaces_ = [IObjectWithSite]
def _get_registrar(cls):
return MyRegistrar(cls)
_get_registrar = classmethod(_get_registrar)
_site = None
def IObjectWithSite_SetSite(self, this, pUnkSite):
self._site = pUnkSite
return S_OK
def IObjectWithSite_GetSite(self, this, riid, ppvSite):
if self._site is not None:
return self._site.QueryInterface(riid, ppvSite)
# I'm not sure the following is correct
ppvSite[0] = POINTER(IUnknown)() # set to a NULL pointer
# or should it be this?
## ppvSite[0] = 0
return S_OK
class DWebBrowserEvents2Impl(dispinterface_EventReceiver):
_com_interfaces_ = [ie6.DWebBrowserEvents2]
def OnQuit(self, this, *args):
self.disconnect(self.handle)
def BeforeNavigate2(self, this, pDisp, url, Flags, TargetFrameName,
PostData, Headers, Cancel):
print "url", url
if __name__ == '__main__':
from ctypes.com.server import UseCommandLine
UseCommandLine(PythonBHO)
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
RSS Feed