Skip to content

Commit 252b52a

Browse files
authored
Improve COM ctor exception code for failing ProgIDs (GH-17673)
The `$module_name` of `com::__construct()` can be a ProgID, ClassID or moniker. We first try `CLSIDFromString()`, and if that fails, we go ahead and try to treat the `$module_name` as a moniker. If that also fails, we throw an exception with the result of `MkParseDisplayName()` what would just be `MK_E_SYNTAX` if given a ProgID. This result is highly confusing for the common case where a ProgID is given, which is not registered (e.g. due to a typo). In this case, we use the original `HRESULT` (`CO_E_CLASSSTRING`) instead.
1 parent fe9c904 commit 252b52a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/com_dotnet/com_com.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PHP_METHOD(com, __construct)
3838
OLECHAR *moniker;
3939
CLSID clsid;
4040
CLSCTX ctx = CLSCTX_SERVER;
41-
HRESULT res = E_FAIL;
41+
HRESULT res = E_FAIL, res2;
4242
ITypeLib *TL = NULL;
4343
COSERVERINFO info;
4444
COAUTHIDENTITY authid = {0};
@@ -142,7 +142,7 @@ PHP_METHOD(com, __construct)
142142
}
143143
}
144144

145-
if (FAILED(CLSIDFromString(moniker, &clsid))) {
145+
if (FAILED(res2 = CLSIDFromString(moniker, &clsid))) {
146146
/* try to use it as a moniker */
147147
IBindCtx *pBindCtx = NULL;
148148
IMoniker *pMoniker = NULL;
@@ -182,6 +182,9 @@ PHP_METHOD(com, __construct)
182182
if (pBindCtx) {
183183
IBindCtx_Release(pBindCtx);
184184
}
185+
if (FAILED(res) && res2 == CO_E_CLASSSTRING && !wcspbrk(moniker, L"\\:")) {
186+
res = res2;
187+
}
185188
} else if (server_name) {
186189
MULTI_QI qi;
187190

0 commit comments

Comments
 (0)