I am trying to call the GetLayeredWindowAttributes(hwnd, crKey, bAlpha, dwFlags) function but it does not work.

I use Visual Basic 6 on Windows Vista Home Premium.


I declared it using:

Private Declare Function GetLayeredWindowAttributes Lib "user32.dll" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Boolean

I called it using:

Dim byteAlpha As Byte, hwnd As Long

byteAlpha = 1 'Make it 1 for debugging purposes
hwnd = Me.hwnd

Call GetLayeredWindowAttributes(hwnd, vbNull, byteAlpha, vbNull)  'use vbNull for variables you don't need

Debug.Print = GetLastError() & " " & byteAlpha

Debug.Print shows that GetLastError() returns 998, which the MSDN says is ERROR_NOACCESS (Invalid access to memory location.)
byteAlpha is still the same value as before (1).

I can call the GetLayeredWindowAttributes in Dev-C++ on the same computer and it works fine.

Does anyone have any idea on how to call it from VB6 in Vista?

I was experimenting and found out the solution. You need to declare it without ByVal like this (except for hwnd as that is not a returned value):

Private Declare Function GetLayeredWindowAttributes Lib "user32.dll" (ByVal hwnd As Long, crKey As Long, bAlpha As Byte, dwFlags As Long) As Boolean

This works now.

HI,

if that solution not works try this one

goto control panel-->user accounts-->User Access control

disable the UAC(Unchek the checkbox)
it will prompt for restart,


restart and try your code,


With regards
Venktramasamy SN

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.