'--------------------------------------------------------------------------------
Sub Form1_Command1_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
text1.text = Str(Add2(370037607, Rnd * 100))
AfxMsg testdll("ddddd")
End Sub
'--------------------------------------------------------------------------------
Sub Form1_Command2_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
Dim As Any Ptr library = DyLibLoad( "dlltest" ) '就文件名,不能带 .DLL
If (library = 0) Then
AfxMsg "加载DLL失败"
Return
End If
Dim AddNumbers As Function(ByVal As Integer, ByVal As Integer) As Integer
AddNumbers = DyLibSymbol(library, "ADD2") ' 特别提醒,必须全部大写
'从DLL查看器里可以看到全称是 ADD2@8 ,而FB用FB的DLL可以省略 @8 的符号
If (AddNumbers = 0) Then
AfxMsg "无法从开发DLL例题库中检索Add2()函数的地址"
Return
End If
text2.text = Str(AddNumbers(100, Rnd * 100))
AfxMsg "使用完成"
DyLibFree(library) '卸载DLL ,特别注意,假如DLL还在工作,卸载会让软件崩溃
'本例题里,加载会弹窗提示,就是在工作,必须先关弹窗在卸载
'但本例题里同时有静态,因此关了也不崩溃,因为不在真正卸载DLL,因为还有静态加载。
End Sub
|