everyone 发表于 2009-8-24 11:14:35

请教VB 标准DLL 问题

Option Explicit

Private Declare Function SetHandleCount Lib "Kernel32" _
      (ByVal a As String) As Long

Private Declare Function SetHandleCount1 Lib "Kernel32" _
      Alias "SetHandleCount" (ByVal a As Long) As String

Private Declare Function RtlMoveMemory Lib "Kernel32" _
      (ByVal a As Long, ByVal b As String, ByVal c As Long) As Long
''''''''''''''''''''''''''''''''''''''''''''''''
''    DLL PROJECT ?2004 DanSoft Australia   ''
''   Your dlls MUST HAVE a DLLMain and Main   ''
'' proc, otherwise it won't compile properly! ''
''''''''''''''''''''''''''''''''''''''''''''''''
Function DLLMain(ByVal a As Long, ByVal b As Long, ByVal c As Long) As Long
    DLLMain = 1
End Function
Sub Main()
    'This is a dummy, so the IDE doesn't complain
    'there is no Sub Main.
End Sub
Function gettime()
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim str As String
On Error GoTo ErrPro
cn.ConnectionString = "driver={SQL Server};" & _
"server=cnaecfuyd000072;uid=sa;pwd=123623255;database=master"
cn.ConnectionTimeout = 300
cn.Open
cmd.ActiveConnection = cn
cmd.CommandText = "select convert(char(20),getdate(),120) as sys_date"
'cmd.ActiveConnection = cn
Set rst = cmd.Execute
str = CStr(rst(0))
gettime = str
Call RtlMoveMemory(200, gettime, Len(gettime) * 2 + 1)
rst.Close
cn.Close
Exit Function
ErrPro:
gettime = Format(Now(), "YYYY-mm-DD HH:mm:ss")
End Function请教大侠这代码有什么问题, 他是一个DLL 里面的函数,我在main 函数中调试,就出错,VB 直接关掉了。

马大哈 发表于 2009-8-24 18:09:37

<p>我想,这样的DLL非VB6原生支持的,因此不能调试吧.</p>
<p>&nbsp;</p>
<p>你应该将它生成,然后使用OD一类动态调试器去调试.</p>

everyone 发表于 2009-8-26 11:32:24

<div class="msgheader">QUOTE:</div><div class="msgborder"><b>以下是引用<i>马大哈</i>在2009-8-24 18:09:37的发言:</b><br/>
<p>我想,这样的DLL非VB6原生支持的,因此不能调试吧.</p>
<p>&nbsp;</p>
<p>你应该将它生成,然后使用OD一类动态调试器去调试.</p>
<p>&nbsp;</p>
<p>这个可是你写的,你自己也不知道怎么调用?</p>
<p>写出来就没意义啦。</p></div>
<p></p>

马大哈 发表于 2009-10-15 14:26:07

工具是我写的,但那只是方便生成这类DLL而已。

DLL本身应该实现什么功能,以及如何调试是最有效的,需要编写者自己掌握。

常用的调用法,我都已给出了示例代码;而调试技术,我只能给出一些通用的建议,因为我并不能了解别人会编写什么样的代码,不能确定地告诉一个相对最有效的手段。

ejer 发表于 2015-4-6 18:42:26

参观各位大侠 讨论
页: [1]
查看完整版本: 请教VB 标准DLL 问题