Win32 API in VBA: Variable not defined

Viewed 110

Hi I am new to VBA and this seems like a simple problem.

I am trying to get the dimensions of an image in excel and using the GetDeviceCaps function as a result.

I will get a variable not defined compile error regarding the VERTES parameter.

The code I use is the following:

Option Explicit

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, _
    ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" _
        (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) _
        As Long
        
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
       ByVal hDC As LongPtr _
       , ByVal nIndex As Long _
       ) As LongPtr
        

Public Sub Test()
    Dim tPOS As POINTAPI
    Dim AColor As Long
    Dim ADC As Long
    Dim width As Integer
    

    ADC = GetWindowDC(0)
    width = GetDeviceCaps(ADC, VERTRES)
            
    Call GetCursorPos(tPOS)
    AColor = GetPixel(ADC, tPOS.x, tPOS.y)
    

    ActiveWindow.Selection.ShapeRange(1).Fill.ForeColor.RGB = 14588691
    Debug.Print "width"
    
    Debug.Print width

End Sub

Questions appears to be so basic there isn't anything specific about this online.

0 Answers
Related