⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_61650.htm

📁 vc
💻 HTM
字号:
<p>
序号:61650 发表者:zengxiaodonghcgs 发表日期:2003-11-20 22:57:06
<br>主题:为什么我写了一个DLL,用的时候有点问题,在调试可以通过,但程序不能正常执行
<br>内容:为什么我写了一个DLL,用的时候有点问题,在调试可以通过,但程序不能正常执行。<BR><BR>就是我在按F5调试的时候通过了,但我把他做成执行程序后,就不行CRTL F5 也是不行,请教,DLL的原代码在下面:分两个CPP 文件。Db_Connect.cpp是向导的,Connect_DB 是我加的一个类,同时我的几个函数就在里面。目的是ODBC连数据库,我就是想包装一下。<BR>// Db_Connect.cpp : Defines the initialization routines for the DLL.<BR>//<BR><BR>#include &#34;stdafx.h&#34;<BR>#include &lt;afxdllx.h&gt;<BR><BR>#ifdef _DEBUG<BR>#define new DEBUG_NEW<BR>#undef THIS_FILE<BR>static char THIS_FILE[] = __FILE__;<BR>#endif<BR><BR><BR>static AFX_EXTENSION_MODULE Db_ConnectDLL = { NULL, NULL };<BR><BR>extern &#34;C&#34; int APIENTRY<BR>DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Remove this if you use lpReserved<BR>&nbsp;&nbsp;&nbsp;&nbsp;UNREFERENCED_PARAMETER(lpReserved);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if (dwReason == DLL_PROCESS_ATTACH)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRACE0(&#34;DB_CONNECT.DLL Initializing!\n&#34;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Extension DLL one-time initialization<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!AfxInitExtensionModule(Db_ConnectDLL, hInstance))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Insert this DLL into the resource chain<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// NOTE: If this Extension DLL is being implicitly linked to by<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;an MFC Regular DLL (such as an ActiveX Control)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;instead of an MFC application, then you will want to<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;remove this line from DllMain and put it in a separate<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;function exported from this Extension DLL.&nbsp;&nbsp;The Regular DLL<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;that uses this Extension DLL should then explicitly call that<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;function to initialize this Extension DLL.&nbsp;&nbsp;Otherwise,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;the CDynLinkLibrary object will not be attached to the<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;Regular DLL's resource chain, and serious problems will<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;result.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new CDynLinkLibrary(Db_ConnectDLL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else if (dwReason == DLL_PROCESS_DETACH)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRACE0(&#34;DB_CONNECT.DLL Terminating!\n&#34;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Terminate the library before destructors are called<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxTermExtensionModule(Db_ConnectDLL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 1;&nbsp;&nbsp; // ok<BR>}<BR><BR>//==================================<BR><BR>#if !defined(AFX_ONNECT_DB_H__00E5F139_A713_48E0_B2BC_CAB9D8F6BAFC__INCLUDED_)<BR>#define AFX_ONNECT_DB_H__00E5F139_A713_48E0_B2BC_CAB9D8F6BAFC__INCLUDED_<BR><BR>#if _MSC_VER &gt; 1000<BR>#pragma once<BR>#endif // _MSC_VER &gt; 1000<BR>// onnect_db.h : header file<BR>//<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// Connect_DB window<BR><BR>class AFX_EXT_CLASS&nbsp;&nbsp;Connect_DB<BR>{<BR>// Construction<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;Connect_DB();<BR>//<BR>// Attributes<BR>public:<BR><BR>// Operations<BR>public:<BR><BR>// Overrides<BR>&nbsp;&nbsp;&nbsp;&nbsp;// ClassWizard generated virtual function overrides<BR>&nbsp;&nbsp;&nbsp;&nbsp;//{{AFX_VIRTUAL(Connect_DB)<BR>&nbsp;&nbsp;&nbsp;&nbsp;//}}AFX_VIRTUAL<BR><BR>// Implementation<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;HDBC Init_Connect_Hdbc(char Res[], char Passw[], char User[]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;HDBC Init_Hdbc(HENV&nbsp;&nbsp;henv);//在初始化HCBC同时连接数据库SERVER<BR>&nbsp;&nbsp;&nbsp;&nbsp;HENV Init_Henv();//在初始化HENV<BR>&nbsp;&nbsp;&nbsp;&nbsp;HSTMT Inin_Hstmt(HDBC hdbc);//在初始化HSTMT<BR>&nbsp;&nbsp;&nbsp;&nbsp;BOOL Set_Paramete(char Res[],char Passw[],char User[]);//送参数<BR>&nbsp;&nbsp;&nbsp;&nbsp;BOOL Connect_Test(HSTMT hstmt);//在初始化所以的变量后,可以用这个函数来判断连接状态,FALSE 是连接失败<BR>&nbsp;&nbsp;&nbsp;&nbsp;virtual ~Connect_DB();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Generated message map functions<BR>protected:<BR>&nbsp;&nbsp;&nbsp;&nbsp;UCHAR Resource[30];<BR>&nbsp;&nbsp;&nbsp;&nbsp;UCHAR Userid[30];<BR>&nbsp;&nbsp;&nbsp;&nbsp;UCHAR Password[30];<BR><BR>};<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR><BR>//{{AFX_INSERT_LOCATION}}<BR>// Microsoft Visual C++ will insert additional declarations immediately before the previous line.<BR><BR>#endif // !defined(AFX_ONNECT_DB_H__00E5F139_A713_48E0_B2BC_CAB9D8F6BAFC__INCLUDED_)<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:hurtmanzc 回复日期:2003-11-21 00:27:04
<br>内容:从上面的代码看不出错误,可能是你使用这个扩展DLL的项目设置的不对。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:zengxiaodonghcgs 回复日期:2003-11-21 08:40:34
<br>内容:希望是这样,但我不知道什么地方设置不对,我也是刚刚学自己做DLL。还的各位帮忙指点指点~~~
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:zengxiaodonghcgs 回复日期:2003-11-21 16:16:34
<br>内容:确实代码没有问题,现在我用动态的方式来调用他,发现运行几次后就可以,我这个重要是ODBCSDK连数据库的,可能这个就是这样吧,调试很方便的过,但执行的时候就要连接好几次才可以,难怪有人不喜欢!!~~~
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -