Compiler option: -w

Forum for discussion about the documentation project.
Josep Roca
Posts: 516
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiler option: -w

Postby Josep Roca » Sep 27, 2020 14:34

> #Include "inc\win\windowsx.bi" ' you must be a very advanced user to find this...!

C++ programmers use it all the time.

> error 42: Variable not declared, SNDMSG in 'listbox_addstring(hList, "just a test")

You must include "windows.bi" first.

> The Utf16$(ansi$) macro replaces around 20 lines of code with MultiByteToWideChar etc;

You can use overloaded functions to allow to pass the parameters as you wish, e.g.

Code: Select all

FUNCTION _SendMessage OVERLOAD (BYVAL hwnd AS HWND, BYVAL Msg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
  FUNCTION = SendMessage(hwnd, Msg, wParam, lParam)
END FUNCTION

FUNCTION _SendMessage (BYVAL hwnd AS HWND, BYVAL Msg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS ANY PTR) AS LRESULT
  FUNCTION = SendMessage(hwnd, Msg, wParam, cast(LPARAM, lParam))
END FUNCTION

FUNCTION _SendMessage (BYVAL hwnd AS HWND, BYVAL Msg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPCTSTR) AS LRESULT
  FUNCTION = SendMessage(hwnd, Msg, wParam, cast(LPARAM, lParam))
END FUNCTION

FUNCTION _SendMessage (BYVAL hwnd AS HWND, BYVAL Msg AS UINT, BYVAL wParam AS ANY PTR, BYVAL lParam AS ANY PTR) AS LRESULT
  FUNCTION = SendMessage(hwnd, Msg, cast(WPARAM, wParam), cast(LPARAM, lParam))
END FUNCTION

' [add more combinations]



The third one allows you to pass string variables or string literals, both ansi and unicode (and without having to mess with MultiByteToWideChar).

Code: Select all

#define UNICODE
....

DIM s AS STRING = "Nabokov"
_SendMessage(hListBox, LB_ADDSTRING, 0, s)
_SendMessage(hListBox, LB_ADDSTRING, 0, "Набóков")


There are always workarounds...
jj2007
Posts: 1962
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Compiler option: -w

Postby jj2007 » Sep 27, 2020 15:19

Josep Roca wrote:> #Include "inc\win\windowsx.bi" ' you must be a very advanced user to find this...!

C++ programmers use it all the time.
Basic programmers don't
> error 42: Variable not declared, SNDMSG in 'listbox_addstring(hList, "just a test")

You must include "windows.bi" first.
I did include windows.bi first
> The Utf16$(ansi$) macro replaces around 20 lines of code with MultiByteToWideChar etc;

You can use overloaded functions to allow to pass the parameters as you wish
Good idea. So we could call the overloaded function SendMessage, and under the hood it's _SendMessageA()?

Oops:

Code: Select all

error 98: Ambiguous call to overloaded function, _SENDMESSAGE() in '_SendMessage(hEdit, WM_SETTEXT, 0, @file_char(0))
Apparently our bloody beginner in BASIC has to study the type of the LPARAM in order to decide which of the overloaded functions is the right one...
Josep Roca
Posts: 516
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiler option: -w

Postby Josep Roca » Sep 27, 2020 17:50

First you complain about...

Btw, FB requires some acrobatics for simple tasks like:
Code: Select all

Dim As String hw="Hello World"
SendMessage(hEdit, WM_SETTEXT, 0, @hw[0])

Same in Assembly:
Code: Select all

SetGlobals hEdit:HANDLE, hw$="Hello World"
invoke SendMessage, hEdit, WM_SETTEXT, 0, hw$


then I suggest an overloaded function that allows to do what you want

Code: Select all

Dim As String hw="Hello World"
_SendMessage(hEdit, WM_SETTEXT, 0, hw)


but you use _SendMessage(hEdit, WM_SETTEXT, 0, @file_char(0)) apparently to look for a way to make the function to fail...

Well, if what you want is to change the compiler to get rid of type checking I'm afraid that this is unlikely to happen.
fxm
Posts: 10228
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Compiler option: -w

Postby fxm » Sep 27, 2020 18:30

I remind you that we are on the documentation forum and "Compiler option: -w" thread.
The original querying was:
I discovered that if I use an invalid value for the -w switch, the compiler doesn't complain."
Jeff added a sentence in the documentation:
fbc does not issue warning or error if the warning name itself is not valid. For example -w flarg, is not a recognized name for a warning. The compiler silently ignores this to allow command lines with warnings added in new versions of fbc to also be used with older versions of fbc without complaint.

If you wish, you can still continue these off-topic post exchanges, but rather on the Windows forum which seems the more appropriate place.
jj2007
Posts: 1962
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Compiler option: -w

Postby jj2007 » Sep 27, 2020 20:54

Josep Roca wrote:but you use _SendMessage(hEdit, WM_SETTEXT, 0, @file_char(0)) apparently to look for a way to make the function to fail...
Josep, I assure you that there was no such intention. I just applied your overloaded function to the existing code that I posted earlier, and it failed, that's it. FB requires considerable acrobatics, and passing a simple string as @file_char(0) is really not BASIC IMHO, but that's what the original code required to pass a standard Windows zstring pointer... if I have such problems with my 35+ years of BASIC experience, what about the n00b?

I have deep respect of your work, and I regret that this topic derails like this.
Josep Roca
Posts: 516
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiler option: -w

Postby Josep Roca » Sep 28, 2020 8:11

We have been reminded that we are off topic, so if you want to continue the disussion please open a new topic in the Windows section. Maybe we can find an acceptable solution.
jj2007
Posts: 1962
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Compiler option: -w

Postby jj2007 » Sep 28, 2020 9:23

Josep Roca wrote:We have been reminded that we are off topic, so if you want to continue the disussion please open a new topic in the Windows section. Maybe we can find an acceptable solution.
So be it: Simple template with menu, edit control, listbox and statusbar

Return to “Documentation”

Who is online

Users browsing this forum: No registered users and 1 guest