1

I have decompiled an old Visual Basic 6 project and opened it using Visual Basic 6 which is installed on a Windows XP Virtual Machine.

When I try to recompile the code I get the error "Compile error: User-defined type not defined" for this line of code -

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

I understand that his function is part of the User32 Windows Library.

I have tried to add user32.dll as a component/reference, with no luck.

1 Answer 1

4

Adding user32.dll as a component/reference will not work. You have to explicitly declare all of the Win32 API types and functions that you want to use. VB 6 includes the API Viewer that will help you with this, although it is horribly out of date.

Presumably, the user-defined type that is not defined here is RECT. It is a structure defined by the Win32 headers, but is not known to VB unless you declare it yourself.

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

You can also change the data type of lpRect to As Any in order to allow a null pointer to be passed (e.g., ByRef 0). This invalidates the entire area of the control.

Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, _
                                                      ByRef lpRect As Any, _
                                                      ByVal bErase As Long) As Long
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.