New Windows API headers

Windows specific questions.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

New Windows API headers

Post by dkl »

Hello,

I've been working on updating inc/windows.bi and inc/win/*.bi for 64bit support recently, and I think they're close to being finished. Here you can find a win32 and a win64 package prepared with the new headers, for testing:

http://sourceforge.net/projects/fbc/fil ... %20Builds/

It'd be really great if some of you could give it a go - to see whether existing win32 programs using windows.bi & co still compile, and to see whether the headers work on win64. Of course I've done some testing myself, but only with the programs from FreeBASIC/examples/GUI/win32...

Some information about the new headers:
  • They are largely auto-generated, based on the *.h files from the MinGW-w64 project. That alone caused a lot of differences in comparison to the previous headers which, I think, were based on the ones from the MinGW.org project.
  • They support 32bit and 64bit, UNICODE and non-UNICODE, and three hand-selected _WIN32_WINNT settings: &h0400 &h0502 &h0602 (more could be done in the future)
  • They are supposed to keep some specialties which FB's winapi headers have traditionally had, such as renaming the RGB macro to BGR, or making windows.bi use winsock2.bi instead of winsock.bi, and only under certain #defines...
SARG
Posts: 1774
Joined: May 27, 2005 7:15
Location: FRANCE

Re: New Windows API headers

Post by SARG »

Hi dkl,

Thanks for this job.

Compilation of fbdebugger, see log below.

- Some VK_[letter] seem missing. e.g. VK_A but not VK_F3.
- Structure of debug_event changed ???. Almost all the errors are related to debug_event.
- Choosefont and choosecolor. Maybe missing include.

And I have not tested the execution....

Code: Select all

