diff --git a/TestPython/TestPython.py b/TestPython/TestPython.py index d48fcff..11021a6 100644 --- a/TestPython/TestPython.py +++ b/TestPython/TestPython.py @@ -1,18 +1,16 @@ ## Sample code to demonstrate how to access Image3dAPI from a python script -import platform import comtypes import comtypes.client import numpy as np from utils import SafeArrayToNumpy from utils import FrameTo3dArray -from utils import TypeLibFromObject if __name__=="__main__": # create loader object loader = comtypes.client.CreateObject("DummyLoader.Image3dFileLoader") # cast to IImage3dFileLoader interface - Image3dAPI = TypeLibFromObject(loader) + Image3dAPI = comtypes.client.GetModule("Image3dAPI.tlb") loader = loader.QueryInterface(Image3dAPI.IImage3dFileLoader) # load file diff --git a/TestPython/TestPython.pyproj b/TestPython/TestPython.pyproj index 1b32374..55b901a 100644 --- a/TestPython/TestPython.pyproj +++ b/TestPython/TestPython.pyproj @@ -14,6 +14,7 @@ <RootNamespace>TestPython</RootNamespace> <LaunchProvider>Standard Python launcher</LaunchProvider> <EnableNativeCodeDebugging>False</EnableNativeCodeDebugging> + <Environment>PATH=$(SolutionDir)x64</Environment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <DebugSymbols>true</DebugSymbols> diff --git a/TestPython/utils.py b/TestPython/utils.py index 2325783..0466198 100644 --- a/TestPython/utils.py +++ b/TestPython/utils.py @@ -1,30 +1,8 @@ ## Sample code to demonstrate how to access Image3dAPI from a python script -import platform import comtypes -import comtypes.client import numpy as np -def TypeLibFromObject (object): - """Loads the type library associated with a COM class instance""" - import winreg - - with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, "CLSID\\"+object.__clsid+"\\TypeLib", 0, winreg.KEY_READ) as key: - typelib = winreg.EnumValue(key, 0)[1] - with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, "CLSID\\"+object.__clsid+"\\Version", 0, winreg.KEY_READ) as key: - version = winreg.EnumValue(key, 0)[1] - - try: - major_ver, minor_ver = version.split(".") - return comtypes.client.GetModule([typelib, int(major_ver), int(minor_ver)]) - except OSError as err: - # API 1.2-only compatibility fallback to avoid breaking existing loaders - if (version != "1.2") or (err.winerror != -2147319779): # Library not registered - raise # rethrow - # Fallback to TypeLib version 1.0 - return comtypes.client.GetModule([typelib, 1, 0]) - - def SafeArrayToNumpy (safearr_ptr, copy=True): """Convert a SAFEARRAY buffer to its numpy equivalent""" import ctypes