我正在尝试加载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
我无法进入if块,就像他找不到字符串一样。
详细错误:
ERROR_RESOURCE_DATA_NOT_FOUND
1812 (0x714)
The specified image file did not contain a resource section.
预期的字符串输出,基于cIndex(在这种情况下,OK_CAPTION,其ID = 800):
Caption = "Ok"
非常感谢帮助!
答案 0 :(得分:1)
LoadLibrary 应该返回 LongPtr 而不是 Long 。
因此,type GameServer struct {
players map[*Player]bool
register chan *Player
unregister chan *Player
broadcast chan []byte
}
func (s *GameServer) broadcastMessage(msg []byte) {
for player := range s.players {
player.messages <- msg
}
}
func (s *GameServer) tick() {
s.broadcastMessage([]byte(time.Now().Format(time.RFC1123)))
}
// question is mostly related to this function
func (s *GameServer) run() {
for {
select {
case _ = <-time.NewTicker(time.Second).C:
s.tick()
case client := <-s.register:
s.players[client] = true
case client := <-s.unregister:
delete(s.players, client)
case msg := <-s.broadcast:
s.broadcastMessage(msg)
}
}
}
代替ByVal hInstance As LongPtr
最后是ByVal hInstance As Long
而不是Dim Instance As LongPtr
希望能帮助别人!