D:\Laurent divers\FreeBASIC\fbc  -s gui -v -maxerr 100 "FBdebugger.bas" "FBdebugger.rc"
FreeBASIC Compiler - Version 1.02.0 (01-12-2015), built for win32 (32bit)
Copyright (C) 2004-2015 The FreeBASIC development team.
standalone
target:       win32, 486, 32bit
compiling:    FBdebugger.bas -o FBdebugger.asm (main module)
FBdebugger.bas(3615) error 41: Variable not declared, VK_C in 'menu_option(menuedit,IDCONTHR,  "Run to Cursor",VK_C)'
FBdebugger.bas(3618) error 41: Variable not declared, VK_S in 'menu_option(menuedit,IDBUTSTEP,  "Next step",VK_S)'
FBdebugger.bas(3619) error 41: Variable not declared, VK_O in 'menu_option(menuedit,IDBUTSTEPP, "Step over procs",VK_O)'
FBdebugger.bas(3620) error 41: Variable not declared, VK_E in 'menu_option(menuedit,IDBUTSTEPM, "Step out current proc",VK_E)'
FBdebugger.bas(3621) error 41: Variable not declared, VK_T in 'menu_option(menuedit,IDBUTSTEPT, "Step top called proc",VK_T)'
FBdebugger.bas(3622) error 41: Variable not declared, VK_B in 'menu_option(menuedit,IDBUTSTEPB, "Step bottom current proc",VK_B)'
FBdebugger.bas(3623) error 41: Variable not declared, VK_R in 'menu_option(menuedit,IDBUTRUN,   "Run",VK_R)'
FBdebugger.bas(3624) error 41: Variable not declared, VK_F in 'menu_option(menuedit,IDFASTRUN,  "Fast Run",VK_F)'
FBdebugger.bas(3625) error 41: Variable not declared, VK_H in 'menu_option(menuedit,IDBUTSTOP,  "Halt running debuggee",VK_H)'
FBdebugger.bas(3626) error 41: Variable not declared, VK_K in 'menu_option(menuedit,IDBUTKILL,  "Kill debuggee",VK_K)'
FBdebugger.bas(3627) error 41: Variable not declared, VK_A in 'menu_option(menuedit,IDBUTAUTO,  "Step auto",VK_A)'
FBdebugger.bas(3628) error 41: Variable not declared, VK_D in 'menu_option(menuedit,IDTHRDAUT,  "Step auto multi threads",VK_D)'
FBdebugger.bas(3629) error 41: Variable not declared, VK_M in 'menu_option(menuedit,IDEXEMOD,   "Modify execution",VK_M)'
FBdebugger.bas(3649) error 41: Variable not declared, VK_L in 'menu_option(menuedit,IDFCSSRC,   "Focus lines",VK_L)'
FBdebugger.bas(9376) error 18: Element not defined, debugstring in 'If debugev.debugstring.nDebugStringLength<400 Then'
FBdebugger.bas(9376) error 8: Undefined symbol, nDebugStringLength in 'If debugev.debugstring.nDebugStringLength<400 Then'
FBdebugger.bas(9377) error 9: Expected expression, found '.' in 'leng=debugev.debugstring.nDebugStringLength'
FBdebugger.bas(9378) error 116: ELSE without IF, found 'Else' in 'Else'
FBdebugger.bas(9380) error 124: Expected 'END SUB', found 'EndIf' in 'EndIf'
FBdebugger.bas(9381) error 9: Expected expression, found '.' in 'If debugev.debugstring.fUnicode Then'
FBdebugger.bas(9381) error 8: Undefined symbol, fUnicode in 'If debugev.debugstring.fUnicode Then'
FBdebugger.bas(9382) error 9: Expected expression, found '.' in 'ReadProcessMemory(dbghand,Cast(LPCVOID,debugev.debugstring.lpDebugStringData),_'
FBdebugger.bas(9385) error 116: ELSE without IF, found 'Else' in 'Else'
FBdebugger.bas(9386) error 9: Expected expression, found '.' in 'ReadProcessMemory(dbghand,Cast(LPCVOID,debugev.debugstring.lpDebugStringData),_'
FBdebugger.bas(9389) error 124: Expected 'END SUB', found 'EndIf' in 'EndIf'
FBdebugger.bas(9415) error 18: Element not defined, Exception in 'firstchance=DebugEv.Exception.dwfirstchance'
FBdebugger.bas(9416) error 9: Expected expression, found '.' in 'adr=Cast(UInteger,DebugEv.Exception.ExceptionRecord.ExceptionAddress)'
FBdebugger.bas(9440) error 9: Expected expression, found '.' in 'Select Case (DebugEv.Exception.ExceptionRecord.ExceptionCode)'
FBdebugger.bas(9457) error 14: Expected identifier, found '.' in 'With DebugEv.Exception.ExceptionRecord'
FBdebugger.bas(9467) error 1: Argument count mismatch, found '.' in 'libel=excep_lib(DebugEv.Exception.ExceptionRecord.ExceptionCode)+Chr(13)'
FBdebugger.bas(9469) error 9: Expected expression, found '.' in 'If DebugEv.Exception.ExceptionRecord.ExceptionCode=EXCEPTION_ACCESS_VIOLATION Then'
FBdebugger.bas(9469) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'ExceptionRecord' in 'If DebugEv.Exception.ExceptionRecord.ExceptionCode=EXCEPTION_ACCESS_VIOLATION Then'
FBdebugger.bas(9470) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'ExceptionInformation' in 'libel+=Accviolstr(.ExceptionInformation(0))+" AT ADR : "+Str(.ExceptionInformation(1))+" / "+Hex(.ExceptionInformation(1))+Chr(13)'
FBdebugger.bas(9471) error 59: Expected 'END WITH', found 'EndIf' in 'EndIf'
FBdebugger.bas(9541) error 18: Element not defined, Createthread in 'With DebugEv.Createthread'
FBdebugger.bas(9548) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'hthread' in 'threadnb+=1 :thread(threadnb).hd=.hthread:thread(threadnb).id=DebugEv.dwThreadId'
FBdebugger.bas(9549) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'hthread' in 'threadcontext=.hthread'
FBdebugger.bas(9564) error 18: Element not defined, CreateProcessInfo in 'With DebugEv.CreateProcessInfo'
FBdebugger.bas(9565) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'hfile' in 'dbghfile=.hfile' to close the handle and liberate the file .exe'
FBdebugger.bas(9566) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'hthread' in 'threadnb=0:thread(0).hd=.hthread:thread(0).id=DebugEv.dwThreadId'
FBdebugger.bas(9567) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'hthread' in 'threadcontext=.hthread'
FBdebugger.bas(9589) error 264: Symbol not a CLASS, ENUM, TYPE or UNION type, before 'lpBaseOfImage' in 'debug_extract(Cast(UInteger,.lpBaseOfImage),exename) '07/11/2013'
FBdebugger.bas(9621) error 18: Element not defined, loaddll in 'Dim loaddll As LOAD_DLL_DEBUG_INFO=DebugEv.loaddll'
FBdebugger.bas(9679) error 18: Element not defined, unloaddll in 'Dim unloaddll As UNLOAD_DLL_DEBUG_INFO =DebugEv.unloaddll'
FBdebugger.bas(11761) error 41: Variable not declared, ChooseFont in 'rc=ChooseFont(@cf)'
FBdebugger.bas(12550) error 41: Variable not declared, choosecolor in 'If choosecolor(@colch) Then 'color chosen, inverse of FBC'

