关于BCB中用ADOConnection和ADOQuery做的动态链接库如何能在VC其他语言中访问的有关问题
关于BCB中用ADOConnection和ADOQuery做的动态链接库怎么能在VC其他语言中访问的问题
我在BCB中做了一个关于数据保存和查询的动态连接库,在bcb中测试没问题一切正常,但是在vc中测试经常出错,我把代码贴出来大家帮我修改下。或者大家有什么好的保存数据和查询数据动态库的方法可以参考下。
//---------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#include <ADODB.hpp>
#include <DB.hpp>
typedef struct _TCompanyMessage
{
DWORD CompanyID;
char CompanyName[40+1];
}TCompanyMessage;
TADOConnection *ADOConn;
TADOQuery *AD;
//---------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
if (reason==DLL_PROCESS_ATTACH) // DLL入口
CoInitialize(NULL);
else if (reason==DLL_PROCESS_DETACH)
CoUninitialize(); // DLL结束
return 1;
}
//---------------------------------------
LRESULT __fastcall Database_Connect(void);
void __fastcall Database_Disconnect(void);
extern "C" __declspec(dllexport) LRESULT __stdcall Save_Company(TCompanyMessage *pCompanyMessage);
extern "C" __declspec(dllexport) LRESULT __stdcall Query_Company(int *iRecordCount,char * CompanyName,TCompanyMessage *pCompanyMessage);
//---------------------------------------
LRESULT __fastcall Database_Connect(void)
{
AnsiString sExeName = ExtractFilePath(Application->ExeName);
AnsiString Connstr="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Persist Security Info=False;Data Source="+sExeName+"Company.mdb";
ADOConn = new TADOConnection(NULL);
ADOConn->Connected = false;
ADOConn->ConnectionString = Connstr;
ADOConn->LoginPrompt=false;
ADOConn->Connected=true;
try
{
AD = new TADOQuery(NULL);
AD->Connection = ADOConn;
return S_OK;
}
catch(...)
{
return S_FALSE;
}
}
//---------------------------------------
void __fastcall Database_Disconnect(void)
{
delete ADOConn;
delete AD;
}
//---------------------------------------
LRESULT __declspec(dllexport) __stdcall Save_Company(TCompanyMessage *pCompanyMessage)
我在BCB中做了一个关于数据保存和查询的动态连接库,在bcb中测试没问题一切正常,但是在vc中测试经常出错,我把代码贴出来大家帮我修改下。或者大家有什么好的保存数据和查询数据动态库的方法可以参考下。
//---------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#include <ADODB.hpp>
#include <DB.hpp>
typedef struct _TCompanyMessage
{
DWORD CompanyID;
char CompanyName[40+1];
}TCompanyMessage;
TADOConnection *ADOConn;
TADOQuery *AD;
//---------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
if (reason==DLL_PROCESS_ATTACH) // DLL入口
CoInitialize(NULL);
else if (reason==DLL_PROCESS_DETACH)
CoUninitialize(); // DLL结束
return 1;
}
//---------------------------------------
LRESULT __fastcall Database_Connect(void);
void __fastcall Database_Disconnect(void);
extern "C" __declspec(dllexport) LRESULT __stdcall Save_Company(TCompanyMessage *pCompanyMessage);
extern "C" __declspec(dllexport) LRESULT __stdcall Query_Company(int *iRecordCount,char * CompanyName,TCompanyMessage *pCompanyMessage);
//---------------------------------------
LRESULT __fastcall Database_Connect(void)
{
AnsiString sExeName = ExtractFilePath(Application->ExeName);
AnsiString Connstr="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Persist Security Info=False;Data Source="+sExeName+"Company.mdb";
ADOConn = new TADOConnection(NULL);
ADOConn->Connected = false;
ADOConn->ConnectionString = Connstr;
ADOConn->LoginPrompt=false;
ADOConn->Connected=true;
try
{
AD = new TADOQuery(NULL);
AD->Connection = ADOConn;
return S_OK;
}
catch(...)
{
return S_FALSE;
}
}
//---------------------------------------
void __fastcall Database_Disconnect(void)
{
delete ADOConn;
delete AD;
}
//---------------------------------------
LRESULT __declspec(dllexport) __stdcall Save_Company(TCompanyMessage *pCompanyMessage)