3

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?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.