请问在COM中要想把日期数据类型传入传出如何解决类型转化的问题呢?代码如下!!如何解决才能使这个根据日期进行的查询可用呢?最好不用MFC的前提下!
STDMETHODIMP CHEHE::Get(BSTR iAA, DATE iRQ, BSTR iBB,_Recordset **ppRs)
{
_ConnectionPtr pConn; _RecordsetPtr pRs; try
{

pConn.CreateInstance(__uuidof( Connection ) );
pConn->CursorLocation = adUseClient;  
pConn ->Open( "DSN=DSNABC","sa","",-1 );
pRs.CreateInstance(__uuidof( Recordset ) ); pRs ->CursorLocation = adUseClient;


pRs ->PutActiveConnection( pConn.GetInterfacePtr() );
TCHAR szBuffer[512]; wsprintf(szBuffer,_T("SELECT * FROM TABLE WHERE AA=%s AND rq=%s AND BB=%s "),(char*)(_bstr_t)iAA,??????,(char*)(_bstr_t)iBB);
_bstr_t strQuery = szBuffer;
pRs ->Open(szBuffer,vtMissing,adOpenDynamic,adLockBatchOptimistic,adCmdText );


pRs ->PutRefActiveConnection( NULL );


if( pConn ->GetState() == adStateOpen )
pConn ->Close();
pConn = NULL;


*ppRs = pRs.Detach();
}
return S_OK;
}

解决方案 »

  1.   

    需要传入传出的话,必须要用指针!
    STDMETHODIMP CHEHE::Get(BSTR iAA, DATE* pRQ, BSTR iBB,_Recordset **ppRs)
      

  2.   

    [id(1), helpstring("method GetCurrentDateTime")] HRESULT GetCurrentDateTime([out, retval]DATE *pdate);[id(2), helpstring("method GetDateTime")] HRESULT GetDateTime[out, retval]DATE *pdate);
      

  3.   

    thank u!but i still don't know how to use the pointer,my teacher has an answer with MFC.
      

  4.   

    ////////////////////////////////////////////////////////////////////
    // in IDL file:
    ////////////////////////////////////////////////////////////////////
    // interface IDateTime
    [
    object,
    uuid(202D541E-0F37-4A46-A886-BCB685AD4BF4),
    dual,
    helpstring("IDateTime Interface"),
    pointer_default(unique)
    ]
    interface IDateTime : IDispatch {
    [id(1), helpstring("method GetCurrentDateTime")] HRESULT GetCurrentDateTime([out, retval]DATE *pdate);
    [id(2), helpstring("method GetDateTime")] HRESULT GetDateTime([in]WORD wYear, [in]WORD wMonth, [in]WORD wDay, [in]WORD wHour, [in]WORD wMinute, [in]WORD wSecond, [out, retval]DATE *pdate);
    };[
    uuid(2F8207DD-B82A-4CA6-BE78-6E40CFE79F75),
    version(1.0),
    helpstring("Utility 1.0 Type Library")
    ]
    library UTILITYLib
    {
    importlib("stdole32.tlb");
    importlib("stdole2.tlb"); [
    uuid(10083515-C2E3-4A0E-AEF6-BD9CD85750AB),
    helpstring("DateTime Class")
    ]
    coclass DateTime {
    [default] interface IDateTime;
    };
    };////////////////////////////////////////////////////////////////////
    // in file DateTime.h
    ////////////////////////////////////////////////////////////////////
    #ifndef __DATETIME_H_
    #define __DATETIME_H_#include "resource.h"       // main symbols/////////
    // CDateTime
    class ATL_NO_VTABLE CDateTime : 
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CDateTime, &CLSID_DateTime>,
    public IDispatchImpl<IDateTime, &IID_IDateTime, &LIBID_UTILITYLib> {
    public:
    CDateTime() {
    }DECLARE_REGISTRY_RESOURCEID(IDR_DATETIME)DECLARE_PROTECT_FINAL_CONSTRUCT()BEGIN_COM_MAP(CDateTime)
    COM_INTERFACE_ENTRY(IDateTime)
    COM_INTERFACE_ENTRY(IDispatch)
    END_COM_MAP()// IDateTime
    public:
    STDMETHOD(GetCurrentDateTime)(DATE *pdate);
    STDMETHOD(GetDateTime)(WORD wYear, WORD wMonth, WORD wDay, WORD wHour, WORD wMinute, WORD wSecond, DATE *pdate);
    private:

    };
    #endif //__DATETIME_H_////////////////////////////////////////////////////////////////////// in file DateTime.cpp
    ////////////////////////////////////////////////////////////////////#include "stdafx.h"
    #include "Utility.h"
    #include "DateTime.h"
    #include <time.h>STDMETHODIMP CDateTime::GetCurrentDateTime(DATE *pdate) {
    time_t time = ::time(NULL);
    tm *ptm = ::localtime(&time);
    GetDateTime((WORD)(ptm->tm_year + 1900), (WORD)(ptm->tm_mon + 1), (WORD)ptm->tm_mday, (WORD)ptm->tm_hour, (WORD)ptm->tm_min, (WORD)ptm->tm_sec, pdate); return S_OK;
    }STDMETHODIMP CDateTime::GetDateTime(WORD wYear, WORD wMonth, WORD wDay, WORD wHour, WORD wMinute, WORD wSecond, DATE *pdate) {
    int arrDays[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; bool bLeapYear = ((wYear & 3) == 0) && ((wYear % 100) != 0 || (wYear % 400) == 0); long nDate = wYear * 365L + wYear / 4 - wYear / 100 + wYear / 400 + arrDays[wMonth - 1] + wDay;
    if (wMonth <= 2 && bLeapYear)
    --nDate;
    nDate -= 693959L; double dblTime = (((long)wHour * 3600L) + ((long)wMinute * 60L) + ((long)wSecond)) / 86400.; *pdate = (double)nDate + ((nDate >= 0) ? dblTime : -dblTime); return S_OK;
    }
      

  5.   

    你可以用CTime和COleDataTime来转换
    其中都有一个函数叫Format,可以格式化成数组
      

  6.   

    用::SystemTimeToVariantTime试试,还有一个::VariantTimeToSystemTime