Bug in W10/64bits with the function CreateWindowEx ?

For everything that's not in any way related to PureBasic. General chat etc...
rlisoft
New User
New User
Posts: 3
Joined: Sun Jan 15, 2017 3:06 pm

Bug in W10/64bits with the function CreateWindowEx ?

Post by rlisoft »

Hello All,
 I have a question about the function CreateWindowEx in vba.
I have managed to make it work on W7/64bits with Access2013/64bits....(and on all 32bit versions). it works fine also on my W10/32bits version.

But when i try exactly the same on W10/64bits with Access2013/64bits CreateWindowEx does not return a valid pointer.
In my module there is this code (for VBA7) : and i run the CreateMyForm function
===============================

Code: Select all

Option Compare Database
Option Explicit
Private Type WNDCLASSEX
    cbSize As Long
    style As Long
    lpfnwndproc As LongPtr
    cbClsextra As Long
    cbWndExtra As Long
    hInstance As LongPtr
    hIcon As LongPtr
    hCursor As LongPtr
    hbrBackground As LongPtr
    lpszMenuName As String
    lpszClassName As String
    hIconSm As LongPtr
End Type
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Type MSG
    hwnd As LongPtr
    message As Long
    wParam As LongPtr
    lParam As LongPtr
    time As Long
    pt As POINTAPI
End Type
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Type PAINTSTRUCT
    hdc As LongPtr
    fErase As Long
    rcPaint As RECT
    fRestore As Long
    fIncUpdate As Long
    rgbReserved(0 To 31) As Byte
    'rgbReserved(32) As Byte 'this was declared incorrectly in VB API viewer
End Type
Private Declare PtrSafe Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As LongPtr, ByVal hMenu As LongPtr, ByVal hInstance As LongPtr, lpParam As Any) As LongPtr
Private Declare PtrSafe Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal hInstance As LongPtr, ByVal lpIconName As String) As LongPtr
Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As LongPtr, ByVal lpCursorName As String) As LongPtr
Private Declare PtrSafe Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function RegisterClassEx Lib "user32" Alias "RegisterClassExA" (pcWndClassEx As WNDCLASSEX) As Integer
Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
Private Declare PtrSafe Function UpdateWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function SetFocus Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Private Declare PtrSafe Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As MSG, ByVal hwnd As LongPtr, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare PtrSafe Function TranslateMessage Lib "user32" (lpMsg As MSG) As Long
Private Declare PtrSafe Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As MSG) As LongPtr
Private Declare PtrSafe Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
Private Declare PtrSafe Function BeginPaint Lib "user32" (ByVal hwnd As LongPtr, lpPaint As PAINTSTRUCT) As LongPtr
Private Declare PtrSafe Function EndPaint Lib "user32" (ByVal hwnd As LongPtr, lpPaint As PAINTSTRUCT) As Long
Private Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As LongPtr, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare PtrSafe Function GetLastError Lib "kernel32" () As Long

Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_VSCROLL As Long = &H200000
Private Const WS_TABSTOP As Long = &H10000
Private Const WS_THICKFRAME As Long = &H40000
Private Const WS_MAXIMIZE As Long = &H1000000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZE As Long = &H20000000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_SYSMENU As Long = &H80000
Private Const WS_BORDER As Long = &H800000
Private Const WS_CAPTION As Long = (WS_BORDER Or WS_DLGFRAME)  '&HC00000
Private Const WS_CHILD As Long = &H40000000
Private Const WS_CHILDWINDOW As Long = (WS_CHILD)
Private Const WS_CLIPCHILDREN As Long = &H2000000
Private Const WS_CLIPSIBLINGS As Long = &H4000000
Private Const WS_DISABLED As Long = &H8000000
Private Const WS_DLGFRAME As Long = &H400000
Private Const WS_EX_ACCEPTFILES As Long = &H10&
Private Const WS_EX_DLGMODALFRAME As Long = &H1&
Private Const WS_EX_NOPARENTNOTIFY As Long = &H4&
Private Const WS_EX_TOPMOST As Long = &H8&
Private Const WS_EX_TRANSPARENT As Long = &H20&
Private Const WS_GROUP As Long = &H20000
Private Const WS_HSCROLL As Long = &H100000
Private Const WS_ICONIC As Long = WS_MINIMIZE
Private Const WS_OVERLAPPED As Long = &H0&
Private Const WS_OVERLAPPEDWINDOW As Long = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
Private Const WS_POPUP As Long = &H80000000
Private Const WS_POPUPWINDOW As Long = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)
Private Const WS_SIZEBOX As Long = WS_THICKFRAME
Private Const WS_TILED As Long = WS_OVERLAPPED
Private Const WS_TILEDWINDOW As Long = WS_OVERLAPPEDWINDOW
Private Const CW_USEDEFAULT As Long = &H80000000
Private Const CS_HREDRAW As Long = &H2
Private Const CS_VREDRAW As Long = &H1
Private Const IDI_APPLICATION As Long = 32512&
Private Const IDC_ARROW As Long = 32512&
Private Const WHITE_BRUSH As Integer = 0
Private Const BLACK_BRUSH As Integer = 4
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_CLOSE As Long = &H10
Private Const WM_DESTROY As Long = &H2
Private Const WM_PAINT As Long = &HF
Private Const SW_SHOWNORMAL As Long = 1
Private Const DT_CENTER As Long = &H1
Private Const DT_SINGLELINE As Long = &H20
Private Const DT_VCENTER As Long = &H4
Private Const WS_EX_STATICEDGE = &H20000
Private Const SW_NORMAL = 1
Public Function CreateMyForm()
    Dim lhwndWindow As LongPtr
    Dim AtomReg As Integer
    Dim tWinClass As WNDCLASSEX
    Dim tMessage As MSG
   
    'Set up and register window class
    tWinClass.cbSize = LenB(tWinClass)
    tWinClass.style = CS_HREDRAW Or CS_VREDRAW
    tWinClass.lpfnwndproc = FunctionPointer(AddressOf WindowProc)
    tWinClass.cbClsextra = 0&
    tWinClass.cbWndExtra = 0&
    tWinClass.hInstance = 0&
    tWinClass.hIcon = LoadIcon(0&, IDI_APPLICATION)
    tWinClass.hCursor = LoadCursor(0&, IDC_ARROW)
    tWinClass.hbrBackground = GetStockObject(WHITE_BRUSH)
    tWinClass.lpszMenuName = 0&
    tWinClass.lpszClassName = "NOMDEMACLASSE"
    tWinClass.hIconSm = LoadIcon(0&, IDI_APPLICATION)
    AtomReg = RegisterClassEx(tWinClass)
    'Create a window
    lhwndWindow = CreateWindowEx(WS_EX_DLGMODALFRAME, "NOMDEMACLASSE", "A NICE TITLE", WS_POPUPWINDOW Or WS_CAPTION, 100, 100, 500, 200, 0&, 0&, 0&, 0&)
    If lhwndWindow = 0 Then
        MsgBox "Debug info : " & vbCrLf _
        & "AtomReg=" & AtomReg & vbCrLf & vbCrLf _
        & "but lhwndWindow = " & lhwndWindow & vbCrLf & vbCrLf _
        & "So CreateWindowEx DOES NOT WORK ! "
        Exit Function
    End If
    'Show the window
    ShowWindow lhwndWindow, SW_SHOWNORMAL
    UpdateWindow lhwndWindow
    SetFocus lhwndWindow
    
    'Message loop
    Do While 0 <> GetMessage(tMessage, 0&, 0&, 0&)
        TranslateMessage tMessage
        DispatchMessage tMessage
    Loop
    
End Function
'Message handler for this window
Private Function WindowProc(ByVal lhwnd As LongPtr, ByVal tMessage As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPtr
    Dim tPaint As PAINTSTRUCT
    Dim tRect As RECT
    Dim lHdc As LongPtr
    Dim sCaption As String
    Select Case tMessage
    Case WM_PAINT
        lHdc = BeginPaint(lhwnd, tPaint)
        Call GetClientRect(lhwnd, tRect)
        sCaption = "CreateWindowEx WORKS .....yessss"
        Call DrawText(lHdc, sCaption, Len(sCaption), tRect, DT_SINGLELINE Or DT_CENTER Or DT_VCENTER)
        Call EndPaint(lhwnd, tPaint)
        Exit Function
    Case WM_KEYDOWN
        'Close window when the user presses a key
        Call PostMessage(lhwnd, WM_CLOSE, 0, 0)
        Exit Function
        
    Case WM_DESTROY
        'Fired when the X button is pressed
        PostQuitMessage 0&
        Exit Function
    End Select
    
    'pass all other messages to default window procedure
    WindowProc = DefWindowProc(lhwnd, tMessage, wParam, lParam)
End Function
==================================================

So the actual call to CreateWindowEx is :
   lhwndWindow = CreateWindowEx(WS_EX_DLGMODALFRAME, CLASSNAME, TITLE, WS_POPUPWINDOW Or WS_CAPTION, 500, 50, 500, 500, 0&, 0&, 0&, 0&)

And this fails on my W10/64bits computer with Access2013/64bits installed. (lhwndWindow = 0), whereas on W7/64bits it returns a valid pointer.
Can anyone tell me why it is different in W10/64bits and how i should solve this issue ?
 Could this be an antivirus issue ? (i tried to turn down Avast and Window Defender to no avail) or is this just a new bug ????
On request i can provide the complet .accdb file with all the code in it
Many thanks in advance....

__________________________________________________
Code tags added
14.03.2017
RSBasic
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Bug in W10/64bits with the function CreateWindowEx ?

Post by Keya »

rlisoft wrote:Can anyone tell me why it is different in W10/64bits and how i should solve this issue ?
i have no problems calling CreateWindow(Ex) in Purebasic, maybe its a VBA issue, but this isnt a VBA forum
On request i can provide the complet .accdb file with all the code in it
No we dont need to execute your potentially malicious database file on our computers to test the CreateWindowEx api call ;)

Hmm, 1st post... absolutely nothing to do with Purebasic just generic basic coding question ... mentions possible antivirus issues... offers to send his code, but in a database file (whats wrong with txt or txt in a zip? why database? seems less convenient ... unless you want to remotely execute code? ransomware?), when the apparent problem is just a simple API call ... ill play devils advocate and sit out :P
Last edited by Keya on Sun Jan 15, 2017 4:26 pm, edited 8 times in total.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Bug in W10/64bits with the function CreateWindowEx ?

Post by IdeasVacuum »

Hello rlisoft

Sorry to inform you but you are on the wrong forum :shock:

This forum is for the Pure Basic language, your post is about Visual Basic for Applications?

So firstly, this is not a PB bug. However, you can use Windows API if required when coding with PB, so somebody here may have encountered your issue with CreateWindowEx, but VBA is a bit different to PB and indeed VB.

You might like to try:
http://www.vbaexpress.com/forum/
https://social.msdn.microsoft.com/Forum ... rum=isvvba
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
rlisoft
New User
New User
Posts: 3
Joined: Sun Jan 15, 2017 3:06 pm

Re: Bug in W10/64bits with the function CreateWindowEx ?

Post by rlisoft »

OK, i must be mistaken.....and posted to a wrong forum ....
Please accept my excuses....


(but to accuse me of ...quote (unless you want to remotely execute code? ransomware?), ) is a bit strong....
All the code in it is already in my post...i just suggested to download the database version in order to see the problem, it is nothing more than the same code.


I will unregister my account on Purebasic....because anyway...you or the other gay obviously don't have a single clue to the solution to my problem....
and i thank you both....for nothing


IdeasVacuum wrote:Hello rlisoft

Sorry to inform you but you are on the wrong forum :shock:

This forum is for the Pure Basic language, your post is about Visual Basic for Applications?

So firstly, this is not a PB bug. However, you can use Windows API if required when coding with PB, so somebody here may have encountered your issue with CreateWindowEx, but VBA is a bit different to PB and indeed VB.

You might like to try:
http://www.vbaexpress.com/forum/
https://social.msdn.microsoft.com/Forum ... rum=isvvba
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Bug in W10/64bits with the function CreateWindowEx ?

Post by netmaestro »

All the structures, constants and declares in your code, consisting of many many lines, are natively imported in PureBasicand ready for use. If you were using PB, all you'd need is the code to set up and register your tWinClass variable, your CreateWindowEx and message loop and you're good to go.
BERESHEIT
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Bug in W10/64bits with the function CreateWindowEx ?

Post by nco2k »

do you go to the denist when your foot hurts? why would anyone on a purebasic forum help you with visualbasic code? why would anyone on a visualbasic forum help you with purebasic code? purebasic has nothing to do with visualbasic and visualbasic has nothing to do with purebasic. being rude to our forum members wont change that fact. if you actually had a purebasic related question, you would have received a lot of help by now. but you dont. purebasic users arent visualbasic experts and visualbasic users arent purebasic experts. its as simple as that. its not our fault that you are unable to understand that. have a nice day.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Bug in W10/64bits with the function CreateWindowEx ?

