ctypes non-valid Win32 dll with valid win32 dll

246 views Asked by At

I am trying to wrap a small cpp file that gets the Jumbo icon for a file. However, when I try to call it from the command line started in the directory of the dll and use the following to call the dll, it doesn't work.

command line (in same dir as dll)

from ctypes import *
lib=ctypes.cdll.LoadLibrary("GetIcon.dll")

Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\ctypes__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "C:\Python27\lib\ctypes__init__.py", line 365, in init
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application

GetIcon.cpp

// GetIcon.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "stdafx.h"
#include <shlobj.h>
#include <shlguid.h>
#include <shellapi.h>
#include <commctrl.h>
#include <commoncontrols.h>

HICON GetJumboIcon(char *filePath);



HICON GetJumboIcon(LPCWSTR filePath) {
    SHFILEINFOW sfi = { 0 };
    SHGetFileInfo(filePath, -1, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX);
    //Get Image list for system
    HIMAGELIST* imageList;
    HRESULT hResult = SHGetImageList(SHIL_EXTRALARGE, IID_IImageList, (void**)&imageList);
    if (hResult == S_OK) {
        HICON hIcon;
        hResult = ((IImageList*)imageList)->GetIcon(sfi.iIcon, ILD_TRANSPARENT, &hIcon);

        if (hResult == S_OK) {
            //if it works, return it.
            return hIcon;
        }

    }
}

I am using x64 Python and I amm using VStudio 2013

0

There are 0 answers