(BMX-NG) Windows icon not attaching properly.

BlitzMax Forums/Brucey's Modules/(BMX-NG) Windows icon not attaching properly.

Devlin(Posted 2016) [#1]
Using version from http://www.bmx-ng.com/main/downloads/
(Updated: 30/12/15)
BlitzMax_win32_0.70.3.09.7z (Includes SDL backend, and mojo2)

I use this code to set an icon in explorer / the window/taskbar for my games/tools.

Works fine in regular OG BlitzMax, but in BlitzMax-NG it gives out a long error and I don't know what I'm doing wrong, if anything.

?Win32
	Import "./icon.o"
	Extern "win32"
		Function ExtractIconA:Int(hWnd:Int,File:String,Index:Int)
		Function GetActiveWindow:Int()
		Function SendMessage:Int(hWnd:Int , MSG:Int , wParam:Int , lParam:Int)
	End Extern
	
	Function SetIcon(iconname$, TheWindow%)
		Local icon:Int=ExtractIconA(TheWindow,iconname,0)
		sendmessage(TheWindow, $80, 1, icon)
	End Function
?

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a bit later on, after I init gfx

?Win32
SetIcon(AppFile, GetActiveWindow())
?



If I try and build with that code above, this happens

Building runner
[ 77%] Processing:Constants.bmx
[ 78%] Processing:HyperScale.bmx
[ 80%] Processing:Joysticks.bmx
[ 81%] Processing:PixelFont.bmx
[ 83%] Compiling:Constants.bmx.release.win32.x86.c
[ 85%] Compiling:HyperScale.bmx.release.win32.x86.c
[ 86%] Compiling:Joysticks.bmx.release.win32.x86.c
[ 88%] Compiling:PixelFont.bmx.release.win32.x86.c
[ 90%] Processing:LanguageData.bmx
[ 91%] Processing:ThingData.bmx
[ 93%] Compiling:LanguageData.bmx.release.win32.x86.c
[ 95%] Compiling:ThingData.bmx.release.win32.x86.c
[ 96%] Processing:runner.bmx
[ 98%] Compiling:runner.bmx.gui.release.win32.x86.c
In file included from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.c:1:0:
C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.h:36:25: error: conflicting types for 'GetActiveWindow'
 extern BBINT __stdcall  GetActiveWindow();
                         ^
In file included from D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/windows.h:72:0,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_thread.h:7,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz.h:28,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/.bmx/blitz.bmx.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.c:1:
D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/winuser.h:2485:26: note: previous declaration of 'GetActiveWindow' was here
   WINUSERAPI HWND WINAPI GetActiveWindow(VOID);
                          ^
In file included from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.c:1:0:
C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.h:37:25: error: conflicting types for 'ExtractIconA'
 extern BBINT __stdcall  ExtractIconA(BBINT bbt_hWnd,BBSTRING bbt_File,BBINT bbt_Index);
                         ^
In file included from D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/windows.h:89:0,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_thread.h:7,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz.h:28,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/.bmx/blitz.bmx.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.c:1:
D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/shellapi.h:87:20: note: previous declaration of 'ExtractIconA' was here
   SHSTDAPI_(HICON) ExtractIconA (HINSTANCE hInst, LPCSTR pszExeFileName, UINT nIconIndex);
                    ^
In file included from D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/winnt.h:9:0,
                 from D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/minwindef.h:163,
                 from D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/windef.h:8,
                 from D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/windows.h:69,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_thread.h:7,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz.h:28,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/.bmx/blitz.bmx.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.c:1:
C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.h:38:25: error: conflicting types for 'SendMessageA'
 extern BBINT __stdcall  SendMessage(BBINT bbt_hWnd,BBINT bbt_MSG,BBINT bbt_wParam,BBINT bbt_lParam);
                         ^
In file included from D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/windows.h:72:0,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_thread.h:7,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz.h:28,
                 from D:/BlitzMax/mod/brl.mod/blitz.mod/.bmx/blitz.bmx.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.h:4,
                 from C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.c:1:
D:/BlitzMax/MinGW32/x86_64-w64-mingw32/include/winuser.h:1980:29: note: previous declaration of 'SendMessageA' was here
   WINUSERAPI LRESULT WINAPI SendMessageA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);
                             ^
