共用方式為


IAttachmentExecute 介面 (shobjidl_core.h)

公開使用用戶端應用程式來呈現使用者環境的方法,以透過電子郵件和傳訊附件提供安全的檔案下載和交換。

繼承

IAttachmentExecute介面繼承自IUnknown介面。 IAttachmentExecute 也有下列類型的成員:

方法

IAttachmentExecute介面具有這些方法。

 
IAttachmentExecute::CheckPolicy

提供布林值測試,可用來根據附件的執行原則做出決策。
IAttachmentExecute::ClearClientState

移除以用戶端 GUID 為基礎的任何預存狀態。 例如,可能是以核取方塊為基礎的設定,指出特定檔案類型不應該再次顯示提示。
IAttachmentExecute::Execute

在附件上執行動作。
IAttachmentExecute::P rompt

向使用者顯示提示 UI。
IAttachmentExecute::Save

儲存附件。
IAttachmentExecute::SaveWithUI

如果儲存動作失敗,則向使用者顯示說明錯誤 UI。
IAttachmentExecute::SetClientGuid

指定並儲存用戶端的 GUID。
IAttachmentExecute::SetClientTitle

指定並儲存提示視窗的標題。
IAttachmentExecute::SetFileName

指定並儲存檔案的建議名稱。
IAttachmentExecute::SetLocalPath

設定並儲存檔案的路徑。
IAttachmentExecute::SetReferrer

根據參考檔案,設定與附件檔案相關聯的安全性區域。
IAttachmentExecute::SetSource

設定檔案傳輸來源的替代路徑或 URL。

備註

此介面假設下列專案:

  • 用戶端具有附件支援和行為的原則或設定。
  • 用戶端會與使用者互動。
此介面的 IID IID_IAttachmentExecute

以下是電子郵件客戶程式如何使用 IAttachmentExecute的範例。


// CClientAttachmentInfo, defined by the client, implements all the
// necessary client functionality concerning attachments. 
class CClientAttachmentInfo;  

// Creates an instance of IAttachmentExecute
HRESULT CreateAttachmentServices(IAttachmentExecute **ppae)
{
    // Assume that CoInitialize has already been called for this thread.
    HRESULT hr = CoCreateInstance(CLSID_AttachmentServices, 
                                  NULL, 
                                  CLSCTX_INPROC_SERVER, 
                                  IID_IAttachmentExecute, 
                                  (void**)&pAttachExec);

    if (SUCCEEDED(hr))
    {
        // Set the client's GUID.

        // UUID_ClientID should be created using uuidgen.exe and 
        // defined internally.
        (*ppae)->SetClientGuid(UUID_ClientID);
        
        // You also could call SetClientTitle at this point, but it is
        // not required.
    }
    return hr;
}

BOOL IsAttachmentBlocked(CClientAttachmentInfo *pinfo)
{
    // Assume that a client function has copied the file from the mail store 
    // into a temporary file.
    PWSTR pszFileName;

    // GetFileName is a method in this class for which we do not provide
    // an implementation here.
    HRESULT hr = pinfo->GetFileName(&pszFileName);
    if (SUCCEEDED(hr))
    {
        IAttachmentExecute *pExecute;

        hr = CreateAttachmentServices(&pExecute);
        if (SUCCEEDED(hr))
        {
            hr = pExecute->SetFileName(pszFileName);

            // Do not call SetLocalPath since we do not have the local path yet.
            // Do not call SetSource since email sources are not verifiable.
            // Do not call SetReferrer since we do not have a better zone 
            // than the default (Restricted sites).

            // Check for a policy regarding the file.
            if (SUCCEEDED(hr))
            {
                hr = pExecute->CheckPolicy();
            }
            pExecute->Release();
        }
        LocalFree(pszFileName);
    }
    return FAILED(hr);
}
    
HRESULT OnDoubleClickAttachment(HWND hwnd, CClientAttachmentInfo *pinfo)
{
    // Assume that a client function has copied the file from the mail store 
    // into a temporary file.
    PWSTR pszTempFile;

    // CopyToTempFile is a method in this class for which we do not provide
    // an implementation here.
    HRESULT hr = pinfo->CopyToTempFile(&pszTempFile);
    if (SUCCEEDED(hr))
    {
        IAttachmentExecute *pExecute;

        hr = CreateAttachmentServices(&pExecute);
        if (SUCCEEDED(hr))
        {
            hr = pExecute->SetLocalPath(pszTempFile);

            // Do not call SetFileName since we already have the local path.
            // Do not call SetSource since email sources are not verifiable.
            // Do not call SetReferrer since we do not have a better zone 
            // than the default (Restricted sites).

            if (SUCCEEDED(hr))
            {
                hr = pExecute->Execute(hwnd, NULL, NULL);
            }
            pExecute->Release();
        }
        LocalFree(pszTempFile);
    }
    return hr;
}

HRESULT OnSaveAttachment(HWND hwnd, CClientAttachmentInfo *pinfo)
{
    // Assume that a client function has copied the file from the mail store 
    // into a location selected by the user.
    PWSTR pszUserFile;

    // CopyToUserFile is a method in this class for which we do not provide
    // an implementation here.
    HRESULT hr = pinfo->CopyToUserFile(hwnd, &pszUserFile);
    if (SUCCEEDED(hr))
    {
        IAttachmentExecute *pExecute;

        hr = CreateAttachmentServices(&pExecute);
        if (SUCCEEDED(hr))
        {
            hr = pExecute->SetLocalPath(pszTempFile);

            // Do not call SetFileName since we have the local path.
            // Do not call SetSource since email sources are not verifiable.
            // Do not call SetReferrer since we do not have a better zone 
            // than the default (Restricted sites).

            if (SUCCEEDED(hr))
            {
                hr = pExecute->Save();
            }
            pExecute->Release();
        }
        LocalFree(pszUserFile);
    }
    return hr;
}

規格需求

   
最低支援的用戶端 具有 SP2 的 Windows XP [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2003 [僅限桌面應用程式]
目標平台 Windows
標頭 shobjidl_core.h