How can i use variables declared in WinMain function in WndProc function ?

New to FreeBASIC? Post your questions here.
MrSwiss
Posts: 2476
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby MrSwiss » Mar 07, 2018 16:40

Thank you, very much indeed, for answering "the" real question ...

fxm wrote:First I am answering as I want (I am not connected as a Boolean)!
OK, next time I'll add: "don't know" to the list. ;-)
caseih
Posts: 1188
Joined: Feb 26, 2007 5:32

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby caseih » Mar 08, 2018 2:25

Got me curious. MrSwiss the answer to your question can be found by looking at the runtime library sources. ERR translates to a function call, "fb_ErrorGetNum()" which itself refers a special context structure. This structure is stored in thread-local storage. So the answer is no, err is not global across the entire program necesarily. However it is global inside of each thread. I believe this is similar to how C does it. But FB's err does not appear to be the same as the standard C library's err variable. FB does it's own thing, based of course on the errors returned by various C library functions, as well as FB runtime functions.
deltarho[1859]
Posts: 1041
Joined: Jan 02, 2017 0:34
Location: UK

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby deltarho[1859] » Mar 08, 2018 2:36

<Exceptionally large yawn>
MrSwiss
Posts: 2476
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby MrSwiss » Mar 08, 2018 16:37

@caseih, thanks for the research, which in conclusion proofes, that FB-DOC is correct,
as currently written.
In order to quickly find the file(s) in source, could you perhaps state their NAME(s)?
Thanks again.
caseih
Posts: 1188
Joined: Feb 26, 2007 5:32

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby caseih » Mar 08, 2018 17:54

At the risk of putting deltarho to sleep, sure. fb_ErrorGetNum() is defined in src/rtlib/error_getset.c. This in turn calls a macro, FB_TLSGETCTX( ERROR ) in fb_thread.h which returns the context structure that is stored in the thread-local storage area. The macro calls fb_TlsGetCtx() that's defined in thread_ctx.c. I never went as far as finding where the structure itself was defined.

Anyway if you have a copy of fbc's source code, grep is a fast and easy way to find things over many thousands of files and modules. Sometimes a more complicated tool like cscope is useful also.
MrSwiss
Posts: 2476
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby MrSwiss » Mar 08, 2018 20:03

caseih wrote:... if you have a copy of fbc's source code, grep is a fast and easy way ...
That's the catch, I've to search on "sf.net", which makes it a PITA, without knowing,
where to look for it ... Thanks again.
caseih
Posts: 1188
Joined: Feb 26, 2007 5:32

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby caseih » Mar 08, 2018 23:36

You're very welcome. Another good search method that's as good as grep is to go to the github repository and search for the symbol using the search box at the top of the page. https://github.com/freebasic/fbc. For example, https://github.com/freebasic/fbc/search ... tNum&type=

Oh and the way I discovered that was the function that returns ERR was to use the compiler to emit C code, which I looked at to see the actual runtime library function call.
kcvinu
Posts: 134
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: How can i use variables declared in WinMain function in WndProc function ?

Postby kcvinu » Mar 11, 2018 19:50

Thank you all. Shared keyword is worked for me. And the GetProp() and SetProp() function examples are really great. Because, i was reading Mr. Fred'd posts in Jose Roca's forum. In one of his posts, he illustrates how to save details about wndProc and other stuff in a CREATESTRUCT. Since his examples were in PB, i was littile bit struggling to convert it to FrerBasic. But jcfuller's code helped me a lot. Thanks once again. Actually, my plan is to make a gui library based win api. All this for only learning. I think doing is the only way to learn. So i decided to make one for me. My goal is to bypass the WndProc function. Something like in thinBasic. User can write the functionality in a callback function and a lot of macros like GetHandle from WM_COMMAND and WM_NOTIFY will help them. Now i am reading Frederick J Harris's tutorial. Cant find something like that in here. If you know something like that here, please point me to that link.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest