Activator.CreateInstance() works inside VSIDE but not externally

前端 未结 7 1512
天涯浪人
天涯浪人 2020-12-19 07:50

I have a bunch of COM objects which all implement the same interface, and need to create one of them as chosen at runtime from a list of options. Since I know the CLSID for

7条回答
  •  半阙折子戏
    2020-12-19 08:47

    This Question is old (and answered), but I thought I would add a little information.

    Adobe X (10.1.x) will fail to provide an IFilter interface under some conditions. Calls to QueryInterface, or ClassFactory->CreateInstance or ::LoadIFilter or whatever will fail with E_FAIL. The condition I'm referring to is when the process that is running is not part of a "Job".

    I.e., their 10.x IFilter checks to see if the current process is in any job. If not, it fails (for me at least). My work around is something like the following psuedo-code:

    HANDLE curProc = GetCurrentProcess();
    BOOL bResult = FALSE;
    int iResult = IsProcessInJob(curProc, NULL, &bResult);
    if(iResult != 0 && bResult == FALSE) {
        HANDLE hJob = CreateJobObject(NULL,"whatever");
        AssignProcessToJob(hJob,curProc);
    }
    

    There may be side effects to this, i.e., the new job gets default security of the current user. I have more testing to do. I welcome anyone's input.

提交回复
热议问题