重奖!!!!!!关于在dll中使用ado的问题

抬头看路 2002-07-19 11:56:31
环境:win2k
bcb6
sybase
我在dll中加入了一个form,form上是一个ADOConnection和几个ADOQuery,大部分ADOQuery连接到ADOConnection上,一个ADOQuery有单独的连接。
我在DllMain中自己新建了一个TForm,dll释放的时候手动删除,现在发现只要操作数据库,删除form的时候程序就停下来了。不知有什么办法解决。
我的邮箱whyjld@yahoo.com.cn
whyjld@sina.com
whyjld@sohu.com
qq:121145789谢谢
...全文
77 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Robin 2003-04-14
  • 打赏
  • 举报
回复
强烈建议奖励invalid(空心菜之2.0开发中) !
另外还有一篇文章推荐!
在delphi中也是关于DLL饿!
是我用另一个号Flyinger1发的!
大家可以看!
是我搜集的一些例子!
抬头看路 2002-09-12
  • 打赏
  • 举报
回复
我估计是ado的问题,编译后患了一台机器就好了。
invalid 2002-07-29
  • 打赏
  • 举报
回复
HRESULT coret=CoInitialize(NULL);
就是判断初试化的返回值啊,
S_OK和S_FALSE好像都可以调用DLL。如果其它的表示失败。
TO:whyjld(白痴) ( )
我上面的代码是在正常运行的程序。
如果不行可能是你的函数代码有问题,跟框架没有关系。
jianlinlong 2002-07-28
  • 打赏
  • 举报
回复
//为什么要用下面这句?
HRESULT coret=CoInitialize(NULL);
//倒底什么意思
coolpony 2002-07-28
  • 打赏
  • 举报
回复
学习
WhyAndAnswer 2002-07-28
  • 打赏
  • 举报
回复
关注
抬头看路 2002-07-28
  • 打赏
  • 举报
回复
我改成数据模块还是不行,谁有办法?
抬头看路 2002-07-22
  • 打赏
  • 举报
回复
但是我改称数据模块后还是有问题。
invalid 2002-07-19
  • 打赏
  • 举报
回复
其它的dll函数,只是简单的调用DM中写好的方法就可以了。
例子如下:
//---------------------------------------------------------------------------
int __stdcall HaveDzd(long _overtime,char* Params,char *message)
{
int ret;
// Zh=Params;
// OverTime=_overtime;
Application->ProcessMessages();
try
{
if(DM->Connect)
ret=DM->HaveDzd(String(Params));
else
{
strcpy(message,"数据库未连接!");
ret=-9999;
}
}
catch(Exception *E)
{
strcpy(message,"查询失败!");
strcat(message,E->Message.c_str());
return -1;
}
return ret;
}

int __stdcall HaveLixi(long _overtime,char* Params,char *message)
{
int ret;
Zh=String(Params);
if(Zh.Length()==14)
Zh="010"+Zh;
Application->ProcessMessages();
try
{
if(DM->Connect)
{
ret=DM->HaveLixi(Zh.c_str());
}
else
{
strcpy(message,"数据库未连接!");
ret=-9999;
}
}
catch(Exception *E)
{
strcpy(message,"查询失败!");
strcat(message,E->Message.c_str());
return -1;
}
return ret;
}
invalid 2002-07-19
  • 打赏
  • 举报
回复
下面是我写的Dll,用ADO连接SQLServer的。
用到了TDataModule,用法是TDataModule中放置ADoconnection。adoquery。adostoreproc...,然后写一些方法完成需要的功能。
使用Dll时先调用OPen,关闭时调用close。
tdm的构造函数中,设置ADoconnection的连接属性。

