2

This is a part of my code:

import os

def _get_appdata_path():
    import ctypes
    from ctypes import wintypes, windll
    CSIDL_APPDATA = 26
    _SHGetFolderPath = windll.shell32.SHGetFolderPathW
    _SHGetFolderPath.argtypes = [wintypes.HWND,
                                 ctypes.c_int,
                                 wintypes.HANDLE,
                                 wintypes.DWORD,
                                 wintypes.LPCWSTR]
    path_buf = wintypes.create_unicode_buffer(wintypes.MAX_PATH)
    result = _SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, path_buf)
    return path_buf.value

But when I call wintypes.create_unicode_buffer() I get the error:

AttributeError: module 'ctypes.wintypes' has no attribute 'create_unicode_buffer'

I am using Python 3.5.1. What could I do?

kame
  • 20,848
  • 33
  • 104
  • 159
  • 2
    http://stackoverflow.com/questions/626796/how-do-i-find-the-windows-common-application-data-folder-using-python#comment33587651_626927 – gplayer Oct 17 '16 at 11:06

1 Answers1

6

Use ctypes.create_unicode_buffer, which works in both PY2 and PY3. It was only accidentally in wintypes in PY2 due to its use of from ctypes import *. :D

gplayer
  • 1,741
  • 1
  • 14
  • 15