安徽彩票大奖 欧洲百万乐透大奖 七星彩17049规律大奖 双色球中大奖领奖过程 3d近期中大奖故事 广州番禺中福彩大奖的 鸡男注定会中大奖 2016江苏彩民中大奖 趣彩网大奖网黑平台 大乐透4.97亿大奖 霍邱一彩民6元中双色球547万大奖 双色球黑龙江中大奖图 体育彩票中大奖名单 什么样的人能中大奖 彩票大奖作假

Access自动删除引用并自动重新添加引用的函数-判断了32位及64位Windows和Office的多种情况

2017-07-23 19:46:00
zstmtony
原创
1308

Access自动删除指定的引用,然后再自动重新添加这个引用的通用代码-判断了32位及64位Windows和32位Office及64位Office的多种情况

在编写Access通用?#25945;?#25110;通用开发库时,或使用第三方控件或链接库时,由于这个开发库可能经常会更新,由于更新后,开发库的对象和属性和方法?#21152;?#25152;改变

必须要手工对这个对象重新引用,如果一次两?#20301;?#21487;以手工操作,如果经常更新,就需要写一个通用删除和添加引用的函数了


自动重新添加Ocx dll 等控件或链接库的引用(DevlibOcx引用)


Option Compare Database
Option Explicit

Private Const POINTERSIZE As Long = 4
Private Const ZEROPOINTER As Long = 0

Const MAX_LEN = 200    '?#22336;?#20018;最大长度
Private Declare Sub apiCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Private Declare Function GetSystemWow64Directory Lib "kernel32" Alias "GetSystemWow64DirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long


'Access或Excel VBA或VB6判断windows系统是32位还是64位
'来判断系统是32bit还是64bit,主要通过API来实现,先在窗体模块里申明以下API定义:
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function IsWow64Process Lib "kernel32" (ByVal hProc As Long, bWow64Process As Boolean) As Long

'然后在窗体或模块中再建立一个判断系统是32位还是64位的函数,返回值是布尔值,如果系统是32位,此函数返回值是Flase 如果是64位,返回值是True,函数代码如下:
Public Function Is64bit() As Boolean
    Dim handle As Long, bolFunc As Boolean
    bolFunc = False
    handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")
    If handle > 0 Then
        IsWow64Process GetCurrentProcess(), bolFunc
    End If
    Is64bit = bolFunc
End Function

'获取64位 windows及32位windows系统 的系统目录 ,正常都是System32
Public Function GetSystemDir() As String
    Dim sTmp As String * MAX_LEN  '存放结果的固定长度的?#22336;?#20018;
    Dim nLength As Long  '?#22336;?#20018;的实际长度
    Dim length As Long
 
    Dim strPath As String
     '获得System目录
        length = GetSystemDirectory(sTmp, MAX_LEN)
        strPath = Left(sTmp, length)
      GetSystemDir = strPath
End Function
 
'获取64位windows系统下32位的系统目录 ,正常是SysWow64
Public Function GetSystemWow64Dir() As String
    Dim sTmp As String * MAX_LEN  '存放结果的固定长度的?#22336;?#20018;
    Dim nLength As Long  '?#22336;?#20018;的实际长度
    Dim length As Long
 
    Dim strPath As String
     '获得System目录
        length = GetSystemWow64Directory(sTmp, MAX_LEN)
        strPath = Left(sTmp, length)
      GetSystemWow64Dir = strPath
      
End Function



'自动重新添加Ocx dll 等控件或链接库的引用(DevlibOcx引用)
Public Function ReAddDevLibReference()
    Dim ref As Reference
    Dim strMDE As String
    On Error Resume Next
    strMDE = CurrentDb.Properties("MDE")
    On Error GoTo 0
    If strMDE = "" Then
 
#If Win64 Then
        If Dir(GetSystemDir & "\DevLibOcx.dll") = "" Then
                MsgBox GetSystemDir & "\DevLibOcx.dll 文件不存在,请检查文件是否丢失!"
        End If
#Else
    If Is64bit Then
        If Dir(GetSystemWow64Dir & "\DevLibOcx.dll") = "" Then
                MsgBox GetSystemWow64Dir & "\DevLibOcx.dll 文件不存在,请检查文件是否丢失!"
        End If
    Else
        If Dir(GetSystemDir & "\DevLibOcx.dll") = "" Then
                MsgBox GetSystemDir & "\DevLibOcx.dll 文件不存在,请检查文件是否丢失!"
        End If
    End If
#End If
        
        For Each ref In Application.References
            If ref.FullPath Like "*DevLibOcx.dll" Then
               Application.References.Remove ref
               Exit For
            End If
        Next
    
#If Win64 Then ’ 64bit Office or  32bit Office  Application.References.AddFromFile GetSystemDir & "\DevLibOcx.dll"
#Else
       If Is64bit Then
        Application.References.AddFromFile GetSystemWow64Dir & "\DevLibOcx.dll"
       Else
        Application.References.AddFromFile GetSystemDir & "\DevLibOcx.dll"
       End If
#End If
    End If

End Function 
分享
? 1999-2019 Office交流网?? 中山市天鸣科技发展有限公司 粤ICP备10043721号-5 SQL查询:19
内存占用:7.75MB
PHP 执行时间:0.22
双色球大奖2000年
安徽彩票大奖 欧洲百万乐透大奖 七星彩17049规律大奖 双色球中大奖领奖过程 3d近期中大奖故事 广州番禺中福彩大奖的 鸡男注定会中大奖 2016江苏彩民中大奖 趣彩网大奖网黑平台 大乐透4.97亿大奖 霍邱一彩民6元中双色球547万大奖 双色球黑龙江中大奖图 体育彩票中大奖名单 什么样的人能中大奖 彩票大奖作假
11选5计划软件神器 传奇霸业道士花了100万 七星彩开奖走势图 印度尼西亚和摩纳哥国旗 三剑客电子 急冻钻石送彩金 加拿大卑斯开奖快乐8 2010拜仁慕尼黑球衣 多特蒙德中后卫 奥格斯堡球队