访问x64 VBA - 尝试从user32.dll加载字符串时出现ERROR_RESOURCE_DATA_NOT_FOUND
问题描述:
我正试图在Access 2016 x64中找到user32.dll中的本地化按钮标题。访问x64 VBA - 尝试从user32.dll加载字符串时出现ERROR_RESOURCE_DATA_NOT_FOUND
奇怪的是,在安装了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
我不能设法进入if块,就好像他没有找到STRINGTABLE。
详细的错误:
ERROR_RESOURCE_DATA_NOT_FOUND
1812 (0x714)
The specified image file did not contain a resource section.
预期串输出,基于CINDEX(在这种情况下,OK_CAPTION,其具有ID = 800):
Caption = "Ok"
帮助十分赞赏!
答
调用LoadLibrary应该返回LongPtr而不是龙。
因此,ByVal hInstance As LongPtr
而不是ByVal hInstance As Long
和最后Dim Instance As LongPtr
而不是Dim Instance As Long
。
希望能帮助别人!
你只是陈述一个事实。就像错误消息告诉你的,更高版本的Windows不再在user32.dll中包含这些字符串。依靠这些实施细节总是一个非常糟糕的做法,鸡回家栖息。 –
我实际上使用ResourceViewer .NET打开了user32.dll,我发现它们都是非常奇怪的。 –
修正了它,LoadLibrary应该返回LongPtr,而不是Long。 –