Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问x64 VBA-尝试从user32.dll加载字符串时,获取错误\u资源\u数据\u未找到_Vba_Ms Access_Ms Office_32bit 64bit_Dllimport - Fatal编程技术网

访问x64 VBA-尝试从user32.dll加载字符串时,获取错误\u资源\u数据\u未找到

访问x64 VBA-尝试从user32.dll加载字符串时,获取错误\u资源\u数据\u未找到,vba,ms-access,ms-office,32bit-64bit,dllimport,Vba,Ms Access,Ms Office,32bit 64bit,Dllimport,我正在尝试加载Access 2016 x64中的本地化按钮标题,这些标题位于user32.dll中 奇怪的是,在另一台安装了Access 2010 x86的机器上,代码工作得非常完美 代码如下: Option Compare Database Option Explicit Private Declare PtrSafe Function LoadString Lib "user32" Alias "LoadStringA" ( _ ByVal hInstance As Long, _

我正在尝试加载Access 2016 x64中的本地化按钮标题,这些标题位于user32.dll中

奇怪的是,在另一台安装了Access 2010 x86的机器上,代码工作得非常完美

代码如下:

Option Compare Database
Option Explicit

Private Declare PtrSafe Function LoadString Lib "user32" Alias "LoadStringA" ( _
    ByVal hInstance As Long, _
    ByVal uID As Long, _
    ByVal lpBuffer As String, _
    ByVal nBufferMax As Long) _
    As Long

Private Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" ( _
    ByVal lpFileName As String) _
    As Long

Private Enum CAPTION
    OK_CAPTION = 800
    CANCEL_CAPTION = 801
    ABORT_CAPTION = 802
    RETRY_CAPTION = 803
    IGNORE_CAPTION = 804
    YES_CAPTION = 805
    NO_CAPTION = 806
    CLOSE_CAPTION = 807
    HELP_CAPTION = 808
    TRYAGAIN_CAPTION = 809
    CONTINUE_CAPTION = 810
End Enum

Private Const lPath As String = "user32.dll"
Private Const BufferMax As Long = 256
Private Const cIndex As Long = CAPTION.OK_CAPTION

Private Sub cmdGetCaptionById_Click()
    Dim Buffer As String * BufferMax
    Dim Instance As Long
    Dim sLen As Long
    Instance = LoadLibrary(lPath)
    sLen = LoadString(Instance, cIndex, Buffer, BufferMax)
    If sLen <> 0 Then
        Caption = Left(Buffer, sLen)
        MsgBox Caption, vbInformation
    Else
        MsgBox "No caption found, error " & Err.LastDllError, vbCritical
    End If
End Sub
基于cIndex的预期字符串输出(在本例中为OK_标题,ID=800):

非常感谢您的帮助

LoadLibrary应返回LongPtr而不是Long。
因此,
ByVal hInstance作为LongPtr
而不是
ByVal hInstance作为Long

最后,
Dim实例作为LongPtr
而不是
Dim实例作为Long


希望这能帮助别人

你只是在陈述一个事实。正如错误消息告诉您的,Windows的更高版本在user32.dll中不再包含这些字符串。依赖这些实现细节一直是一种非常糟糕的做法,鸡飞狗跳。实际上,我用ResourceViewer.NET打开了user32.dll,我发现了它们,所以这很奇怪。修复了它,LoadLibrary应该返回LongPtr,而不是LongPtr。
ERROR_RESOURCE_DATA_NOT_FOUND
1812 (0x714)
The specified image file did not contain a resource section.
Caption = "Ok"