2017-09-26 45 views
0

自分の入力デバイスをマイクなど(マイクなど)にリストしたいとします。pythonでwinmm.dllを使用して入力デバイスを取得する

コードはここにある:

from ctypes import * 
    import sys 
    #printf = libc.printf 
    winmm = windll.LoadLibrary("winmm.dll") 
    widn = winmm.waveInGetDevCapsA #wave in device num 
    widn.restype = c_uint 

    waveNum = winmm.waveInGetNumDevs 

    class LPWAVEINCAPS(Structure): 
     _fields_ = [ 
      ("wMid",c_ushort), 
      ("wPid",c_ushort), 
      ("vDriverVersion",c_uint), 
      ("szPname",c_wchar_p), 
      ("dwFormats",c_uint), 
      ("wChannels",c_ushort), 
      ("wReserved1",c_ushort), 
      ] 

    widn.argtypes = [ 
     c_uint, 
     POINTER(LPWAVEINCAPS), 
     c_uint 
     ] 

    count_devs = waveNum() 

    print(count_devs) 

    structLP = LPWAVEINCAPS() 

    for i in range(count_devs): 
     str = widn(c_uint(i),byref(structLP),c_uint(sys.getsizeof(structLP))) 
     print(structLP.szPname) 

出力は、セグメントの障害であると私はbyrefを削除するときには、出力として私をNone与えました。

私は問題を解決し、私はそんなにあなたに感謝してください:)

答えて

0

を助ける:

問題は私の文字列ポインタだった、私は構造で

from ctypes import * 
import sys 
#printf = libc.printf 
winmm = windll.LoadLibrary("winmm.dll") 
widn = winmm.waveInGetDevCapsA #wave in device num 
widn.restype = c_uint 

waveNum = winmm.waveInGetNumDevs 

s = create_string_buffer(b'\000' * 32) 

class LPWAVEINCAPS(Structure): 
    _fields_ = [ 
     ("wMid",c_ushort), 
     ("wPid",c_ushort), 
     ("vDriverVersion",c_uint), 
     ("szPname", type(s)), 
     ("dwFormats",c_uint), 
     ("wChannels",c_ushort), 
     ("wReserved1",c_ushort), 
     ] 

widn.argtypes = [ 
    c_uint, 
    POINTER(LPWAVEINCAPS), 
    c_uint 
    ] 

count_devs = waveNum() 

print(count_devs) 

structLP = LPWAVEINCAPS() 

for i in range(count_devs): 
    print(sizeof(type(structLP))) 
    str = widn(c_uint(i),byref(structLP),sizeof(structLP)) 
    print(structLP.szPname) 
#waveCaps = winmm.waveOutGetDevCaps 
waveNum.restype = c_uint 
#waveCaps.argtypes = [] 
s = create_string_buffer(b'\000' * 32)を使用して、 ("szPname", type(s))
関連する問題