M
Mikhail Gryaznov
Hi,
I am trying to get a call to native API function from inside VB code:
Public Class Form1
Public Declare Function GetDeviceCaps Lib "gdi32.dll" Alias
"GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Public Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As
Long
Public Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long,
ByVal hdc As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Public Const LOGPIXELSX As Long = 88 'Logical pixels/inch in X
Public Const LOGPIXELSY As Long = 90 'Logical pixels/inch in Y
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hwndS As Long, dcS As Long
'Get the windows handle for the desktop (screen)
hwndS = GetDesktopWindow()
'Get a device context for the above
dcS = GetDC(hwndS)
MsgBox("Horizontal Resolution: " & GetDeviceCaps(dcS, LOGPIXELSX))
'Release the device context to avoid GDI memory leaks
ReleaseDC(hwndS, dcS)
End Sub
End Class
When I run application on desktop in emulator mode I got and exception:
"Can't find PInvoke DLL 'user32.dll'"
at the line of calling to GetDesktopWindow().
Mikhail Gryaznov
I am trying to get a call to native API function from inside VB code:
Public Class Form1
Public Declare Function GetDeviceCaps Lib "gdi32.dll" Alias
"GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Public Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As
Long
Public Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long,
ByVal hdc As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Public Const LOGPIXELSX As Long = 88 'Logical pixels/inch in X
Public Const LOGPIXELSY As Long = 90 'Logical pixels/inch in Y
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hwndS As Long, dcS As Long
'Get the windows handle for the desktop (screen)
hwndS = GetDesktopWindow()
'Get a device context for the above
dcS = GetDC(hwndS)
MsgBox("Horizontal Resolution: " & GetDeviceCaps(dcS, LOGPIXELSX))
'Release the device context to avoid GDI memory leaks
ReleaseDC(hwndS, dcS)
End Sub
End Class
When I run application on desktop in emulator mode I got and exception:
"Can't find PInvoke DLL 'user32.dll'"
at the line of calling to GetDesktopWindow().
Mikhail Gryaznov