03-14-2005, 10:02 AM
Quote:Thanks!
It works now, although I didn't need to put brackets (right word?)
around hwnd=0
Do anyone know why these differences matter in fB compared to c?
Hi:
I am another newbie using FreeBASIC for the first time, and but then FreeBASIC is new, so I guess we are all learning together.
I did not try your code, as zydon already got it working for you, but I will try answering your questions based on what I have see and read so far.
1)
A variable in FreeBASIC has a value and a memory address where that value is stored. If you send a variable to a Win API function BYVAL, you are sending its value. If you send a variable BYREF, you are sending the address. There is an exception to this simple rule. In C which all the windows API was written in, a string is an array of characters. In FreeBASIC it is a structure, containing the string of characters, the string length and the string type (and possibly some more info that I donât recall). If a Windows API function expects the address of an array of characters, you can not send it the address of a BASIC string, or you will crash. Instead there is a convention that you send the string BYVAL, and the FreeBASIC compiler understands that what you actually want is to send a reference to the actual data inside the string.
2)
const char g_szClassName[] = "myWindowClass";
g_szClassName is a character pointer, not a constant like used in FreeBASIC. The prefix const is to tell the C++ compiler (and this is C++ code, not C code) not to allow the programmer to edit the string. Depending on how you tried to translate this into BASIC you might have mixed things up. A CONST in FreeBASIC behaves like a #define in C.
3)
wndproc=0
In FreeBASIC giving a value to the function return does not cause the function to exit. You need to add EXIT FUNCTION, or do as Zydon recommended, and move the wndproc=0 to before the select case. The problem with the original code was that
wndproc=defwindowproc(hwnd,msg,wparam,lparam)
just assigned a value to wndproc, but this value was never returned from the function because the function did not exit at that point. It was overwritten by wndproc=0 you had at the bottom of the function.
Have fun
Garvan