共用方式為


ASSEMBLY_FILE_DETAILED_INFORMATION結構 (winnt.h)

QueryActCtxW 函式會使用ASSEMBLY_FILE_DETAILED_INFORMATION結構。

語法

typedef struct _ASSEMBLY_FILE_DETAILED_INFORMATION {
  DWORD  ulFlags;
  DWORD  ulFilenameLength;
  DWORD  ulPathLength;
  PCWSTR lpFileName;
  PCWSTR lpFilePath;
} ASSEMBLY_FILE_DETAILED_INFORMATION, *PASSEMBLY_FILE_DETAILED_INFORMATION;

成員

ulFlags

這個值一定是 0。

ulFilenameLength

lpFileName 所指向之檔名的位元組長度。 計數不包含終止的 Null 字元。

ulPathLength

lpFilePath 所指向之路徑字串的位元組長度 計數不包含終止的 Null 字元。

lpFileName

指定檔名的 Null 終止字串。

lpFilePath

以 Null 結尾的字串,指定 lpFileName 中名為 之檔案的路徑。

備註

如果使用 FileInformationInAssemblyOfAssemblyInActivationContext 選項呼叫 QueryActCtxW ,而且函式會成功,傳回緩衝區中的資訊會以 ASSEMBLY_FILE_DETAILED_INFORMATION 結構的形式呼叫。 以下是結構範例,可用來保存啟動內容和 來自QueryActCtxW的呼叫詳細資訊。

PASSEMBLY_FILE_DETAILED_INFORMATION pAssemblyInfo = NULL;
ACTIVATION_CONTEXT_QUERY_INDEX QueryIndex;
BOOL fSuccess = FALSE;
SIZE_T cbRequired;
HANDLE hActCtx = INVALID_HANDLE_VALUE;
BYTE bTemporaryBuffer[512];
PVOID pvDataBuffer = (PVOID)bTemporaryBuffer;
SIZE_T cbAvailable = sizeof(bTemporaryBuffer);

// Request the first file in the root assembly
QueryIndex.ulAssemblyIndex = 1;
QueryIndex.ulFileIndexInAssembly = 0;

if (GetCurrentActCtx(&hActCtx)) {

    // Attempt to use our stack-based buffer first - if that's not large
    // enough, allocate from the heap and try again.
    fSuccess = QueryActCtxW(
        0, 
        hActCtx, 
        (PVOID)&QueryIndex, 
        FileInformationInAssemblyOfAssemblyInActivationContext,
        pvDataBuffer,
        cbAvailable,
        &cbRequired);

    // Failed, because the buffer was too small.
    if (!fSuccess && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {

        // Allocate what we need from the heap - fail if there isn't enough
        // memory to do so.        
        pvDataBuffer = HeapAlloc(GetProcessHeap(), 0, cbRequired);
        if (pvDataBuffer == NULL) {
            fSuccess = FALSE;
            goto DoneQuerying;
        }
        cbAvailable = cbRequired;

        // If this fails again, exit out.
        fSuccess = QueryActCtxW(
            0, 
            hActCtx,
            (PVOID)&QueryIndex,
            FileInformationInAssemblyOfAssemblyInActivationContext,
            pvDataBuffer,
            cbAvailable,
            &cbRequired);

    }

    if (fSuccess) {
        // Now that we've found the assembly info, cast our target buffer back to
        // the assembly info pointer.  Use pAssemblyInfo->lpFileName
        pAssemblyInfo = (PASSEMBLY_FILE_DETAILED_INFORMATION)pvDataBuffer;
    }
}

DoneQuerying:
    if (hActCtx != INVALID_HANDLE_VALUE)
        ReleaseActCtx(hActCtx);

    if (pvDataBuffer && (pvDataBuffer != bTemporaryBuffer)) {
        HeapFree(GetProcessHeap(), 0, pvDataBuffer);
        pvDataBuffer = 0;
    }

規格需求

需求
最低支援的用戶端 Windows XP [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2003 [僅限桌面應用程式]
標頭 winnt.h (包含 Windows.h)