最近在用ATL封装一个COM接口,需要引用一个第三方的dll文件,我在头文件中通过import进行了引用,h和cpp中都能识别该第三方类库中的类型,但是idl中却识别不了作为函数参数的类型,怎么办?

解决方案 »

  1.   

    你在IDL中import IDL文件,然后将相关的头文件添加到工程中,就可以了。
      

  2.   

    http://blog.csdn.net/lion_wing/article/details/7401238
      

  3.   

    这个第三方库只有DLL文件,找不到他的IDL文件啊
      

  4.   

    IDL文件如下:import "oaidl.idl";
    import "ocidl.idl";[
    object,
    uuid(9C0BADE3-30DB-4037-A655-24128EA50623),
    pointer_default(unique)
    ]
    interface ISGWorldObject : IUnknown{
    [] HRESULT Open([in] BSTR ProjectURL);
    };
    [
    uuid(1B24D8D1-31CC-41BE-B35A-6AF4F955099C),
    version(1.0),
    ]
    library TSDI3DEngineLib
    {
    importlib("stdole2.tlb");
    [
    uuid(295A40CD-7B9C-480D-8958-1518AEB5D619)
    ]
    dispinterface _ISGWorldObjectEvents
    {
    properties:
    methods:
    [id(1), helpstring("This event occurs after TerraExplorer finishes loading a Fly file.")] HRESULT OnLoadFinished(void);
    [id(2), helpstring("This event indicates to the client the current status of the terrain analysis calculations.")] HRESULT OnAnalysisProgress([in] LONG CurrPos, [in] LONG Range, [in] VARIANT_BOOL* pbCancelled);
    [id(3), helpstring("This event occurs before a presentation step is activated to notify the client that the step is being activated.")] HRESULT OnBeforePresentationItemActivation([in] BSTR PresentationID, [in] IPresentationStep61* Step);
    [id(4), helpstring("This event occurs when a standard TerraExplorer menu command’s value is changed.")] HRESULT OnCommandValueChanged([in] LONG commandID, [in] VARIANT newVal);
    };
    [
    uuid(A4431A01-0FE6-488E-8E3C-40104FB4DB6B)
    ]
    coclass SGWorldObject
    {
    [default] interface ISGWorldObject;
    [default, source] dispinterface _ISGWorldObjectEvents;
    };
    };
      

  5.   

    上面代码中红色字体标注的类型,是在第三方DLL中定义的。
      

  6.   

    我用import试了,报错:错误 2 error C1004: 发现意外的文件尾 C:\Program Files\Skyline\TerraExplorer Pro\TerraExplorerX.dll 7 1 TSDI3DEngine
      

  7.   

    必须是IUnknown* 或者IDispatch*
    其他类型不可,就会造成你这样的问题。