Author Topic: MasmBasic  (Read 143753 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #60 on: April 05, 2013, 05:53:12 AM »
Waiting for your sample code showing that "ODBC is better", Yves

japheth

  • Guest
Re: MasmBasic - a fast and easy-to-use library
« Reply #61 on: April 05, 2013, 06:48:44 AM »
Waiting for your sample code showing that "ODBC is better", Yves

I cannot see why he needs to provide "sample code" - that's an additional requirement imposed by you, troll!  :icon_mrgreen:

Actually, it is sufficient if a plausible reason is supplied that makes obvious - more or less -  that ODBC is at least in one aspect better than DDE.

One possible reason that comes into my mind is that DDE requires a window for communication, while ODBC does NOT requires this.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #62 on: April 05, 2013, 07:31:39 AM »
One possible reason that comes into my mind is that DDE requires a window for communication, while ODBC does NOT requires this.

Thanks for this clarification, Andreas. I wonder, though, why the attached executable works - must be an invisible window then  ::)

Source is in \Masm32\RichMasm\Res\Masm2Excel.asc, the Excel sheet at \Masm32\RichMasm\Res\LifeExOECD.xls ;-)

Still waiting for demo code (or at least: arguments) why ODBC is better than DDE for grabbing data from an Excel sheet ;-)

EDIT: To complete the DDE interface, I added four new macros, ddeConnect, ddeDisconnect, ddeCommand and ddeRequest$(). This snippet shows the Firefox URL currently loaded, and if the user presses y, it opens a new page (code for MSIE attached):

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  ddeConnect "Firefox|WWW_GetWindowInfo"
  .if !Zero?
        PrintLine "Current URL= ", ddeRequest$("URL")
        ddeDisconnect
        Inkey "Open a new page (y)?"
        .if eax=="y"
                ddeConnect "Firefox|WWW_OpenURL"
                .if !Zero?
                        ddeCommand "http://masm32.com/board/index.php?action=unread"
                        ddeDisconnect
                .endif
        .endif
  .endif
  Inkey CrLf$, "bye"
  Exit
end start
« Last Edit: April 05, 2013, 10:00:08 AM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
MasmBasic bug fix
« Reply #63 on: April 05, 2013, 06:20:58 PM »
Bugfix concerning \Masm32\RichMasm\Res\Masm2Excel.asc, line 51:

Wrong:
                mov ecx, Instr_(esi, "[Book")                ; this might fail for a non-English Excel version
                .if ecx
                        .if Instr_(ecx, esi, Tb$)
                                xlsConnect Mid$(esi, ecx, edx-1)          ; connect to the new sheet
                        Let TopBot$=String$(9, Cat$("xxxxxxxxx"+Tb$))+"x"
                        xlsWrite "R2C3:R2C14", TopBot$

Right:
                mov ecx, Instr_(esi, "[Book")                ; this might fail for a non-English Excel version
                .if ecx
                        .if Instr_(ecx, esi, Tb$)
                                xlsConnect Mid$(esi, ecx, edx-ecx)          ; connect to the new sheet
                        Let TopBot$=String$(9, Cat$("xxxxxxxxx"+Tb$))+"x"
                        xlsWrite "R2C3:R2C14", TopBot$

Excel 2003 did not complain about being connected to [Book1]Sheet1 whatever, but Excel 2010 didn't like it  :biggrin:

Updated library here, as always.

japheth

  • Guest
Re: MasmBasic - a fast and easy-to-use library
« Reply #64 on: April 05, 2013, 06:26:20 PM »
Thanks for this clarification, Andreas. I wonder, though, why the attached executable works - must be an invisible window then  ::)

