Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions DummyLoader/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID
// DllRegisterServer - Adds entries to the system registry.
STDAPI DllRegisterServer()
{
// registers object, typelib and all interfaces in typelib
return _AtlModule.DllRegisterServer();
return _AtlModule.DllRegisterServer(FALSE); // skip TypeLib registration since that is the responsibility of the host
}

// DllUnregisterServer - Removes entries from the system registry.
STDAPI DllUnregisterServer()
{
return _AtlModule.DllUnregisterServer();
return _AtlModule.DllUnregisterServer(FALSE); // skip TypeLib unregistration for consistency with DllRegisterServer
}

// DllInstall - Adds/Removes entries to the system registry per user per machine.
Expand Down
15 changes: 15 additions & 0 deletions SandboxTest/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ int wmain(int argc, wchar_t *argv[]) {
}
}

// register type library to enable out-of-proc Image3dAPI calls
// only works if running as admin
CComPtr<ITypeLib> typelib;
HRESULT hr = LoadTypeLibEx(L"Image3dAPI.tlb", REGKIND_REGISTER, &typelib);
CHECK(hr);

#if 0
// unregister type library
TLIBATTR * tlb_attr = nullptr;
CHECK(typelib->GetLibAttr(&tlb_attr));
hr = UnRegisterTypeLib(tlb_attr->guid, tlb_attr->wMajorVerNum, tlb_attr->wMinorVerNum, tlb_attr->lcid, tlb_attr->syskind);
CHECK(hr);
typelib->ReleaseTLibAttr(tlb_attr);
#endif

// create loader in a separate "low integrity" dllhost.exe process
CComPtr<IImage3dFileLoader> loader;
CComPtr<IImage3dSource> source;
Expand Down
4 changes: 1 addition & 3 deletions TestPython/TestPython.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions TestPython/TestPython.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
22 changes: 0 additions & 22 deletions TestPython/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down