I wrote the following C++ code, trying to perform some OLE automation tasks for currently-running Photoshop:
IUnknown* unk = NULL;
IDispatch* disp = NULL;
CLSID clsId;
if (FAILED(CLSIDFromProgID(L"Photoshop.Application", &clsId)))
goto err;
puts("CLSIDFromProgID succeeded");
if (FAILED(GetActiveObject(&clsId, NULL, &unk)))
goto err;
puts("GetActiveObject succeeded");
if (FAILED(IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp)))
goto err;
puts("QueryInterface succeeded");
DISPID dispId;
HRESULT resultOfGettingId = IDispatch_GetIDsOfNames(disp, &IID_NULL,
(LPOLESTR[1]){L"ActiveDocument"}, 1,
LOCALE_USER_DEFAULT, &dispId);
if (FAILED(resultOfGettingId))
{
//The code always goes here.
//The result code is printed as 0X8001010A,
//which is RPC_E_SERVERCALL_RETRYLATER.
printf("GetIDsOfNames for <ActiveDocument> failed. Result code: %#lX.\n",
resultOfGettingId);
goto err;
}
puts("GetIDsOfNames for Selection succeeded");
The above C++ code always prints the following text (whenever I run it):
GetIDsOfNames for <ActiveDocument> failed. Result code: 0X8001010A.
After searching for RPC_E_SERVERCALL_RETRYLATER, I found that the error code seems to mean that the application is busy. But Photoshop is just opened, and not being manipulated at all, and just contains only a single empty document. How can it always be busy?
And why does the equivalent C# code such as
try
{
activeDocument.activeLayer.textItem.font = "FZCYJW--GB1-0";
}
catch(e)
{
...
}
works fine?
It doesn't make sense that Photoshop just happens to be busy everytime when the C++ program is trying to connect.
Something problematic other than the so-called busyness must be hiden in the details but I just have no clue.
Edit:
Issued resloved!
I've found the culprit of "busyness". If Photoshop is in the state of selecting some text, then it fails, otherwise it succeeds. So when some text is selected, Photoshop is in a state where it thinks handleing COM call-ins out of process isn't a good idea.
I've found the culprit of "busyness". If Photoshop is in the state of selecting some text, then it fails, otherwise it succeeds. So when some text is selected, Photoshop is in a state where it thinks handling COM call-ins out of process isn't a good idea.
User contributions licensed under CC BY-SA 3.0