问题
Note:
- Pass BSTR variable to COM method, HRESULT return is
8000FFFF - Previous calls with interface pointer, was successful: HRESULT is
0 - Execution, inside Visual Studio succeeds, outside fails - release and debug
Illustration:
const char *simFile;
simFile = new char;
//omitted
_bstr_t simFileToOpen(simFile);
BSTR raw_sim_Open = simFileToOpen.copy();
SysFreeString(simFileToOpen);
delete simFile;
hresult = pis8->raw_Open (raw_sim_Open); //0x8000FFFF returned
回答1:
simFile looks to be a single character stored inside a const char*.
It is not a NULL terminated string, unless it is an empty string and it's contents are 0. Are you sure you didn't mean to do something like:
const char *simFile = new char[1024];
strcpy(simFile, "path");
Even better yet you can just use SysAllocString to get a BSTR directly.
BSTR str = SysAllocString(_T("path"));
来源:https://stackoverflow.com/questions/669347/com-method-call-returns-catastrophic-failure