请教如何将voconnection vorecordset VOString三个类的做成动态链接库DLL

654091821   2009-5-25 12:15 楼主
三个类的.cpp和.h在附件中

请教如何将voconnection vorecordset VOString三个类的做成动态链接库DLL?

谢谢

回复评论 (3)

http://download.eeworld.net/source/1348247

voconnection vorecordset VOString三个类的压缩包可以在这里下载
点赞  2009-5-25 12:20
//-------------------------------------------------------------------
// VOConnection header file
//-------------------------------------------------------------------
//-------------------------------------------------------------------

#if !defined(AFX_VOCONNECTION_H__EE2E886A_8A8A_4CC8_9A48_28681F64544B__INCLUDED_)
#define AFX_VOCONNECTION_H__EE2E886A_8A8A_4CC8_9A48_28681F64544B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include
#include "adoce31.H"
#include "VOString.h"

class CVOConnection  
{
public:
        CVOConnection(LPCTSTR pcszProvider = NULL);
        virtual ~CVOConnection();

        BOOL Execute(LPCTSTR pcszSQL);
        BOOL Initialize();
        LPCTSTR GetProvider() { return m_strProvider; }

        operator _Connection*()        { return m_Conn; }

protected:
        CVOString m_strProvider;
        static TCHAR*                g_ProgID;
        static CLSID                g_ClsID;
        static BOOL                        g_Init;

        _Connection*                m_Conn;
/*===================================================================================*/
public:
        void SetConnectDB(LPCTSTR lpszDBName);
        void ClearConnect();
/*===================================================================================*/
};

#endif // !defined(AFX_VOCONNECTION_H__EE2E886A_8A8A_4CC8_9A48_28681F64544B__INCLUDED_)










//-------------------------------------------------------------------
//VOConnection.cpp
// VOConnection implementation
//-------------------------------------------------------------------
//-------------------------------------------------------------------

#include "stdafx.h"
#include
//#include "adoce31.H"
#include "voconnection.h"
#include "vorecordset.h"
#include "VOString.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

const IID IID__Connection = { 0x113033de, 0xf682, 0x11d2,        { 0xbb, 0x62, 0x00, 0xc0, 0x4f, 0x68, 0x0a, 0xcc}};

void __stdcall _com_issue_error(HRESULT m_hr)
{
        TCHAR pcszError[1024];

        _stprintf(pcszError, TEXT("_com_issue_error(%ld)\n"), m_hr);
        OutputDebugString(pcszError);
}

BOOL        CVOConnection::g_Init = FALSE;
CLSID        CVOConnection::g_ClsID;
TCHAR*        CVOConnection::g_ProgID = TEXT("ADOCE.Connection.3.1");

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CVOConnection::CVOConnection(LPCTSTR pcszProvider) : m_Conn(NULL)
{
        if(!g_Init)
                Initialize();

        HRESULT hr;

        if(pcszProvider == NULL)
        {
                pcszProvider = TEXT("Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;data source=Phone.sdf");

                hr = CoCreateInstance(g_ClsID, NULL, CLSCTX_INPROC_SERVER, IID__Connection, (LPVOID*) &m_Conn);
                hr = m_Conn->put_Provider((LPTSTR)pcszProvider);
                //hr = m_Conn->Open(TEXT(""),TEXT(""),TEXT(""),adOpenUnspecified);

                hr = m_Conn->Open(TEXT("My Documents\\Phone.sdf"),TEXT(""),TEXT(""),adOpenUnspecified);
                /*
                hr = m_Conn->Open(TEXT("My Do***ents\\Employee.cdb"),TEXT(""),TEXT(""),adOpenUnspecified);
                其中的My Do***ents\\Employee.cdb就是数据库的存放路径及名称。
                */
        }
        else
        {
                m_strProvider = pcszProvider;
                m_Conn = NULL;
        }
}

CVOConnection::~CVOConnection()
{
        if(m_Conn)
        {
                m_Conn->Close();
                m_Conn->Release();
        }
}

