我用VB6.0 SP5 写了一个Activex dll, 然后主程序调用这个DLL的一个函数, 这个函数传递一个对象参数, 类似于这样:
Dll 中有个函数: MyFunction(Msflxgrd as Object)
exe的窗体上有个MSFlexgrid1,主程序这样调用:sub MySub()
dim clsNew as New MyDll.ClsNew
    call clsNew.MyFunction(MsFlexgrid1)
end sub
现在问题来了:
如果这个DLL和exe都在同一台机器上编译,那么发布是没有问题的, 但是如果DLL在一台机器上编译,EXE在另外的机器上编译, 调用这个DLL就会出现"错误13 类型不匹配".
我试过只要不传递这个MSFlexgrid1就不会有问题,也就是说在传递这个Object上出问题了,但是我两台机器的VB环境是一样的, 我不知道为什么会这样, 这对我发布程序有很大的问题,希望得到高手的指点.

解决方案 »

  1.   

    試試將參數改成控件的句柄,在MyFunction中通過Copymemory來轉換成Object再操作.
      

  2.   

    to: leolan(史留香)Copymemory來轉換成Object, 没搞过啊, 详细点好吗?
      

  3.   

    '通過傳遞對象實例的地址(接口對象)來返回對象
    Private Function ObjectFromPtr(ByVal lPtr As Long) As Object
        Dim oTemp As Object
        ' Turn the pointer into an illegal, uncounted interface
        CopyMemory oTemp, lPtr, 4
        ' Do NOT hit the End button here! You will crash!
        ' Assign to legal reference
        Set ObjectFromPtr = oTemp
        ' Still do NOT hit the End button here! You will still crash!
        ' Destroy the illegal reference
        CopyMemory oTemp, 0&, 4
        ' OK, hit the End button if you must--you'll probably still crash,
        ' but it will be because of the subclass, not the uncounted reference
    End PropertyPrivate Sub Command1_Click()
        Msgbox ObjectFromPtr(ObjPtr(MSFlexGrid1)).Name
    End Sub
      

  4.   

    to leolan(史留香) 
    哇, 好高深啊, 试试先, 不过你上边说了好几个地方 do NOT hit the End button here! You will  crash!是不是用这个方法很容易崩溃 啊?END BUTTON 是指键盘上的END键还是程序界面上的退出按钮啊?
      

  5.   

    哦, 谢谢 flyingscv(zlj), 结贴的时候你得5分
      

  6.   

    to  leolan(史留香) 晕哦, VB找不到ObjPtr()这个API啊, 是不是C专用的啊?
      

  7.   

    ObjPtr是VB的一個未公開函數,直接用就可以了:)
      

  8.   

    谢谢 leolan(史留香) , 果然OK, 高人啊! 佩服佩服, 奉上95分, 聊表谢意! 同时谢谢 flyingscv(zlj), 在我需要的时候帮我回答了一个小问题, 按约定, 奉上5分, 请笑纳!