Build error(s)
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: New Windows API headers

Post by dkl »

VK_0 to VK_Z #defines: do not exist in the C headers, but easy to add for FB again.

DEBUG_EVENT: in the C headers it's .u.DebugString instead of .DebugString - the union is named, not anonymous. http://msdn.microsoft.com/en-us/library ... 79308.aspx
It looks like that was omitted in the old headers, but it seems to me like we should match the C headers here.

ChooseColor/ChooseFont: currently broken indeed (some others too)
SARG
Posts: 1774
Joined: May 27, 2005 7:15
Location: FRANCE

Re: New Windows API headers

Post by SARG »

dkl wrote:VK_0 to VK_Z #defines: do not exist in the C headers, but easy to add for FB again.
Added using enum.
DEBUG_EVENT: in the C headers it's .u.DebugString instead of .DebugString - the union is named, not anonymous. http://msdn.microsoft.com/en-us/library ... 79308.aspx
It looks like that was omitted in the old headers, but it seems to me like we should match the C headers here.
"u." added when necessary
ChooseColor/ChooseFont: currently broken indeed (some others too)
For now lines commented.

Compilation ok and no problem when executing fbdebugger.

I have tried the 64bit version just to see..... I got a lot of errors but the only issue with headers is : "GCL_HBRBACKGROUND" is unknown.

Code: Select all

SetClassLong(windmain,GCL_HBRBACKGROUND,Cast(Long,hbrsh))
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: New Windows API headers

Post by MichaelW »

As a first test I took the 64-bit cycle count test code (test64.bas) from here, modified it to:

Code: Select all

#include "windows.bi"
''=============================================================================

''---------------------------------------------------------------
'' These declarations are the minimum required for this app, to
'' replace the functionality of the windows.bi that is currently
'' missing from the 64-bit version.
''---------------------------------------------------------------

''type HANDLE as any ptr
''type DWORD as uinteger
''type WINBOOL as integer
''type BOOL as WINBOOL

''#define REALTIME_PRIORITY_CLASS &h00000100
''#define THREAD_PRIORITY_TIME_CRITICAL 15

''extern "windows" lib "kernel32"
''declare function GetCurrentProcess () as HANDLE
''declare function GetCurrentThread () as HANDLE
''declare function GetPriorityClass (byval as HANDLE) as DWORD
''declare function GetThreadPriority (byval as HANDLE) as integer
''declare function SetPriorityClass (byval as HANDLE, byval as DWORD) as BOOL
''declare function SetThreadPriority (byval as HANDLE, byval as integer) as BOOL
''declare function SetProcessAffinityMask (byval as HANDLE, byval as DWORD) as BOOL
''end extern

''=============================================================================
#include "counter64.bas"
''=============================================================================

dim as integer x=1,y=2,z=3
dim as long    xL=1,yL=2,zL=3
dim as longint xLi=1,yLi=2,zLi=3
dim shared as any ptr p1, p2

p1 = allocate(100*8)
p2 = allocate(100*8)

SetProcessAffinityMask( GetCurrentProcess(), 1)

sleep 5000

for i as integer = 1 to 3
    counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)
        z = 0
        z = (x*x+y*y)\(x+1)
    counter_end
    print counter_cycles;" cycles integer"

    counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)
        zL = 0
        zL = (xL*xL+yL*yL)\(xL+1)
    counter_end
    print counter_cycles;" cycles long"

    counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)
        zLi = 0
        zLi = (xLi*xLi+yLi*yLi)\(xLi+1)
    counter_end
    print counter_cycles;" cycles longint"
    print
