Created
October 21, 2019 18:18
-
-
Save peteristhegreat/924832e88806b05dafd434fb1e71252c to your computer and use it in GitHub Desktop.
Print HRESULT values from Julia, CoInitializeEx and CLSIDFromString examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _crypt32 = "Crypt32.dll" | |
const _ole32 = "Ole32.dll" | |
HANDLE = Ptr{Cvoid} | |
HCRYPTPROV = HANDLE | |
HCRYPTPROV_LEGACY = HCRYPTPROV | |
HCERTSTORE = HANDLE | |
LPWSTR = Cwstring | |
LPCWSTR = Cwstring | |
LPCOLESTR = Cwstring | |
LPSTR = Cstring | |
BOOL = Cint | |
BYTE = Cuchar | |
DWORD = Culong | |
LPCLSID = Ptr{UInt128} | |
BSTR = Cwstring | |
HRESULT = Int32 | |
LPVOID = Ptr{Cvoid} | |
REFCLSID = Ptr{UInt128} | |
LPUNKNOWN = HANDLE | |
REFIID = Ptr{UInt128} | |
hr = ccall((:CoInitializeEx, _ole32), HRESULT, (LPVOID, DWORD), | |
C_NULL, COINIT_APARTMENTTHREADED) | |
hr < 0 && error("Failed CoInitializeEx: HRESULT 0x$(string(reinterpret(UInt32, hr),base=16))") | |
CLSID_CCertAdmin = Vector{UInt128}(undef, 1) | |
hr = ccall((:CLSIDFromString, _ole32), HRESULT, (LPCOLESTR, LPCLSID), | |
"{37eabaf0-7fb6-11d0-8817-00a0c903b83c}", pointer(CLSID_CCertAdmin)) | |
hr < 0 && error("Failed IFactory::CreateInstance ppv: HRESULT 0x$(string(reinterpret(UInt32, hr),base=16))") | |
# The syntax to get the hresults is tricky, but this works: 0x$(string(reinterpret(UInt32, hr),base=16)) | |
# S_OK Operation successful 0x00000000 | |
# E_ABORT Operation aborted 0x80004004 | |
# E_ACCESSDENIED General access denied error 0x80070005 | |
# E_FAIL Unspecified failure 0x80004005 | |
# E_HANDLE Handle that is not valid 0x80070006 | |
# E_INVALIDARG One or more arguments are not valid 0x80070057 | |
# E_NOINTERFACE No such interface supported 0x80004002 | |
# E_NOTIMPL Not implemented 0x80004001 | |
# E_OUTOFMEMORY Failed to allocate necessary memory 0x8007000E | |
# E_POINTER Pointer that is not valid 0x80004003 | |
# E_UNEXPECTED Unexpected failure 0x8000FFFF | |
# "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment