描述:
有这个接口提供了三个方法:
/******** PayTxn.idl ************/
interface IPositivePTxn : IDispatch
{
[id(1), helpstring("method PPAutoValidation")] HRESULT PPAutoValidation(BSTR pFullPathName);
[id(2), helpstring("method PPManualValidation")] HRESULT PPManualValidation(BSTR pMicrNo,BSTR pChequeNO,BSTR fltAmount,BSTR pClrBranch,BSTR dtClrdate,BSTR pDebitBr,BSTR pICSRefNumber);
[id(3), helpstring("method PPCreateReport")] HRESULT PPCreateReport(BSTR dtClrDate,BSTR clrAccount,BSTR pReportType1,BSTR pReportType2);
};
/********** PayTxn.h ******************/
class ATL_NO_VTABLE CPositivePTxn :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CPositivePTxn, &CLSID_PositivePTxn>,
public ISupportErrorInfo,
public IDispatchImpl<IPositivePTxn, &IID_IPositivePTxn, &LIBID_POSITIVEPAYTXNLib>
{
public:
CPositivePTxn()
{
}
~CPositivePTxn();
DECLARE_REGISTRY_RESOURCEID(IDR_POSITIVEPTXN)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CPositivePTxn)
COM_INTERFACE_ENTRY(IPositivePTxn)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
.
.
.
STDMETHOD(PPCreateReport)(BSTR dtClrDate,BSTR clrAccount,BSTR pReportType1,BSTR pReportType2);
STDMETHOD(PPManualValidation)(BSTR pMicrNo,BSTR pChequeNO,BSTR fltAmount,BSTR pClrBranch,BSTR dtClrdate,BSTR pDebitBr,BSTR pICSRefNumber);
STDMETHOD(PPAutoValidation)(BSTR pFullPathName);
};
然后客户端程序如何调用这几个接口方法?
我打算这么调,可是这些接口好象没有REFIID?
if ((hr = ::CLSIDFromProgID(L"PayTxn.PositivePTxn.1", &clsid)) != NOERROR) {
TRACE("unable to find Program ID -- error = %x\n", hr);
return;
}
if ((hr = ::CoGetClassObject(clsid, CLSCTX_INPROC_SERVER,
NULL, IID_IClassFactory, (void **) &pClf)) != NOERROR) {;
TRACE("unable to find CLSID -- error = %x\n", hr);
return;
}
pClf->CreateInstance(NULL, IID_IUnknown, (void**) &pUnk);
pUnk->QueryInterface(IID_IPTXN,(void**) &pPtxn);//接口声明也不知道该怎么写
IDL文件是这样的,不明白呀:
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(BE225665-CEAD-11D6-8760-00096B40CB3E),
dual,
helpstring("IPositivePTxn Interface"),
pointer_default(unique)
]
interface IPositivePTxn : IDispatch
{
[id(1), helpstring("method PPAutoValidation")] HRESULT PPAutoValidation(BSTR pFullPathName);
[id(2), helpstring("method PPManualValidation")] HRESULT PPManualValidation(BSTR pMicrNo,BSTR pChequeNO,BSTR fltAmount,BSTR pClrBranch,BSTR dtClrdate,BSTR pDebitBr,BSTR pICSRefNumber);
[id(3), helpstring("method PPCreateReport")] HRESULT PPCreateReport(BSTR dtClrDate,BSTR clrAccount,BSTR pReportType1,BSTR pReportType2);
};
[
uuid(BE225657-CEAD-11D6-8760-00096B40CB3E),
version(1.0),
helpstring("PositivePayTxn 1.0 Type Library")
]
library POSITIVEPAYTXNLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(BE225666-CEAD-11D6-8760-00096B40CB3E),
helpstring("PositivePTxn Class")
]
coclass PositivePTxn
{
[default] interface IPositivePTxn;
};
};
解决方案1:
.idl文件中有两部分,
其中的odl(就是library block)是程成tlb的,idl(除了library block的其它block)是生成proxy stub的
library POSITIVEPAYTXNLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(BE225666-CEAD-11D6-8760-00096B40CB3E),
helpstring("PositivePTxn Class")
]
coclass PositivePTxn
{
[default] interface IPositivePTxn;
};
};
library内部的是odl
The MIDL compiler generates a type library when it sees a library statement. The statements found in the library block follow essentially the same syntax as earlier versions of ODL.
ODL attributes can be applied to an element both inside and outside of the library block. Outside the block, they typically do nothing, unless the element is referenced from within the block by using it as a base type, inheriting from it, or referencing it on a line such as this:
library a
{
interface [xyz]];
struct bar;
...
};
If&