Visual Basic 6 - Compile Error: User-defined type not defined

Visual Basic 6 - Compile Error: User-defined type not defined

我反编译了一个旧的 Visual Basic 6 项目并使用安装在 Windows XP 虚拟机上的 Visual Basic 6 打开它。

当我尝试重新编译代码时,这行代码出现错误 "Compile error: User-defined type not defined" -

Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long

我知道他的功能是 User32 Windows 库的一部分。

我尝试将 user32.dll 添加为 component/reference,但没有成功。

将 user32.dll 添加为 component/reference 不会 起作用。您必须显式声明所有要使用的 Win32 API 类型和函数。 VB 6 包括 API 查看器,可以帮助您解决这个问题,尽管它已经非常过时了。

推测这里没有定义的user-defined类型是RECT。它是由 Win32 headers 定义的结构,但 VB 不知道,除非您自己声明它。

Public Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

您还可以将 lpRect 的数据类型更改为 As Any 以允许传递空指针(例如ByRef 0).这会使控件的整个区域无效。

Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, _
                                                      ByRef lpRect As Any, _
                                                      ByVal bErase As Long) As Long