#include <vcl.h>
#pragma hdrstop
extern "C" __declspec(dllexport) int __stdcall Open(long _overtime,char* Params,char *message);
extern "C" __declspec(dllexport) int __stdcall Close(long _overtime,char* Params,char *message);
extern "C" __declspec(dllexport) int __stdcall HaveDzd(long _overtime,char* Params,char *message);
extern "C" __declspec(dllexport) int __stdcall HaveLixi(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall GetDzd(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall GetDzdADO(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall GetLixi(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall SendFile(long _overtime,char* Params,char *file,char *message);
#include "unitSocket.h"
#include "unitdm.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 perfomring 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
//---------------------------------------------------------------------------
USERES("adodata.res");
USEFORM("unitDm.cpp", DM); /* TDataModule: File Type */
USEFORM("unitSocket.cpp", formSocket);
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
return 1;
}
//---------------------------------------------------------------------------
int __stdcall Open(long _overtime,char* Params,char *message)
{
int ret=0;
Application->ProcessMessages();
HRESULT coret=CoInitialize(NULL);
switch (coret)
{
case S_OK:
break;
case S_FALSE:
strcpy(message,"Indicates that the library is already initialized or that it could not release default allocator.");
break;
case E_OUTOFMEMORY:
strcpy(message,"Indicates that it was unable to initialize because the system is out of memory.");
break;
case E_INVALIDARG:
strcpy(message,"Indicates the argument is invalid.");
break;
case E_UNEXPECTED:
strcpy(message,"Indicates an unexpected error occurred.");
break;
}
if(coret!=S_OK&&coret!=S_FALSE)
{
return -1;
}
try{
DM=new TDM(NULL);
}
catch(...)
{
strcpy(message,"创建数据模块失败!");
return -1;
}
// Application->CreateForm(__classid(TDM), &DM);
try
{
DM->Connect=true;
}
catch(Exception *E)
{
strcpy(message,"连接数据库失败!");
strcat(message,E->Message.c_str());
CoUninitialize();
return -1;
}
return ret;
}
//---------------------------------------------------------------------------
int __stdcall Close(long _overtime,char* Params,char *message)
{
int ret=0;
Application->ProcessMessages();
if(!DM)
{
strcpy(message,"没有数据模块的实例!");
return -1;
}
try
{
DM->Connect=false;
}
catch(Exception *E)
{
strcpy(message,"断开数据库失败!");
strcat(message,E->Message.c_str());
ret=-8888;
}
try
{
delete DM;
}
catch(...)
{
strcpy(message,"释放数据模块失败");
ret=-9999;
}
CoUninitialize();
return ret;
}
invalid 2002-07-19
  • 打赏
  • 举报
回复
下面是我写的Dll,用ADO连接SQLServer的。
用到了TDataModule,用法是TDataModule中放置ADoconnection。adoquery。adostoreproc...,然后写一些方法完成需要的功能。
使用Dll时先调用OPen,关闭时调用close。
tdm的构造函数中,设置ADoconnection的连接属性。

#include <vcl.h>
#pragma hdrstop
extern "C" __declspec(dllexport) int __stdcall Open(long _overtime,char* Params,char *message);
extern "C" __declspec(dllexport) int __stdcall Close(long _overtime,char* Params,char *message);
extern "C" __declspec(dllexport) int __stdcall HaveDzd(long _overtime,char* Params,char *message);
extern "C" __declspec(dllexport) int __stdcall HaveLixi(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall GetDzd(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall GetDzdADO(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall GetLixi(long _overtime,char * Params,char *message);
extern "C" __declspec(dllexport) int __stdcall SendFile(long _overtime,char* Params,char *file,char *message);
#include "unitSocket.h"
#include "unitdm.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 perfomring 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
//---------------------------------------------------------------------------
USERES("adodata.res");
USEFORM("unitDm.cpp", DM); /* TDataModule: File Type */
USEFORM("unitSocket.cpp", formSocket);
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
return 1;
}
//---------------------------------------------------------------------------
int __stdcall Open(long _overtime,char* Params,char *message)
{
int ret=0;
Application->ProcessMessages();
HRESULT coret=CoInitialize(NULL);
switch (coret)
{
case S_OK:
break;
case S_FALSE:
strcpy(message,"Indicates that the library is already initialized or that it could not release default allocator.");
break;
case E_OUTOFMEMORY:
strcpy(message,"Indicates that it was unable to initialize because the system is out of memory.");
break;
case E_INVALIDARG:
strcpy(message,"Indicates the argument is invalid.");
break;
case E_UNEXPECTED:
strcpy(message,"Indicates an unexpected error occurred.");
break;
}
if(coret!=S_OK&&coret!=S_FALSE)
{
return -1;
}
try{
DM=new TDM(NULL);
}
catch(...)
{
strcpy(message,"创建数据模块失败!");
return -1;
}
// Application->CreateForm(__classid(TDM), &DM);
try
{
DM->Connect=true;
}
catch(Exception *E)
{
strcpy(message,"连接数据库失败!");
strcat(message,E->Message.c_str());
CoUninitialize();
return -1;
}
return ret;
}
//---------------------------------------------------------------------------
int __stdcall Close(long _overtime,char* Params,char *message)
{
int ret=0;
Application->ProcessMessages();
if(!DM)
{
strcpy(message,"没有数据模块的实例!");
return -1;
}
try
{
DM->Connect=false;
}
catch(Exception *E)
{
strcpy(message,"断开数据库失败!");
strcat(message,E->Message.c_str());
ret=-8888;
}
try
{
delete DM;
}
catch(...)
{
strcpy(message,"释放数据模块失败");
ret=-9999;
}
CoUninitialize();
return ret;
}
钛哥 2002-07-19
  • 打赏
  • 举报
回复
用DataModule 还是非常有道理的,否则Borland不会强烈推荐
钛哥 2002-07-19
  • 打赏
  • 举报
回复
ADOConnection和几个ADOQuery 不要放在 form上,用一个DataModule ,数据库控件全部放在里面。
钛哥 2002-07-19
  • 打赏
  • 举报
回复
ADOConnection和几个ADOQuery 不要放在form上,用一个DATAModule ,数据库控件全部放在里面。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