next

for i as integer = 1 to 3
    counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)
        asm
            ".intel_syntax noprefix"
            "push rdi"
            "push rsi"
            "mov  esi, P1$"
            "mov  edi, P2$"
            "mov  ecx, 100"
            '' test64.asm:937: Error: same type of prefix used twice for:
            '' "rex64 rep movsq"
            "rep   movsq"
            "pop   rsi"
            "pop   rdi"
            ".att_syntax prefix"
        end asm
    counter_end
    print counter_cycles;" cycles, rep movsq * 100"
next

sleep
And it compiled and ran as expected.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: New Windows API headers

Post by MichaelW »

For my next test I used dialogs.bas from here, and the toolbar demo from the same thread. Compiling to a 32-bit app everything worked as expected, but when I tried to compile to a 64-bit app I got the following errors:

Code: Select all

C:\Users\User\Documents\MyFreeBASIC\Dialogs\dialogs.bas(342) error 20: Type mismatch, before ')' in 'ul = cast(ULONG,g_lpw) + 3'
C:\Users\User\Documents\MyFreeBASIC\Dialogs\dialogs.bas(345) error 28: Expected pointer, before ')' in 'g_lpw = cast(LPWORD,ul)'
To correct the problem, starting on line 337 of dialogs.bas, I made two changes, going from:

Code: Select all

  dim as ULONG ul

  '' The DLGITEMTEMPLATE structure must be aligned on a
  '' DWORD boundary.
  ''
  ul = cast(ULONG,g_lpw) + 3
  ul shr= 2
  ul shl= 2
  g_lpw = cast(LPWORD,ul)
To:

Code: Select all

  dim as ULONG_PTR ul

  '' The DLGITEMTEMPLATE structure must be aligned on a
  '' DWORD boundary.
  ''
  ul = cast(ULONG_PTR,g_lpw) + 3
  ul shr= 2
  ul shl= 2
  g_lpw = cast(LPWORD,ul)
And the explanation for this:
MSDN wrote: A ULONG_PTR is an unsigned long type used for pointer precision. It is used when casting a pointer to a long type to perform pointer arithmetic.
This type is declared as follows:
typedef unsigned __int3264 ULONG_PTR;
Where __int3264 is 32-bit for a 32-bit app and 64-bit for a 64-bit app.

The code then compiled with no warnings or errors and running the app under Windows 7-64 everything worked as expected, except for the tool tips. After some searching it looks like the tool tip problem is due to a Windows 7 bug, and I have no way ATM to test a 64-bit app under any other version of Windows.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: New Windows API headers

Post by MichaelW »

For my next test I used the Bezier curve demo here, and it compiled to a 64-bit app with no errors or warnings, and the exe ran as expected.

And I just realized that in my previous post, when I compiled a 32-bit app it was with the 0.90.1 32-bit compiler.
PaulSquires
Posts: 1002
Joined: Jul 14, 2005 23:41

Re: New Windows API headers

Post by PaulSquires »

Hi dkl,

I have started to test the Win64 headers. Thanks for providing them. My initial compiles revealed several undefined equates. As mentioned before GCL_HBRBACKGROUND but actually all of the GCL_* equates. I checked out the the winuser.bi include files and it appears that a lot of defined equates are wrapped in a conditional test:

Code: Select all

#ifndef __FB_64BIT__
	#define GCL_MENUNAME (-8)
	#define GCL_HBRBACKGROUND (-10)
	#define GCL_HCURSOR (-12)
	#define GCL_HICON (-14)
	#define GCL_HMODULE (-16)
#endif
Not sure why that test needs to be done. There shouldn't be abything special about the GCL_* equates between the 32 and 64 versions of Windows.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: New Windows API headers

Post by dkl »

I don't know, but it seems that these are not defined for Win64, by MinGW-w64 (same for original Windows SDK):
#ifdef _WIN64
#undef GCL_MENUNAME
...
Edit: searching the web revealed that the GCLP_* defines should be used instead - of course also GetClassLongPtr instead of GetClassLong, etc.
PaulSquires
Posts: 1002
Joined: Jul 14, 2005 23:41

