Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
translating win32API C tutorial to fB ::New question::
#6
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
Reply


Messages In This Thread
translating win32API C tutorial to fB ::New question:: - by Sisophon2001 - 03-14-2005, 10:02 AM
Next question: - by red_Marvin - 03-16-2005, 07:53 PM
Win32 Api wgl - by Glu - 03-18-2005, 01:29 AM
Win32 Api wgl - by Glu - 03-22-2005, 07:00 AM
Win 32 - by Glu - 03-23-2005, 10:31 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)