| 16 | |
| 17 | |
| 18 | BIF_DECL(ComObject_Call) // Formerly BIF_ComObjCreate. |
| 19 | { |
| 20 | ++aParam; // Exclude `this` |
| 21 | --aParamCount; |
| 22 | |
| 23 | HRESULT hr; |
| 24 | CLSID clsid, iid; |
| 25 | for (;;) |
| 26 | { |
| 27 | #ifdef UNICODE |
| 28 | LPTSTR cls = TokenToString(*aParam[0]); |
| 29 | #else |
| 30 | CStringWCharFromTChar cls = TokenToString(*aParam[0]); |
| 31 | #endif |
| 32 | // It has been confirmed on Windows 10 that both CLSIDFromString and CLSIDFromProgID |
| 33 | // were unable to resolve a ProgID starting with '{', like "{Foo", though "Foo}" works. |
| 34 | // There are probably also guidelines and such that prohibit it. |
| 35 | if (cls[0] == '{') |
| 36 | hr = CLSIDFromString(cls, &clsid); |
| 37 | else |
| 38 | // CLSIDFromString is known to be able to resolve ProgIDs via the registry, |
| 39 | // but fails on registration-free classes such as "Microsoft.Windows.ActCtx". |
| 40 | // CLSIDFromProgID works for that, but fails when given a CLSID string |
| 41 | // (consistent with VBScript and JScript in both cases). |
| 42 | hr = CLSIDFromProgID(cls, &clsid); |
| 43 | if (FAILED(hr)) break; |
| 44 | |
| 45 | __int64 punk = 0; |
| 46 | if (aParamCount > 1) |
| 47 | { |
| 48 | hr = CLSIDFromString(CStringWCharFromTCharIfNeeded(TokenToString(*aParam[1])), &iid); |
| 49 | if (FAILED(hr)) break; |
| 50 | } |
| 51 | else |
| 52 | iid = IID_IDispatch; |
| 53 | |
| 54 | hr = CoCreateInstance(clsid, NULL, CLSCTX_SERVER, iid, (void **)&punk); |
| 55 | if (FAILED(hr)) break; |
| 56 | |
| 57 | _f_return(new ComObject(punk, iid == IID_IDispatch ? VT_DISPATCH : VT_UNKNOWN)); |
| 58 | } |
| 59 | ComError(hr, aResultToken); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | BIF_DECL(BIF_ComObjGet) |
nothing calls this directly
no test coverage detected