Tim Roberts wrote:
> J wrote:
>   
>> On Tue, Jan 5, 2010 at 16:53, Tim Roberts <t...@probo.com> wrote:
>>   
>>
>>     
>>> C:\tmp>python
>>> Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
>>> (Intel)] onwin32
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>  >>> import ctypes
>>>  >>> c = ctypes.windll.cpuid
>>>  >>> hex(c.GetCpuidEcx())
>>> '0x444d4163'
>>>  >>> hex(c.GetCpuidEdx())
>>> '0x69746e65'
>>>     
>>>       
>> Also have to figure out how to decode the hex value into a more user
>> friendly format ;-)  

OK, so I was being overly clever, showing off a bit, demonstrating that
it's possible to build a minimal DLL in assembler.  It turns out you can
do the same thing in Visual C++:

c:\tmp>type cpuid.c
#include <intrin.h>

int
GetCpuidEcx( int var )
{
    int parts[4];
    __cpuid( parts, var );
    return parts[2];
}

int
GetCpuidEdx( int var )
{
    int parts[4];
    __cpuid( parts, var );
    return parts[3];
}
C:\tmp>cl /LD cpuid.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08
for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cpuid.c
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:cpuid.dll
/dll
/implib:cpuid.lib
cpuid.obj
   Creating library cpuid.lib and object cpuid.exp

C:\tmp>python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
  >>> import ctypes
  >>> c = ctypes.cdll.cpuid
  >>> c.GetCpuidEcx(1)
1
  >>> hex(c.GetCpuidEdx(1))
'0x178bfbff'
  >>>

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to