Re: New Windows API headers

Post by PaulSquires »

dkl wrote:Edit: searching the web revealed that the GCLP_* defines should be used instead - of course also GetClassLongPtr instead of GetClassLong, etc.
Ah, yes, good find. I will have to do research to see if other areas of my Win32 api code need changes. Thanks!
PaulSquires
Posts: 1002
Joined: Jul 14, 2005 23:41

Re: New Windows API headers

Post by PaulSquires »

Hi dkl,

In my testing on 64 bit I noticed that my toolbar tooltips were not displaying. I tracked the problem down to the NMHDR code being defined as UINT but the notification I need was a negative number (TTN_GETDISPINFO = -520).

In the Win32 includes (commctrl.bi) the equate TTN_FIRST uses CUINT to convert the value to a positive number. Such a conversion is missing from the 64 bit version of commctrl.bi. I modifed commctrl.bi to use CULNG (rather than CUINT) and everything works okay now.

I believe the following 64 bit commctrl.bi modification will help:

Code: Select all

#define NM_FIRST CULng(0 - 0)
#define NM_LAST CULng(0 - 99)
#define LVN_FIRST CULng(0 - 100)
#define LVN_LAST CULng(0 - 199)
#define HDN_FIRST CULng(0 - 300)
#define HDN_LAST CULng(0 - 399)
#define TVN_FIRST CULng(0 - 400)
#define TVN_LAST CULng(0 - 499)
#define TTN_FIRST CULng(0 - 520)
#define TTN_LAST CULng(0 - 549)
#define TCN_FIRST CULng(0 - 550)
#define TCN_LAST CULng(0 - 580)
#define TBN_FIRST CULng(0 - 700)
#define TBN_LAST CULng(0 - 720)
#define UDN_FIRST CULng(0 - 721)
#define UDN_LAST CULng(0 - 740)
#define MCN_FIRST CULng(0 - 750)
#define MCN_LAST CULng(0 - 759)
#define DTN_FIRST CULng(0 - 760)
#define DTN_LAST CULng(0 - 799)
#define CBEN_FIRST CULng(0 - 800)
#define CBEN_LAST CULng(0 - 830)
#define RBN_FIRST CULng(0 - 831)
#define RBN_LAST CULng(0 - 859)
#define IPN_FIRST CULng(0 - 860)
#define IPN_LAST CULng(0 - 879)
#define SBN_FIRST CULng(0 - 880)
#define SBN_LAST CULng(0 - 899)
#define PGN_FIRST CULng(0 - 900)
#define PGN_LAST CULng(0 - 950)
#define WMN_FIRST CULng(0 - 1000)
#define WMN_LAST CULng(0 - 1200)
#define BCN_FIRST CULng(0 - 1250)
#define BCN_LAST CULng(0 - 1350)
I guess the other (easier) alternative would instead be to modify the NMHDR structure definition to change the Code member from UINT to LONG.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: New Windows API headers

Post by dkl »

Hmm, I see, that's not good. In C it's 32bit arithmetic, but in FB it's 64bit... so the result of such operations must be truncated to 32bit. I'll have to adjust fbfrog to handle that case, because I bet there will be other places with the same issue.
VANYA
Posts: 1839
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: New Windows API headers

Post by VANYA »

Hi all!

Error in the headers.

32bit version:

Code: Select all

#Include "windows.bi"
#Include "zlib.bi"
D:\Compilier\inc\zlib.bi(22) error 4: Duplicated definition in 'type uInt as ulong'
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: New Windows API headers

Post by dkl »

It works for me. Are you mixing old/new headers somehow?

Code: Select all

'' win/windef.bi:
type UINT as ulong
'' zlib.bi:
type uInt as ulong
'' same typedefs - should compile ok
VANYA
Posts: 1839
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: New Windows API headers

Post by VANYA »

dkl wrote:It works for me. Are you mixing old/new headers somehow?

Code: Select all

'' win/windef.bi:
type UINT as ulong
'' zlib.bi:
type uInt as ulong
'' same typedefs - should compile ok
I specifically downloaded the latest release, unpack and compile using it without changing its folders. Your example compiles fine, but my example does not compile (still the same error). And it's not just me.
Post Reply