由于要做一个小的项目(asp.net+access BS结构的),需要实现对浏览器返回的数值通过DLL调用计算结果而后再返回结果。
如何实现DLL访问access,接口如何定义?另外:用哪种方式好些ODBC、OLE还是别的?
谢谢

解决方案 »

  1.   

    // stdafx.h : include file for standard system include files,
    //  or project specific include files that are used frequently, but
    //      are changed infrequently
    //#if !defined(AFX_STDAFX_H__927A42BD_14DE_4132_8B78_460DC1085317__INCLUDED_)
    #define AFX_STDAFX_H__927A42BD_14DE_4132_8B78_460DC1085317__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // Insert your headers here
    #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers#include <windows.h>// TODO: reference additional headers your program requires here
    #import "c:\program files\common files\system\ado\msado15.dll" \
    no_namespace rename ("EOF","adoEOF")
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_STDAFX_H__927A42BD_14DE_4132_8B78_460DC1085317__INCLUDED_)
      

  2.   

    // DllBase.cpp : Defines the entry point for the DLL application.
    //#include "stdafx.h"
    #include "DllBase.h"BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
     )
    {
        switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    //AfxOleInit();
    CoInitialize(NULL);
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH: //CoUninitialize(); break;
        }
        return TRUE;
    }
    // This is an example of an exported variable
    DLLBASE_API int nDllBase=0;// This is an example of an exported function.
    DLLBASE_API int fnDllBase(void)
    {
    return 42;
    }// This is the constructor of a class that has been exported.
    // see DllBase.h for the class definition
    CDllBase::CDllBase()

    return; 
    }void Open()
    {
    _ConnectionPtr m_pConnection;
    _RecordsetPtr m_pTypeset;
    _RecordsetPtr m_pDataset; HRESULT hr;
    //try
    //{
    hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
    if(SUCCEEDED(hr))
    {
    hr = m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\PropertyManage.mdb","","",adModeUnknown);///连接数据库
    ///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;
    }
    //} /*catch(_com_error e)///捕捉异常
    {
    CString errormessage;
    errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
    AfxMessageBox(errormessage);///显示错误信息
    }*/  m_pTypeset.CreateInstance("ADODB.Recordset"); m_pTypeset->Open("SELECT * FROM tFamily ORDER BY Name",&(*m_pConnection),adOpenForwardOnly,adLockOptimistic,adCmdText);
    m_pTypeset->MoveFirst(); _variant_t Holder; char *AAA; 
    AAA=new char[50]; while(!m_pTypeset->adoEOF)

    //strcpy(AAA,(LPCTSTR)(_bstr_t) m_pTypeset->GetCollect("Name"));
    Holder = m_pTypeset->GetCollect("Name");
    strcpy(AAA,(LPCTSTR)(_bstr_t)(Holder)); ::MessageBox(NULL,AAA,"提示",MB_OK);
    m_pTypeset->MoveNext(); }
    m_pTypeset->MoveFirst(); delete AAA;

    if(m_pTypeset->State==1)
    m_pTypeset->Close();
        m_pConnection->Close(); return ;
    }