BOOL CVOConnection::Initialize()
{
        if(FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
                return FALSE;
       
        HRESULT hr;

        hr = CLSIDFromProgID(g_ProgID, &g_ClsID);

        if(FAILED(hr))
                return FALSE;

        return TRUE;
}

BOOL CVOConnection::Execute(LPCTSTR pcszSQL)
{
        CVORecordset        rs(*this);

        return rs.Open(pcszSQL, adOpenForwardOnly, adLockPessimistic);
}

/************************************************************************/
                                /* 在CVOConnection类中添加如下两个函数
                                   它们的作用是设置连接的数据源以及断开连接
                                  */
/************************************************************************/
void CVOConnection::SetConnectDB(LPCTSTR lpszDBName)
{
        if (m_Conn)
        {
                m_Conn->Close();
                m_Conn->put_Provider((LPTSTR)(TEXT("Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;data source=Phone.sdf")));
                m_Conn->Open((LPTSTR)lpszDBName,TEXT(""),TEXT(""),adOpenUnspecified);
                m_strProvider = lpszDBName;
        }
}

void CVOConnection::ClearConnect()
{
        if (m_Conn)
        {
                m_Conn->Close();
                m_Conn->put_Provider((LPTSTR)(TEXT("Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;data source=Phone.sdf")));
                m_Conn->Open(TEXT(""),TEXT(""),TEXT(""),adOpenUnspecified);
                m_strProvider = TEXT("");
               
        }
}
/************************************************************************/
/************************************************************************/







点赞  2009-5-25 12:54
// VOString.h: interface for the CVOString class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_VOSTRING_H__91406803_1D87_4DA9_A5A0_499A88AC4E86__INCLUDED_)
#define AFX_VOSTRING_H__91406803_1D87_4DA9_A5A0_499A88AC4E86__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CVOString  
{
public:
        CVOString(const CVOString& rSrc);
        CVOString(LPCTSTR pcszValue = TEXT(""));
        virtual ~CVOString();
        operator LPCTSTR() { return (LPCTSTR)m_pBuffer; }
        DWORD GetLength() { return m_dwLength; }
        LPCTSTR operator =(LPCTSTR pcszValue);
        BOOL operator == (LPCTSTR pcszValue);
        LPCTSTR operator += (LPCTSTR pcszAppend);
protected:
        BOOL SetMinBufferSize(DWORD dwChars);
        DWORD m_dwLength;
        DWORD m_dwBufferSize;
        TCHAR* m_pBuffer;
};

#endif // !defined(AFX_VOSTRING_H__91406803_1D87_4DA9_A5A0_499A88AC4E86__INCLUDED_)















// VOString.cpp: implementation of the CVOString class.
//
//////////////////////////////////////////////////////////////////////


#include "stdafx.h"
#include "VOString.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CVOString::CVOString(LPCTSTR pcszValue)
{
        m_pBuffer = NULL;
        m_dwBufferSize = 0;

        *this = pcszValue;
}

// Copy Constructor
CVOString::CVOString(const CVOString &rSrc)
{
        m_pBuffer = NULL;
        m_dwBufferSize = 0;

        *this = rSrc.m_pBuffer;
}

CVOString::~CVOString()
{
        if(m_pBuffer)
                delete m_pBuffer;
}

LPCTSTR CVOString::operator = (LPCTSTR pcszValue)
{

        m_dwLength = _tcslen(pcszValue);

        SetMinBufferSize(m_dwLength);
        _tcscpy(m_pBuffer, pcszValue);

        return 0;
}

BOOL CVOString::operator == (LPCTSTR pcszValue)
{
        return(_tcscmp(pcszValue, m_pBuffer) == 0);
}

LPCTSTR CVOString::operator += (LPCTSTR pcszAppend)
{
        SetMinBufferSize(GetLength() + _tcslen(pcszAppend));

        _tcscat(m_pBuffer, pcszAppend);
        return *this;
}

BOOL CVOString::SetMinBufferSize(DWORD dwChars)
{
        if(m_dwBufferSize < dwChars + 1)
        {
                TCHAR*        pNewBuffer;
                DWORD        dwNewBufferSize = dwChars + 256;

                pNewBuffer = new TCHAR[dwNewBufferSize];

                if(m_pBuffer)
                {
                        memmove(pNewBuffer, m_pBuffer, m_dwBufferSize);
                        delete m_pBuffer;
                }

                m_pBuffer = pNewBuffer;
                m_dwBufferSize = dwNewBufferSize;
        }

        return TRUE;
}
点赞  2009-5-25 12:52
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复