首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在DLL“GetAsncKeyState”中找到名为“user32”的入口点

无法在DLL“GetAsncKeyState”中找到名为“user32”的入口点
EN

Stack Overflow用户
提问于 2016-09-02 13:07:37
回答 1查看 1.4K关注 0票数 0

我试图捕捉所有的键击,我得到并“无法在DLL‘user32’中找到一个名为‘user32’的入口点”,结果= GetAsncKeyState(i)中的错误如下所示

代码语言:javascript
复制
Private Declare Function GetAsncKeyState Lib "user32" (ByVal vkey As Integer) As Integer
Private Sub tmrKeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrKeys.Tick
    Dim result As Integer
    Dim key As String
    Dim i As Integer
    For i = 2 To 90
        result = 0
        result = GetAsncKeyState(i)
        If result = -3276 Then
            key = Chr(i)
            If i = 13 Then key = vbNewLine
            Exit For
        End If
    Next i
EN

回答 1

Stack Overflow用户

发布于 2016-09-02 13:15:37

您描述的错误的原因是因为函数名是GetAsyncKeyState,而不是GetAsyncKeyState

同样在.NET中,您应该考虑对对如何调用平台调用函数提供更多控制。使用DllImport属性而不是Declare语句(这是一种过时的VB6风格的方法)。

下面是GetAsyncKeyState声明我用的,其中包含了XML文档:

代码语言:javascript
复制
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Determines whether a key is up or down at the time the function is called, 
''' and whether the key was pressed after a previous call to <see cref="GetAsyncKeyState"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <remarks>
''' <see href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx"/>
''' </remarks>
''' ----------------------------------------------------------------------------------------------------
''' <param name="vKey">
''' The virtual-key code.
''' <para></para>
''' You can use left- and right-distinguishing constants to specify certain keys.
''' <para></para>
''' See Virtual-Key Codes: 
''' <see href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx"/>
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' If the function succeeds, 
''' the return value specifies whether the key was pressed since the last call to <see cref="GetAsyncKeyState"/>, 
''' and whether the key is currently up or down.
''' <para></para>
''' If the most significant bit is set, the key is down, and if the least significant bit is set, 
''' the key was pressed after the previous call to <see cref="GetAsyncKeyState"/>.
''' <para></para>
''' However, you should not rely on this last behavior.
''' <para></para>
''' <para></para>
''' The return value is zero for the following cases: 
''' <para></para>
''' The current desktop is not the active desktop.
''' <para></para>
''' The foreground thread belongs to another process and the desktop does not allow the hook or the journal record.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<SuppressUnmanagedCodeSecurity>
<DllImport("user32.dll", CharSet:=CharSet.Auto)>
Public Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys
) As Short
End Function

注意:如果使用preffer,可以将vKey参数更改为Integer数据类型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39293226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档