当前位置:编程学习 > VB >>

COM/DOCM中的IDL文件问题

目前我要写一个客户端,与以有的DCOM服务器通信,接口函数是行业协会制定的,协会提供了接口标准,并提供了一个IDL文件和C++的头文件,格式如下:例子
[
  uuid(D94112AF-05A3-4294-AD76-7EA97F512592),
  version(1.0),
  helpstring("EasyDCOM Library")

]
library EasyDCOM
{

  importlib("stdole2.tlb");
  importlib("STDVCL40.DLL");

  [
    uuid(B5D53700-D644-43A6-832B-4FAF482CA277),
    version(1.8),
    helpstring("Dispatch interface for HostInfo Object"),
    dual,
    oleautomation
  ]
   interface IHostInfo: IDispatch
  {
    [
    propget, 
    id(0x00000001)
    ]
    HRESULT _stdcall Info([out, retval] BSTR * Value );
  };

  [
    uuid(342B12F3-EB07-4579-B026-B140DB1E468D),
    version(1.0), 
    helpstring("HostInfo Object")
  ]
  coclass HostInfo
  {
    [default] interface IHostInfo;
  };

};
怎么接上去?一般调入DCOM,需要.cpp和.h文件,但DCOM服务器厂家说与他们无关系,只要采用行业协会的通信标准就行了,也就是说他们不提供.cpp和.h文件,我考虑是不是通过IDL文件来调用,网上资料idl可通过midl.exe生成.h,.c等文件,生成tlb文件,再生成dll,我通过midl生成了tlb和dll文件,但没有生成.h,.c等文件,不知如何使用了,协会提供的C++头文件有点像写服务器时用的,现在我的问题是:能不能通过idl文件来调入,写程序,如果可以,怎么用,我用midl ***.idl时,直接生成了tlb文件,没有生成.h,c等文件,是不是idl文件格式不同,怎么修改?
我在CB版也发了贴,不知有没有违反规则 --------------------编程问答-------------------- 我用你的IDL代码放到工程中编译,出来.h和.c文件了
.h文件为:


/* this ALWAYS GENERATED file contains the definitions for the interfaces */


 /* File created by MIDL compiler version 7.00.0555 */
/* at Sun Jan 06 14:59:42 2013
 */
/* Compiler settings for .\SERVER.IDL:
    Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 
    protocol : dce , ms_ext, c_ext, robust
    error checks: allocation ref bounds_check enum stub_data 
    VC __declspec() decoration level: 
         __declspec(uuid()), __declspec(selectany), __declspec(novtable)
         DECLSPEC_UUID(), MIDL_INTERFACE()
*/
/* @@MIDL_FILE_HEADING(  ) */

#pragma warning( disable: 4049 )  /* more than 64k source lines */


/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif

#include "rpc.h"
#include "rpcndr.h"

#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__


#ifndef __SERVER_h_h__
#define __SERVER_h_h__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

/* Forward Declarations */ 

#ifndef __IHostInfo_FWD_DEFINED__
#define __IHostInfo_FWD_DEFINED__
typedef interface IHostInfo IHostInfo;
#endif  /* __IHostInfo_FWD_DEFINED__ */


#ifndef __HostInfo_FWD_DEFINED__
#define __HostInfo_FWD_DEFINED__

#ifdef __cplusplus
typedef class HostInfo HostInfo;
#else
typedef struct HostInfo HostInfo;
#endif /* __cplusplus */

#endif  /* __HostInfo_FWD_DEFINED__ */


#ifdef __cplusplus
extern "C"{
#endif 



#ifndef __EasyDCOM_LIBRARY_DEFINED__
#define __EasyDCOM_LIBRARY_DEFINED__

/* library EasyDCOM */
/* [helpstring][version][uuid] */ 


EXTERN_C const IID LIBID_EasyDCOM;

#ifndef __IHostInfo_INTERFACE_DEFINED__
#define __IHostInfo_INTERFACE_DEFINED__

/* interface IHostInfo */
/* [object][oleautomation][dual][helpstring][version][uuid] */ 


EXTERN_C const IID IID_IHostInfo;

#if defined(__cplusplus) && !defined(CINTERFACE)
    
    MIDL_INTERFACE("B5D53700-D644-43A6-832B-4FAF482CA277")
    IHostInfo : public IDispatch
    {
    public:
        virtual /* [id][propget] */ HRESULT __stdcall get_Info( 
            /* [retval][out] */ BSTR *Value) = 0;
        
    };
    
#else  /* C style interface */

    typedef struct IHostInfoVtbl
    {
        BEGIN_INTERFACE
        
        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
            IHostInfo * This,
            /* [in] */ REFIID riid,
            /* [annotation][iid_is][out] */ 
            __RPC__deref_out  void **ppvObject);
        
        ULONG ( STDMETHODCALLTYPE *AddRef )( 
            IHostInfo * This);
        
        ULONG ( STDMETHODCALLTYPE *Release )( 
            IHostInfo * This);
        
        HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( 
            IHostInfo * This,
            /* [out] */ UINT *pctinfo);
        
        HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( 
            IHostInfo * This,
            /* [in] */ UINT iTInfo,
            /* [in] */ LCID lcid,
            /* [out] */ ITypeInfo **ppTInfo);
        
        HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( 
            IHostInfo * This,
            /* [in] */ REFIID riid,
            /* [size_is][in] */ LPOLESTR *rgszNames,
            /* [range][in] */ UINT cNames,
            /* [in] */ LCID lcid,
            /* [size_is][out] */ DISPID *rgDispId);
        
        /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( 
            IHostInfo * This,
            /* [in] */ DISPID dispIdMember,
            /* [in] */ REFIID riid,
            /* [in] */ LCID lcid,
            /* [in] */ WORD wFlags,
            /* [out][in] */ DISPPARAMS *pDispParams,
            /* [out] */ VARIANT *pVarResult,
            /* [out] */ EXCEPINFO *pExcepInfo,
            /* [out] */ UINT *puArgErr);
        
        /* [id][propget] */ HRESULT ( __stdcall *get_Info )( 
            IHostInfo * This,
            /* [retval][out] */ BSTR *Value);
        
        END_INTERFACE
    } IHostInfoVtbl;

    interface IHostInfo
    {
        CONST_VTBL struct IHostInfoVtbl *lpVtbl;
    };

    

#ifdef COBJMACROS


#define IHostInfo_QueryInterface(This,riid,ppvObject) \
    ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) 

#define IHostInfo_AddRef(This) \
    ( (This)->lpVtbl -> AddRef(This) ) 

#define IHostInfo_Release(This) \
    ( (This)->lpVtbl -> Release(This) ) 


#define IHostInfo_GetTypeInfoCount(This,pctinfo) \
    ( (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) ) 

#define IHostInfo_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
    ( (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) ) 

#define IHostInfo_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
    ( (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) ) 

#define IHostInfo_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
    ( (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) ) 


#define IHostInfo_get_Info(This,Value) \
    ( (This)->lpVtbl -> get_Info(This,Value) ) 

#endif /* COBJMACROS */


#endif  /* C style interface */




#endif  /* __IHostInfo_INTERFACE_DEFINED__ */


EXTERN_C const CLSID CLSID_HostInfo;

#ifdef __cplusplus

class DECLSPEC_UUID("342B12F3-EB07-4579-B026-B140DB1E468D")
HostInfo;
#endif
#endif /* __EasyDCOM_LIBRARY_DEFINED__ */

/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */

#ifdef __cplusplus
}
#endif

#endif
补充:VB ,  COM/DCOM/COM+
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,