ctypes.windll.kernel32.GetProcAddress returns address of 0

Jason Marshall <[email protected]> Sat, 14 Jun 2014 05:41:11 -0700 (PDT)
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Hello ctypes-users,


I am a novice at ctypes and C. I am trying to get the addresses of some methods in ddraw.dll (obsolete, I know) so that I may use them with pygame. When I run the script below to get the methods' addresses, ctypes.windll.kernel32.GetProcAddress gives me addresses of 0. Can you see something that I'm doing wrong?


I have tried this in Python 2.7 (32-bit) under Win 7 (64-bit) and Python 2.5 (32-bit) under Win XP (32-bit). I got the same result in both environments.


Thanks,
Jason


# coding: cp1252
# What I am trying to do:
#   http://www.nerdblog.com/2010/04/fun-vertical-sync-hack.html
#
# DirectDrawCreate function
#   http://msdn.microsoft.com/en-us/library/windows/desktop/gg426116%28v=vs.85%29.aspx
# IDirectDraw7::GetMonitorFrequency method
#   http://msdn.microsoft.com/en-us/library/windows/desktop/gg426148%28v=vs.85%29.aspx
# IDirectDraw7::GetScanLine method
#   http://msdn.microsoft.com/en-us/library/windows/desktop/gg426149%28v=vs.85%29.aspx
# 
# DirectX headers
#   http://www.steve-oh.com/blog/index.php/directx-70a-sdk-download/
#
# scary GUID structure
#   https://code.google.com/p/pyglet/source/browse/pyglet/com.py
# scary pointer to a pointer
#   http://stackoverflow.com/questions/8638942/python-ctypes-pointer-to-pointer-to-structure

import ctypes
from ctypes import POINTER, WINFUNCTYPE, byref, c_int, c_char_p, c_void_p, windll, wintypes

DD_OK = 0

# Load DirectDraw DLL
ddraw_dll = windll.LoadLibrary("ddraw")

# Initialize DirectDraw with DirectDrawCreate
class GUID(ctypes.Structure):
    _fields_ = [
        ('Data1', ctypes.c_ulong),
        ('Data2', ctypes.c_ushort),
        ('Data3',
 ctypes.c_ushort),
        ('Data4', ctypes.c_ubyte * 8)
    ]


    def __init__(self, l=0x6C14DB80, w1=0xA733, w2=0x11CE, b1=0xA5, b2=0x21, b3=0x00, b4=0x20, b5=0xAF, b6=0x0B, b7=0xE5, b8=0x60): # IID_IDirectDraw
        self.Data1 = l
        self.Data2 = w1
        self.Data3 = w2
        self.Data4[:] = (b1, b2, b3, b4, b5, b6, b7, b8)

    def __repr__(self):
        b1, b2, b3, b4, b5, b6, b7, b8 = self.Data4
        return 'GUID(%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x)' % (
            self.Data1, self.Data2, self.Data3, b1, b2, b3, b4, b5, b6, b7, b8)

DirectDrawCreate = ddraw_dll.DirectDrawCreate
DirectDrawCreate.argtypes = [c_void_p,
 POINTER(POINTER(GUID)), c_void_p]
control = POINTER(GUID)()
result = DirectDrawCreate(None, byref(control), None)

print "DirectDrawCreate result (0 is DD_OK):", result
assert result == DD_OK, "DirectDraw did not initialize"

# Get GetMonitorFrequency function's address
windll.kernel32.GetProcAddress.argtypes = [c_void_p, c_char_p]
GetMonitorFrequency_addr = windll.kernel32.GetProcAddress(ddraw_dll._handle, "GetMonitorFrequency")
print "GetMonitorFrequency_addr", hex(GetMonitorFrequency_addr)

# Get GetScanLine function's address
GetScanLine_addr = windll.kernel32.GetProcAddress(ddraw_dll._handle, "GetScanLine")
print "GetScanLine_addr", hex(GetScanLine_addr)

------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users