大虾们帮帮忙啊,
小弟最近做VB,可偶从来没学过VB
现在遇到了一个这样的问题:
别人调我编写的dll,假设是(search.dll)
我的dll是一个窗口,然后能够输入名字等检索条件后
出来一个列表框,选择一条记录之后返回,(personID, name)现在我想问大虾们:
调我的窗口怎么样得到在我写的窗口这边的"选择记录(personID, name)"?
在我的工程里怎么写?
调我的dll的工程怎么写?谢谢大虾了

解决方案 »

  1.   

    你要调用的是标准DLL还是ACTIVE DLL比如:先声明
    Declare Function OpenComm Lib "dascard" (ByVal commport&) As Longdim icdev as long 
    icdev = OpenComm(0)  '此处调用打开串口
      

  2.   

    楼主,
    VB不能作这种DLL吧,你说的DLL可以做成OCX控件
    传回值用函数返回值,或ByRef引用传递的参数
      

  3.   

    谢谢,aohan(景升)
    不过可能我的意思没说清,我编的工程(含窗口)编成dll,别人来调用我的dll,从而打开我的窗口原来类似这样的dll(不返回值时)是这样写的
    mydll.clsBedLayoutIF(这个文件是别人调用我的接口)
    Option Explicit
    Public Function Execute(objCN As ADODB.Connection, strLoginID As String) As Boolean
        On Error GoTo ERR_LABEL
        
        Execute = True
        
        Set p_adoConn = objCN(连接)
        
        mdlCommon.p_strLoginID = strLoginID
        
        frmBedLayout.Show
        
        Exit FunctionERR_LABEL:    Execute = False
        Call OSCErrProc("Execute() / clsBedLayoutIF")
    End Function别人可能通过:
    Set objBedItiran = CreateObject("mydll.clsBedItiranIF")
        
    If objBedItiran.Execute(p_adoConn, p_strLoginID) = False Then
        Exit Sub
    End If
    这种方式调用我的dll来打开我dll的窗口
    =============================================如果我这个在我这个窗口里不往回返回值,倒没什么
    现在是别人在我的dll打开的窗口里选了一条记录(同时关掉了我的窗口)
    我怎么把选中的这条记录返回给调用我的窗口?
      

  4.   

    定义一个全局变量: 
    global currRec as integer 在关闭前赋值就行了currRec = 选择的记录
      

  5.   


    在你的接口里写一个
    function SetRec(rec as integer)
           currRec = rec
    end subfunction GetRec() as integer
           GetRec = currRec
    end function外部调用GetRec函数就得到了当前记录
      

  6.   

    你可以试试下面两种方法:
    1、定义事件
       你的Dll里面定义
        event ReturnValue(Personid as string ,password as stirng)   然后在你的需要返回的地方raiseevent returnvalue   别人调用的时候要用withevents定义
    2.就是别人调用你的时候,把他自己传到你的DLL里面,然后约定一个方法
       你可以在你的DLL 里面定义一个RelaObject 对象,当这个对象不是nothing的时候
       你就执行一个约定的函数
      

  7.   

    zqfleaf(动力港湾)
    有这样类似的例子不,谢谢了!
      

  8.   

    Option Explicit
    private m_strPersonID as string
    private m_strName as string
    'Public Function Execute(objCN As ADODB.Connection, strLoginID As String) As Boolean
    Public Function Execute(objCN As ADODB.Connection, strLoginID As String, strPersonID as string, strName as string) As Boolean    On Error GoTo ERR_LABEL
        
        Execute = True
        
        Set p_adoConn = objCN(连接)
        
        mdlCommon.p_strLoginID = strLoginID
        
        frmBedLayout.Show
        strPersonID = m_strPersonID 
        strName = m_strName    Exit FunctionERR_LABEL:    Execute = False
        Call OSCErrProc("Execute() / clsBedLayoutIF")
    End Function'在选擇记录的事件裡將所選記錄的personid,name分別賦給m_strPersonID,m_strName'調用:
    dim strPersonID as string, strName as string
    Set objBedItiran = CreateObject("mydll.clsBedItiranIF")
        
    If objBedItiran.Execute(p_adoConn, p_strLoginID, strPersonID, strName ) = False Then
        Exit Sub
    End If
    'Msgbox strPersonID & vblf & strName
      

  9.   

    同意zqfleaf(动力港湾)
    用事件来解决
    在你的Dll的类模块中定义一个事件如:
    public Event GetRecord(personID, name)
    然后在选择一条记录返回时用RaiseEvent GetRecord(personID, name)下面在你的工程中定义如:
    dim WithEvents a as 你的类名  '加了WithEvents该变量就能响应事件
    然后在对象列表框中选择a,就能在事件列表中看到你定义的事件。到此personID, name就通过该事件的参数传过来了
      

  10.   

    HtoFire(HotFire)你说的怎么写啊?我不知道你说的这些东西写在哪!
    我是真的一点都不会vb在你的Dll的类模块中定义一个事件如:
    public Event GetRecord(personID, name)这个事件定义写哪?我选中一条记录是在一个button的click事件后返回的,那么是不是在
    cmdMybutton_click里写:RaiseEvent GetRecord(personID, name)?在调用我的dll工程里怎么写?
    dim WithEvents a as 你的类名  '加了WithEvents该变量就能响应事件  这个写在哪啊,form里,还是哪儿?
    然后在对象列表框中选择a???这个就更加不明白了,不知道在哪儿找.或者这种要求是不是做不了啊?
      

  11.   

    我也有这个问题,按楼上的试了,也是不行,我的代码是这样的DLL里的代码
    public Event GetContent(str As Variant)Public Sub addcon(ByVal str As Variant)
    RaiseEvent GetContent(str)
    End Sub
    A程序调用addcon
    dim s as new test.class1
    s.addcon("测试")B程序
    Dim WithEvents a As B1.Class1Private Sub a_GetContent(str As Variant)
    Text1.Text = str
    End Sub
      

  12.   

    网上有一个ping.exe的例子,我只知道里有怎么写事件的列子,其实也有很多第二种方法:
       你的DLL 里面
       dim RelaForm as object    '需要返回值的时候
       if Not RelaForm is Nnothing then 
      

  13.   

    第一种方法:你可以在网上找到很多,如有一个ping.exe的例子
    第二种方法:    你的DLL 中
        
        定义:
        Public RelaForm as Object 
        
        
        
        '在你需要返回值的时候
        
        if not RelaForm is Nothing then 
          
           Call Relaform.ExeCute(PersonID,PassWord)
          
        end if
        
        
        别人引用你的时候:
        
            dim aa as MyDll.AA
            
            set aa=new MyDll.aa
            set aa.RelaForm=Me
            
          '写上一个函数
          public Sub ExeCute(PersonID as string ,PassWord as string )
          
            'do 
          end sub