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

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

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

Post by MrSwiss »

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: 2157
Joined: Feb 26, 2007 5:32

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

Post by caseih »

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: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

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

Post by deltarho[1859] »

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

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

Post by MrSwiss »

@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: 2157
Joined: Feb 26, 2007 5:32

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

Post by caseih »

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: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

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

Post by MrSwiss »

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: 2157
Joined: Feb 26, 2007 5:32

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

Post by caseih »

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: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

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

Post by kcvinu »

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.
Post Reply