C#试图实现COM接口

时间:2017-02-12 04:50:36

标签: c# com com-interop sccm

我正在尝试在C#服务中实现COM接口。界面来自MS,并在此处记录:https://msdn.microsoft.com/en-us/library/hh948551.aspx。在我添加这个方法DownloadContent之前,一切正常。添加后,客户端COM服务崩溃与0xc0000005。这让我相信存在某种不匹配。

这是我的C#接口代码。

    [PreserveSig]
    [return: MarshalAs(UnmanagedType.Error)]
    int DownloadContent(
        [In]
        StringBuilder szContentId,
        [In]
        StringBuilder szContentVersion,
        [In]
        StringBuilder szRemotePath,
        [In]
        StringBuilder szLocalPath,
        [In]
        StringBuilder szNotifyEndpoint,
        [In]
        StringBuilder szNotifyData,
        [In]
        CCM_DTS_PRIORITY Priority,
        [In]
        int dwTimeoutSeconds,
        [In]
        int dwChunkSize,
        [In]
        int dwFlags,
        [In]
        StringBuilder szLocationOptions,
        [In]
        StringBuilder szFileManifest,
        [In]
        StringBuilder szOwnerSID,
        [In]
        [MarshalAs(UnmanagedType.Bool)]
        bool bDeleteJobOnError,
        [In]
        StringBuilder szProviderData,
        [In]
        StringBuilder szPackageData,
        [Out]
        out Guid pJobID
    );

使用regasm.exe / tlb构建类型库我得到以下IDL:

    HRESULT DownloadContent(
                    [in] LPWSTR szContentId, 
                    [in] LPWSTR szContentVersion, 
                    [in] LPWSTR szRemotePath, 
                    [in] LPWSTR szLocalPath, 
                    [in] LPWSTR szNotifyEndpoint, 
                    [in] LPWSTR szNotifyData, 
                    [in] CCM_DTS_PRIORITY Priority, 
                    [in] long dwTimeoutSeconds, 
                    [in] long dwChunkSize, 
                    [in] long dwFlags, 
                    [in] LPWSTR szLocationOptions, 
                    [in] LPWSTR szFileManifest, 
                    [in] LPWSTR szOwnerSID, 
                    [in] long bDeleteJobOnError, 
                    [in] LPWSTR szProviderData, 
                    [in] LPWSTR szPackageData, 
                    [out] GUID* pJobID);

Microsoft的文档显示该方法应为:

HRESULT DownloadContent(
        LPCWSTR szContentId, 
        LPCWSTR szContentVersion, 
        LPCWSTR szRemotePath, 
        LPCWSTR szLocalPath, 
        LPCWSTR szNotifyEndpoint, 
        LPCWSTR szNotifyData, 
        CCM_DTS_PRIORITY Priority, 
        DWORD dwTimeoutSeconds, 
        DWORD dwChunkSize, 
        DWORD dwFlags, 
        LPCWSTR szLocationOptions, 
        LPCWSTR szFileManifest, 
        LPCWSTR szOwnerSID, 
        BOOL bDeleteJobOnError, 
        LPCWSTR szProviderData, 
        LPCWSTR szPackageData, 
        GUID *pJobID
    ); 

我能看到的唯一区别是C#方法使用的是LPWSTR而不是LPCWSTR。反正有没有在C#中获得LPCWSTR,或者其他人是否有任何关于它为什么会崩溃COM客户端的想法?

0 个答案:

没有答案