Build Error: failed to compile (1) C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/.bmx/runner.bmx.gui.release.win32.x86.c
Process complete


Not sure if it's relevant or not but regardless of arch setting(x86 or x64) it seems to include the header from an x86_64 folder?


Devlin(Posted 2016) [#2]
x


Brucey(Posted 2016) [#3]
Hallo :-)

Welcome to low level cross-architecture programming!

Firstly, some useful information regarding bigger changes you'll need to look out for regarding making stuff for 64-bit.
The main thing is that pointers are BIG, and no longer the same size as an Int. With BlitzMax, BRL were able to drastically simplify API calls by declaring most things as Int, including the majority of pointers. But with 64-bit you can't do that anymore, and legacy code will need to be changed.

Your code is "legacy" so will need to be changed :-)

As far as Win32 types are concerned : HWND, HICON, WPARAM and LPARAM are all pointers, so you should probably use Byte Ptr instead of Int.

Now, because NG is generating C code, and by default, Extern functions are included in the header (for other modules to see), and on Windows, windows.h is always loaded, all these functions are already declared. Which is why you see things like "previous declaration of ...".

One way to get around this is to not include duplicated declarations. But how to decide which extern functions to declare ourselves or not?

So I came up with a concept of adding an extra file (.x) with the same filename as your externs are declared in, which simply lists the functions in question and optionally causes them not to be implicitly declared.

The format is pretty simple really. When you see a function listed in the error like this:
WINUSERAPI HWND WINAPI GetActiveWindow(VOID);

you can add a line to your .x file like this:
HWND GetActiveWindow()!

Note the exclamation at the end. It tells the compiler not to generate a declaration of the function ourself. If you leave it off, it will declare the function as listed in the .x file.

For a more complex example :
WINUSERAPI LRESULT WINAPI SendMessageA(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);

You just list all arguments by their type, excluding the name of the argument :
LRESULT SendMessageA(HWND, UINT, WPARAM, LPARAM)!


In your particular example, all these functions are now part of the latest pub.win32, so in theory you wouldn't need to declare them yourself in an extern block.


Devlin(Posted 2016) [#4]
When I import Pub.Win32 I get a new error now, and it comes up with this error regardless of whether my code is present or not.

Building runner
[ 77%] Processing:Constants.bmx
[ 79%] Processing:HyperScale.bmx
[ 80%] Processing:Joysticks.bmx
[ 82%] Processing:PixelFont.bmx
[ 83%] Compiling:Constants.bmx.release.win32.x86.c
[ 85%] Compiling:HyperScale.bmx.release.win32.x86.c
[ 87%] Compiling:Joysticks.bmx.release.win32.x86.c
[ 88%] Compiling:PixelFont.bmx.release.win32.x86.c
[ 90%] Processing:LanguageData.bmx
[ 91%] Processing:ThingData.bmx
[ 93%] Compiling:LanguageData.bmx.release.win32.x86.c
[ 95%] Compiling:ThingData.bmx.release.win32.x86.c
[ 96%] Processing:runner.bmx
[ 98%] Compiling:runner.bmx.gui.release.win32.x86.c
[100%] Linking:runner.exe
D:/BlitzMax/mod/pub.mod/win32.mod/win32.release.win32.x86.a(com.bmx.release.win32.x86.o):com.bmx.release.win32.x86.c:(.text+0x6b3): undefined reference to `_imp__IIDFromString@8'
D:/BlitzMax/mod/pub.mod/win32.mod/win32.release.win32.x86.a(com.bmx.release.win32.x86.o):com.bmx.release.win32.x86.c:(.text+0x6f0): undefined reference to `_imp__StringFromIID@8'
Build Error: Failed to link C:/Users/David/Dropbox/Dev Stuff/Complete/Rising Runner/Source/runner.exe
Process complete