Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #18922 > unrolled thread
| Started by | AKE <assadebrahim2000@gmail.com> |
|---|---|
| First post | 2013-01-20 02:52 -0800 |
| Last post | 2013-01-21 11:51 -0800 |
| Articles | 11 — 4 participants |
Back to article view | Back to comp.lang.forth
Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! AKE <assadebrahim2000@gmail.com> - 2013-01-20 02:52 -0800
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! mhx@iae.nl (Marcel Hendrix) - 2013-01-20 12:16 +0200
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! AKE <assadebrahim2000@gmail.com> - 2013-01-20 03:25 -0800
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! mhx@iae.nl (Marcel Hendrix) - 2013-01-20 14:34 +0200
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! AKE <assadebrahim2000@gmail.com> - 2013-01-20 03:17 -0800
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! AKE <assadebrahim2000@gmail.com> - 2013-01-20 06:15 -0800
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! Alex McDonald <blog@rivadpm.com> - 2013-01-20 11:31 -0800
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! AKE <assadebrahim2000@gmail.com> - 2013-01-20 15:21 -0800
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! Alex McDonald <blog@rivadpm.com> - 2013-01-21 08:23 -0800
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-01-21 18:25 +0000
Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! Alex McDonald <blog@rivadpm.com> - 2013-01-21 11:51 -0800
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-01-20 02:52 -0800 |
| Subject | Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! |
| Message-ID | <5fb78940-c093-40b5-affc-b2465e2877bb@googlegroups.com> |
Hi there: I'm relatively new to Forth, having programmed before in C, Win32, Ruby, and a little assemnbly. I've found Forth to be quite refreshing in its extreme modularity and interactivity. Am now involved in investigations around the design of a simulator, and thought that Forth might be a good platform during the explorations. It would make refactoring easier, allow quickly exploring various algorithms -- in short, am hoping it will help me develop and modify quickly, without the overhead involved in using a language like C, maybe even Ruby, all while being able to do things quite quickly (important because of large data loads). However, there are some facilities in Forth which are quite cumbersome compared to similar capability in other languages. For example, in Ruby is is incredibly easy to read in from files, parsing data, writing formatted data, connect to a SQL database, etc. I have little appetite to do any of this in Forth. So, in the spirit of the right tool for the right job, I would like to keep the high level stuff in Ruby or Python, but do the algorithmics, simulation, data manipulations / transformations in Forth. This requires an interface. To avoid having to use Forth's file utilities (blocks, etc.), I want to use the SHARED MEMORY facility provided by Win32. Which in principle means that I would read into a shared memory location using Ruby (facilitated by Win32 calls). Then open the shared memory in Forth using Win32 calls. I've got this working between C and Ruby. Now I need to get the Win32 calls working in Forth. And... embarassingly, I can't even get a simple MessageBoxA( ) call to work in Forth. I've been through the documentation, but can't seem to find the problem. Here's what I've got. Any help would be greatly appreciated! : hi z" Hello World! (from Forth)" rel>abs \ string ( -- msg_str_ptr len ) z" Extending Forth with Win32" rel>abs \ string ( -- title_str_ptr len ) NULL \ ( -- 0 ) call MessageBoxA \ ( style_param msg_str_ptr title_str_ptr handle -- ) ;
[toc] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2013-01-20 12:16 +0200 |
| Message-ID | <68199115028434@frunobulax.edu> |
| In reply to | #18922 |
AKE <assadebrahim2000@gmail.com> Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! [..] > And... embarassingly, I can't even get a simple MessageBoxA( ) call to work in Forth. > I've been through the documentation, but can't seem to find the problem. > > Here's what I've got. Any help would be greatly appreciated! > > : hi > z" Hello World! (from Forth)" rel>abs \ string ( -- msg_str_ptr len ) > z" Extending Forth with Win32" rel>abs \ string ( -- title_str_ptr len ) > NULL \ ( -- 0 ) > call MessageBoxA \ ( style_param msg_str_ptr title_str_ptr handle -- ) > ; When pasted into the Win32For console window: --- 8< ------------------------------------------------ 32bit Forth for Windows 95, 98, and NT Compiled: October 18th, 2006, 0:19am Version: 4.2 Build: 0545 Rebuilt by User Platform: Windows NT Version: 6.1 Build: 7601 3,815k bytes free 2,904 Words in Application dictionary 1,445 Words in System dictionary 4,349 Words total in dictionaries 9,462 Windows Constants available Loading Win32For.CFG *** DON'T PANIC, Press: F1 NOW! *** : hi z" Hello World! (from Forth)" rel>abs \ string ( -- msg_str_ptr len ) z" Extending Forth with Win32" rel>abs \ string ( -- title_str_ptr len ) NULL \ ( -- 0 ) call MessageBoxA \ ( style_param msg_str_ptr title_str_ptr handle -- ) ; ok hi ok .s empty ok --- 8< ----------------------------------------------------- ... it works as expected. Are you using Windows? (Not Linux and Wine)? Are you using the proper Win32for binary? What happens when you try to compile? What happens when you try to execute hi ? What happens when you use MessageBox and not MessageBoxA ? Do you know about the Yahoo Forth group? Please do not post using mime. -marcel
[toc] | [prev] | [next] | [standalone]
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-01-20 03:25 -0800 |
| Message-ID | <619b9133-469a-4e24-b2ad-165349b5a982@googlegroups.com> |
| In reply to | #18924 |
To Marcel: Thanks for the reply -- answers inline below: > ... it works as expected. Hmm. Did you see a Message Box appear with an OK button when you ran it? > Are you using Windows? (Not Linux and Wine)? Yes, Windows XP > Are you using the proper Win32for binary? Currently using Version 6.08.00. Also tried it in Tom Zimmer's last version: 42.0602 (Downloaded from Win32Forth) > What happens when you try to compile? Haven't tried compiling. Do I need to? I was hoping it would work from the interactive terminal. > What happens when you try to execute hi ? All 4 parameters get used up; get a 0 return value on the stack (correct), but no message box! > What happens when you use MessageBox and not MessageBoxA ? Same thing. > Do you know about the Yahoo Forth group? I saw both Google Groups (comp.lang.forth) and Yahoo Groups. Since I already have google accounts, chose comp.lang.forth. Is there a difference? Preference? > Please do not post using mime. ...? I'm using Google Groups web interface... is this a setting I should disable? Thanks!
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2013-01-20 14:34 +0200 |
| Message-ID | <91698915028434@frunobulax.edu> |
| In reply to | #18924 |
AKE <assadebrahim2000@gmail.com> writes Re: Wanting to use Shared Memory in Win32Forth using Win32 -- but stuck at MessageBoxA( ) ! >> ... it works as expected. > Hmm. Did you see a Message Box appear with an OK button when you ran it? Yes, it did. It probably works because the TOS contains 0 when I boot Win32Forth. You may have done something before defining hi, making TOS an invalid style constant. Technically, your example creates a stack underflow. You should always supply a stackdiagram for your words. I didn't notice that I should supply a style constant and expect a result. Your correction: : hi 40 \ style constant: MB_ICONINFORMATION z" Hello World!" rel>abs ( -- str_msg ) z" Title" rel>abs ( -- str_title ) NULL \ handle (independent) call MessageBoxA ( n ptr ptr h -- ret ) ; produces the information icon and a sound effect, HOWEVER, one should type $40 and not 40. The (decimal) style constant "40" is not valid with Windows 7 and no message box appears at all. >> Are you using Windows? (Not Linux and Wine)? > Yes, Windows XP I tested using Windows 7. >> Are you using the proper Win32for binary? >Currently using Version 6.08.00. >Also tried it in Tom Zimmer's last version: 42.0602 >(Downloaded from Win32Forth) I guess it should work, unless they got rid of the reverse parameters for Windows calls (Try NULL title msg style -- res). >> What happens when you try to compile? >Haven't tried compiling. Do I need to? I was hoping it would > work from the interactive terminal. In Forth, pasting in the text leads to the word "hi" being compiled. It may produce error messages in this stage. Then typing "hi" executes the word and ... hold on, you DID type hi at the prompt, after pasting the text, didn't you :-) >> What happens when you try to execute hi ? > All 4 parameters get used up; get a 0 return value on the stack > (correct), but no message box! That happened when I tried it with decimal 40 as a style constant. [..] >> Do you know about the Yahoo Forth group? >I saw both Google Groups (comp.lang.forth) and Yahoo Groups. >Since I already have google accounts, chose comp.lang.forth. >Is there a difference? Preference? The real Win32Forth gurus lurk at Yahoo, for some reason. >> Please do not post using mime. >...? I'm using Google Groups web interface... is this a setting >I should disable? I see you're learning fast. Welcome! -marcel
[toc] | [prev] | [next] | [standalone]
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-01-20 03:17 -0800 |
| Message-ID | <87fc604c-00b7-481e-b65c-7d2e2f126ebe@googlegroups.com> |
| In reply to | #18922 |
Sorry -- typos in the posted code. Simplified and corrected below. : hi 40 \ style constant: MB_ICONINFORMATION z" Hello World!" rel>abs ( -- str_msg ) z" Title" rel>abs ( -- str_title ) NULL \ handle (independent) call MessageBoxA ( n ptr ptr h -- ret ) ;
[toc] | [prev] | [next] | [standalone]
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-01-20 06:15 -0800 |
| Message-ID | <94672126-2c3d-4b79-a624-606885e5f12a@googlegroups.com> |
| In reply to | #18922 |
Aha! Brilliant! It was the $40 for hex -- doh! For future reference, here's the final working code (with stackdiagram). Thanks Marcel (and any other stylistic suggestions most welcomed!) ;) \ Simple Example extending Forth with Win32 API : hi ( a b c d -- ) \ displays a message box $40 \ style_ID (note: hex!) MB_ICONINFORMATION z" From Forth (win32forth)" rel>abs \ title string z" Hello World!" rel>abs \ message string NULL \ no parent window call MessageBoxA ( style title msg handle -- r ) \ return value drop ; Got the SharedMemory working as well now, from Ruby as well as C. Looking forward to experimenting with Forth as a rapid algorithm development environment... Cheers!
[toc] | [prev] | [next] | [standalone]
| From | Alex McDonald <blog@rivadpm.com> |
|---|---|
| Date | 2013-01-20 11:31 -0800 |
| Message-ID | <086e43dd-4003-4136-a220-e5a4f35155bb@f25g2000vby.googlegroups.com> |
| In reply to | #18935 |
On Jan 20, 2:15 pm, AKE <assadebrahim2...@gmail.com> wrote: > Aha! Brilliant! It was the $40 for hex -- doh! > > For future reference, here's the final working code (with stackdiagram). > > Thanks Marcel (and any other stylistic suggestions most welcomed!) ;) > > \ Simple Example extending Forth with Win32 API > : hi ( a b c d -- ) \ displays a message box > $40 \ style_ID (note: hex!) MB_ICONINFORMATION > z" From Forth (win32forth)" rel>abs \ title string > z" Hello World!" rel>abs \ message string > NULL \ no parent window > call MessageBoxA ( style title msg handle -- r ) \ return value > drop > ; > > Got the SharedMemory working as well now, from Ruby as well as C. > > Looking forward to experimenting with Forth as a rapid algorithm development environment... > > Cheers! You should be able to replace $40 with MB_ICONINFORMATION, since Win32Forth comes with predefined Windows constants. Try constants mb_ for a list of the MB_ constants.
[toc] | [prev] | [next] | [standalone]
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-01-20 15:21 -0800 |
| Message-ID | <7c1cbec6-e53b-43b3-8537-b027054e3cda@googlegroups.com> |
| In reply to | #18942 |
Thanks Alex -- yes that works. Very convenient -- don't have to go digging around in gcc\include\*.h files. Cheers for that.
[toc] | [prev] | [next] | [standalone]
| From | Alex McDonald <blog@rivadpm.com> |
|---|---|
| Date | 2013-01-21 08:23 -0800 |
| Message-ID | <bfa0cc49-1626-49a3-8b65-d5f28cae3365@px4g2000pbc.googlegroups.com> |
| In reply to | #18946 |
On Jan 20, 11:21 pm, AKE <assadebrahim2...@gmail.com> wrote: > Thanks Alex -- yes that works. Very convenient -- don't have to go digging around in gcc\include\*.h files. > > Cheers for that. You can also drop the A in entry points that have an ANSI and widechar equivalent. CALL MessageBox tries for MessageBox; if that fails, and it will since there's no entry point by that name (they are MessageBoxW and MessageBoxA), it then looks for MessageBoxA automatically.
[toc] | [prev] | [next] | [standalone]
| From | albert@spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2013-01-21 18:25 +0000 |
| Message-ID | <50fd8819$0$586$e4fe514c@dreader34.news.xs4all.nl> |
| In reply to | #18962 |
In article <bfa0cc49-1626-49a3-8b65-d5f28cae3365@px4g2000pbc.googlegroups.com>, Alex McDonald <blog@rivadpm.com> wrote: >On Jan 20, 11:21 pm, AKE <assadebrahim2...@gmail.com> wrote: >> Thanks Alex -- yes that works. Very convenient -- don't have to go >digging around in gcc\include\*.h files. >> >> Cheers for that. > >You can also drop the A in entry points that have an ANSI and widechar >equivalent. CALL MessageBox tries for MessageBox; if that fails, and >it will since there's no entry point by that name (they are >MessageBoxW and MessageBoxA), it then looks for MessageBoxA >automatically. Interesting. That searching is that done by MS-Windows or by win32forth? Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | Alex McDonald <blog@rivadpm.com> |
|---|---|
| Date | 2013-01-21 11:51 -0800 |
| Message-ID | <e5018b72-6d60-4e68-9215-a52e34d58b3f@y8g2000vbb.googlegroups.com> |
| In reply to | #18969 |
On Jan 21, 6:25 pm, alb...@spenarnc.xs4all.nl (Albert van der Horst) wrote: > In article <bfa0cc49-1626-49a3-8b65-d5f28cae3...@px4g2000pbc.googlegroups.com>, > Alex McDonald <b...@rivadpm.com> wrote: > > >On Jan 20, 11:21 pm, AKE <assadebrahim2...@gmail.com> wrote: > >> Thanks Alex -- yes that works. Very convenient -- don't have to go > >digging around in gcc\include\*.h files. > > >> Cheers for that. > > >You can also drop the A in entry points that have an ANSI and widechar > >equivalent. CALL MessageBox tries for MessageBox; if that fails, and > >it will since there's no entry point by that name (they are > >MessageBoxW and MessageBoxA), it then looks for MessageBoxA > >automatically. > > Interesting. That searching is that done by MS-Windows or by win32forth? By Win32Forth. All versions support the feature. > > Groetjes Albert > -- > Albert van der Horst, UTRECHT,THE NETHERLANDS > Economic growth -- being exponential -- ultimately falters. > albert@spe&ar&c.xs4all.nl &=nhttp://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web