首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

DLL中使用ADO的有关问题

2012-05-09 
DLL中使用ADO的问题使用DLL中使用了ADO。执行到跟ADO相关的代码行就出错 Application is not licensed to u

DLL中使用ADO的问题
使用DLL中使用了ADO。执行到跟ADO相关的代码行就出错 Application is not licensed to use this feature
并且DLL工程和调用DLL的工程打勾选了 Builder Runtime packes的那个选项 
这里是在执行到 new TADOQuery(NULL)这行时出错的,帮忙看看那里出的问题

DLL代码

C/C++ code
#include <vcl.h>#include <windows.h>#include <ADODB.hpp>#include <DB.hpp>//#include "Unit2.h"//---------------------------------------//   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//---------------------------------------extern "C"{ __declspec(dllexport) int __stdcall InserPariteTODB(char *SQL,char *Filename,bool bUpdate);}#pragma argsusedBOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved){    return 1;}//---------------------------------------//返回0表示错误//返回1表示成功//返回2表示该用户已经存在//参数 3表示如果用户存在是否直接更新文件名返回int __stdcall InserPariteTODB(char *SQL,char *Filename,bool bUpdate){    CoInitialize(NULL);    TADOQuery *ADOQuery1 = new TADOQuery(NULL);    AnsiString ans = Filename;    AnsiString conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ans;    conn += "Persist Security Info=False";    //"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\SkyHolter\\DB\\HOLTER.MDB;Persist Security Info=False";    ADOQuery1->ConnectionString = conn;    ADOQuery1->SQL->Clear();    conn = SQL;    ADOQuery1->SQL->Add(conn);    try    {        ADOQuery1->ExecSQL();        return 1;    }catch(...)    {        return 0;    }    return 1;    CoUninitialize(); }



调用部分
C/C++ code
//使用动态库    typedef int __stdcall(* ExcelSQLData)(char *,char *,bool);    AnsiString filePath = ExtractFilePath(Application->ExeName);    filePath += "DB_Access.dll";    HINSTANCE DBdll;    DBdll = LoadLibrary(filePath.c_str());    if(DBdll == NULL)    return false;    ExcelSQLData InserPariteTODB;    InserPariteTODB = (ExcelSQLData)GetProcAddress(DBdll,"InserPariteTODB");    char DBdir[100];    char SQL[300];    strcpy(&SQL[0],SQLans.c_str());    strcpy(&DBdir[0],AnsiString("D:\\SkyHolter\\DB\\HOLTER.MDB").c_str());    int btemp = InserPariteTODB(&SQL[0],&DBdir[0],true);    FreeLibrary(DBdll);    return btemp;


为什么到new TADOQuery 而且使用静态的ADO控件也不行。那里没设置好吗

[解决办法]
奇怪,你的CBuilder是什么版本,难道不是企业版?
[解决办法]
这里 new TADOQuery(NULL) 不要传入 NULL , 传入 Application 试试

热点排行