Post by Keya »

rlisoft wrote:(but to accuse me of ...quote (unless you want to remotely execute code? ransomware?), ) is a bit strong...
Quick question: why not a zip file? And, why in particular this specific Microsoft Access database format that most people don't have? And if all youre trying to do is make an API call to CreateWindowEx why is any additional file let alone a database required, especially given that 1) youve posted the code in question, and 2) even that code has nothing to do with databases ... ?

I apologise if you're not fishing with malware (i apologise for assuming the worst), it's just that when people ask for questions about code they usually send, well... just code -- in the form of text (or a zip if there's associated files), as it's simply the most convenient.

I've never seen "i'll send it in a <insert executable database format here>", which would additionally require users to have a program that supports that database format just to open it (so again warning bells - why not a zip?), so when 1) it's your first post, 2) it's nothing to do with Purebasic yet about some other basic, and 3) you're offering to send a file of that nature when it has seemingly nothing to do with a simple API call (and one which (.accdb) is known as a malware host), and 4) thats instead of a .txt or .zip ... red flags every time sorry.

If your question was about using CreateWindowEx in Purebasic I guarantee you we would've had a solution for you by now (and plenty of people have already called CreateWindowEx in Purebasic), most questions rarely go half a day without some answer, but as your question is about Visual Basic this isn't the forum sorry.

Again please forgive me if you feel I was rude or overly-cautious, but as you're a programmer and given the above context and the security position we're all in in 2017 I'm sure you can understand why :)
Anyway I hope somebody at a Visual Basic forum is able to help you with your Visual Basic problem
rlisoft
New User
New User
Posts: 3
Joined: Sun Jan 15, 2017 3:06 pm

Re: Bug in W10/64bits with the function CreateWindowEx ?

Post by rlisoft »

In response to the last post of KENIA :
OK, i accept your apology if you accept mine...
I do admit that i posted to the wrong forum (although i think my problem with CreateWindowEx has finaly nothing to do with visual basic, nor with Purebasic. But with W10/64bits)
And i should have left out that last phrase in my initial post...OK, sorry

But now please go back to the initial problem i am facing :

The function CreateWindowEx seems to fail on W10/64bits familly edition, whereas the same coding returns a valid handler with W7/64bits or W10/32bits

So let me rephrase my question : does anyone on this PureBasic forum has experienced such behaviour with CreateWindowEx in PureBasic under W10/64bits and if so, did he find a solution ?
If purebasic programmers can execute CreateWindowEx succesfully on W10/64bits i would still like to know it because that would be usefull information to me.
CreateWindowEx is a api-function in user32.dll provided by Windows. So PureBasic calls to that function might encounter simular behaviour and that would point to a W10/64bits bug.

So I take up your bold 'guarantee' to get real help within a day, but will not be disapointed if i dont... :lol: :lol:
Keya wrote:
rlisoft wrote:(but to accuse me of ...quote (unless you want to remotely execute code? ransomware?), ) is a bit strong...
Quick question: why not a zip file? And, why in particular this specific Microsoft Access database format that most people don't have? And if all youre trying to do is make an API call to CreateWindowEx why is any additional file let alone a database required, especially given that 1) youve posted the code in question, and 2) even that code has nothing to do with databases ... ?

I apologise if you're not fishing with malware (i apologise for assuming the worst), it's just that when people ask for questions about code they usually send, well... just code -- in the form of text (or a zip if there's associated files), as it's simply the most convenient.

I've never seen "i'll send it in a <insert executable database format here>", which would additionally require users to have a program that supports that database format just to open it (so again warning bells - why not a zip?), so when 1) it's your first post, 2) it's nothing to do with Purebasic yet about some other basic, and 3) you're offering to send a file of that nature when it has seemingly nothing to do with a simple API call (and one which (.accdb) is known as a malware host), and 4) thats instead of a .txt or .zip ... red flags every time sorry.

If your question was about using CreateWindowEx in Purebasic I guarantee you we would've had a solution for you by now (and plenty of people have already called CreateWindowEx in Purebasic), most questions rarely go half a day without some answer, but as your question is about Visual Basic this isn't the forum sorry.

Again please forgive me if you feel I was rude or overly-cautious, but as you're a programmer and given the above context and the security position we're all in in 2017 I'm sure you can understand why :)
Anyway I hope somebody at a Visual Basic forum is able to help you with your Visual Basic problem
Post Reply