Yes, I guess that's true. Sorry, can't really run your sample because I threw away the MSO BS from this machine - and the one where it's still installed is now too noisy for my taste.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
DDE and Excel 2010 Starter Edition on Win7-64
« Reply #65 on: April 06, 2013, 08:49:51 PM »
The DDE demo in \Masm32\RichMasm\Res\Masm2Excel.asc works fine with DDE and Excel 2010 Starter Edition on Italian Win7-64. Note that the "starter" editions do not run any macros... but DDE works just fine. Probably some big corporations running legacy software had a chat with the M$ marketing department. Won't go into detail here because it would violate the forum rules  ;-)

                xlsCommand "[new(1)]"                          ; let Excel create a new workbook (works fine on non-English Excel versions!)
                Let esi=xlsSysRead$("Topics")        ; we must find the sheet
                mov ecx, Instr_(esi, "[Book")                ; this might fail for a non-English Excel version
                .if !ecx
                        mov ecx, Instr_(esi, "[Cartel")                ; let's try Italian - OK on Win7-64, Excel Starter 2010 (does not support macros!!)
                .endif
                .if ecx
                        .if Instr_(ecx, esi, Tb$)
                                xlsConnect Mid$(esi, ecx, edx-ecx)          ; connect to the new sheet

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #66 on: April 15, 2013, 08:41:19 AM »
Update 15 April (download from post #1):
- fixed a bug in Replace$()
- Clip$() had a 160k limit, now the limit is available memory
- Exp10, Exp2, ExpE and ExpXY implemented (special thanks to qWord :t)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #67 on: April 19, 2013, 06:01:01 AM »
Update 18 April (download from post #1):

- fixed a bug in StringToArray (the string to numerical array variant pushed one dword too much; the string to string array variant was OK)

- Pelles C "Hello World" example added (see New Masm source in the RichMasm editor)

- SetPoly3 MyArray(ecx) is now possible, i.e. take 3 xy pairs starting with element ecx (where ecx = 0, 2, 4...)

- Str$() accepts now single quotes (rarely needed, but I had a problem with DDE...):
                        mov row, 3
                        xlsCommand Str$('[select("R%iC5")]', row)                ; select("R3C5")

Finally, the handling of resource strings was improved, so that you can use two of them in MsgBoxes, as shown below for Unicode (same for the Ansi version):

include \masm32\MasmBasic\MasmBasic.inc
        Init
        wMsgBox 0, wRes$(2), wRes$(3), MB_OK
        Exit
end start

Rsrc
STRINGTABLE                ; RichMasm creates the rc file "on the fly"; edit the strings, then press F6 to assemble, link & run
BEGIN
  2,        "Нажмите на эту кнопку"        ; "Click on this button" in Russian
  3,        "Добро пожаловать"        ; "Welcome" in Russian
END
Rsrc

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: MasmBasic - a fast and easy-to-use library
« Reply #68 on: April 19, 2013, 06:46:52 AM »
You're a hard working man, Jochen.  :t Thank you for the update.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
PickFont
« Reply #69 on: May 06, 2013, 08:43:25 PM »
Thanks, Gunther ;-)

In the meantime, I had to fix a little bug: CL$() and wCL$() choked after arg #126. Now the number of arguments from the commandline is apparently limited by Windows; for example, under Win7-32 you can pass up to 32767 bytes via CreateProcess aka Launch(). Little test app attached.

I seized the occasion to add one more macro:

        PickFont addr hFont        ; use the font dialog to change the font whose handle is in hFont
        PickFont addr hFont, hEdit        ; apply to edit control (if user didn't cancel)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
BUG warning
« Reply #70 on: May 08, 2013, 06:11:14 PM »
In the meantime, I had to fix a little bug: CL$()...

And I introduced a fresh one on that occasion: CL$() with no args (i.e. "return the complete commandline") crashed. Concerns only version 6 May and is now fixed with version 8 May attached on top of this thread. Apologies :redface:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
Inter-Process communication with shared segments
« Reply #71 on: July 15, 2013, 06:18:43 PM »
It is possible to share data between two applications using the same DLL. In Win-16, that was the default, in Win-32 you need to declare a shared data segment (more at MSDN).

Strangely enough, it is even possible to have a joint memory area between two instances of an application:

include \masm32\MasmBasic\MasmBasic.inc        ; download
MyShared SEGMENT read write shared "BSS"
TheCount        dd ?
MyShared ends

        Init
        inc TheCount
        .if TheCount<=2
                Delay 500        ; if you see "1" on screen more than once, press Ctrl C
                Launch CL$(0)        ; launch another instance
        .endif
        Inkey Str$("n=%i\n", TheCount)
        Exit
end start

Output:
1
2
3

(hit any key three times to exit - there are three inkey statements)

Sharing segments as shown above works for JWasm and Masm 8.0 and higher. For Masm 6.15, there is a workaround as shown below, but it needs the linker option...
/SECTION:.bss,rws
... which fails miserably with POLINK (warning: /SECTION:.bss ignored; section is missing)

.data?
TheCount        dd ?


Credits go to Japheth and qWord

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MasmBasic - a fast and easy-to-use library
« Reply #72 on: July 15, 2013, 09:03:08 PM »
JJ,

I have seen IPC done this way but its rather clunky along side a memory mapped file and conventional messaging. The memory mapped file provides the shared memory area of more or less any size you like while the messaging using the HWND_BROADCAST identifier can be used to signal when data is available to any other app that can access the shared memory.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • Assembler is fun ;-)
    • MasmBasic
Re: Inter-Process communication with shared segments
« Reply #73 on: July 16, 2013, 03:43:58 AM »
Hutch,

I wouldn't call it clunky, it's really as simple as declaring myvar dd 123 in the .data section. Memory-mapped files are great for many purposes, sure.

But I have to admit that I don't see many uses for shared segments. As a proof of concept, I attach a little app that launches itself three times, declaring instance 0 as "server" and 1+2 as "clients". The common segment has an array where each instance stores its window handle, so no need for broadcasting:
MyShared SEGMENT read write shared "BSS"
MyCount   dd ?
hWinByInstance   dd 20 dup(?)
MyShared ends


The server can send a WM_COPYDATA message, the clients can handle them. Instead of that message, shared memory could be used to copy strings from server to client. IIRC, WM_COPYDATA eats around 4,000 cycles, which is quite a lot. Mem to mem should be faster...

On startup, MyCount is increased. Each instance knows its identity, and uses it e.g. to decide the x position on the screen, and whether to add pushbuttons or not.

Antariy

  • Member
  • ****
  • Posts: 541
Re: MasmBasic - a fast and easy-to-use library
« Reply #74 on: July 16, 2013, 07:07:19 PM »
Hi Jochen :t

Yes, I can confirm that this way of IPC in suitable cases is the best possible, just unbeatable: it's simple, reliable and fastest.

As one more proof of the concept: RAM Clear working in Advanced Mode - when it is unlimited with the size of memory it may free - working in that way. It launch "subsystems" - "clients" in your terminology here - and all interaction between server-controller-interface-father and client-subsystem-child is going via shared section of the same EXE.

RAM Clear has multiprocess, multithreaded concept, and in the extents it was designed for, special shared section does its job for IPC best of any other method.

But one needs to remember that with such an IPC way the designed controlling system should be properly designed for preemptiveness and reenterantness - i.e., multithreading (here this is equal to multiprocessing) there is no serialization like in message pump of the target-window process, like if "messages-way" IPC is using. I.e., all working programs can change data in the shared section just simultaneously, and there should be a mechanism to protect "atomical values" from changing simultaneously.

On the alpha-stage RAM Clear there were a fullscale tests with 96 working subsystems (96 child processes launched by a father process). So, this concept is really good one - when it is suitable :t