The MASM Forum

Projects => Rarely Used Projects => GoAsm => Topic started by: shankle on July 26, 2013, 06:55:07 AM

Title: possessive case in a line of text
Post by: shankle on July 26, 2013, 06:55:07 AM
In a line of text a word such as "inversion''s" causes the 1st letter of the line of text
not to print. Ex: derived shows as erived. Where in the documentation is this explained?
I only count the 2 ticks as one. If I increase it by 1 that does not solve the problem.
Title: Re: possessive case in a line of text
Post by: Yuri on July 26, 2013, 03:06:50 PM
I was unable to reproduce this. Can you provide any code that shows the bug?
Title: Re: possessive case in a line of text
Post by: shankle on July 26, 2013, 08:44:13 PM
Thanks Yuri for responding.
Hope this helps to solve the problem.

Text line as coded.
T10    db   'derived. The 2nd INVERSION''S 1st note is G (5th note of the C scale). The 2nd  ',0

Code to execute the above line.
    invoke TextOut, [hdc],10,215,addr T10,79       

This is what displays on the screen.   
    erived. The 2nd INVERSION''S 1st note is G (5th note of the C scale). The 2nd
Title: Re: possessive case in a line of text
Post by: Yuri on July 27, 2013, 12:07:38 AM
Yes, now I can see the effect. As it follows from the examples in the manual, you can use single quotes within a string only if the string is in double quotes, and vice versa. Or you have to use character codes instead of literal quote characters. The character code for the single quote is 27h.

T10    db   'derived. The 2nd INVERSION',27h,'S 1st note is G (5th note of the C scale). The 2nd  ',0
Title: Re: possessive case in a line of text
Post by: shankle on July 27, 2013, 05:00:05 AM
Thank you Yuri.
That fixed it.
I guess the answer is in the GoAsm docs but where?
Title: Re: possessive case in a line of text
Post by: Yuri on July 27, 2013, 12:33:01 PM
Basic GoAsm elements -> Data declaration -> Declaring strings + Declaring more than one string per line
Title: Re: possessive case in a line of text
Post by: wjr on July 30, 2013, 11:21:28 AM
At first glance, that looked like a double quote in the middle, in which case it should have worked (although you wanted the double and single quotes swapped). What you had was two single quotes there, and for that GoAsm probably should have given an error message instead of an error.

Your problem has been solved, but I shall still add this to the list of things to look into when I get a chance...
Title: Re: possessive case in a line of text
Post by: shankle on August 16, 2013, 12:59:31 PM
This is another example that I am having trouble with in GoAsm.
No error is given but the program stalls.
Neither datestring works.

datein             db   12 DUP (0)
datestring       db   "MM'-'dd'-'yyyy",0
datestring       db   "MM-dd-yyyy",0

    invoke GetDateFormat, NULL, 0, NULL, addr datestring, addr datein,12

Suggestions for where to read about it would be most appreciated.
Title: Re: possessive case in a line of text
Post by: wjr on August 16, 2013, 02:54:27 PM
The second datestring looks like the one that you want to use, and what you have shown should work. If it doesn't then the problem is elsewhere. One possibility, it looks like you are intending to use an ANSI string, so if you have defined the symbol UNICODE and/or used STRINGS UNICODE, that will throw things off (if so for both, use DUS instead of db for the strings so that they are UNICODE).
Title: Re: possessive case in a line of text
Post by: dedndave on August 16, 2013, 08:06:38 PM
give this a try, Jack

;###############################################################################################

        .XCREF
        .NoList
        INCLUDE    \Masm32\Include\Masm32rt.inc
        .List

;###############################################################################################

        .DATA

szTitle     db         'GetDateFormat',0
szFormat    db         'MM-dd-yyyy',0

;***********************************************************************************************

        .DATA?

stLocalTime SYSTEMTIME <>
szBuffer    db         12 dup(?)

;###############################################################################################

        .CODE

;***********************************************************************************************

_main   PROC

        INVOKE  GetLocalTime,offset stLocalTime
        INVOKE  GetDateFormat,LOCALE_USER_DEFAULT,NULL,offset stLocalTime,
                offset szFormat,offset szBuffer,sizeof szBuffer
        INVOKE  MessageBox,NULL,offset szBuffer,offset szTitle,MB_OK
        INVOKE  ExitProcess,0

_main   ENDP

;###############################################################################################

        END     _main


it's MASM syntax, but you can convert it   :P
Title: Re: possessive case in a line of text
Post by: shankle on August 16, 2013, 08:45:56 PM
Thanks guys for responding.
I commented out the "GetDataFormat" and the program worked fine.
So neither string I used worked.
I am not doing anything with Unicode.
Could it be a header problem with GoAsm??
I use this same code in Masm32 and it works there.
I read in the manual about strings and could find nothing that applies to my problem.
I have two other programs with the same problem  - "GetDateFormat"
Title: Re: possessive case in a line of text
Post by: wjr on August 17, 2013, 08:36:53 AM
The above, although just a small snippet, tested fine at this end with Donkey's headers. If the return value from GetDateFormat is non-zero and the string in datein is what you expected, then the problem is elsewhere in what you do with this date string...
Title: Re: possessive case in a line of text
Post by: shankle on August 17, 2013, 11:45:16 AM
I am running Windows 7. Microsoft says I should use GetDateFormatEx with that OS.
What is the header name that contains this API? I want to check to see if it is included in my
GoAsm headers.

Title: Re: possessive case in a line of text
Post by: Yuri on August 17, 2013, 01:10:19 PM
You don't need any special header. On my Windows 7, both GetDateFormat and GetDateFormatEx work as expected. Only windows.h is included.
Title: Re: possessive case in a line of text
Post by: shankle on August 17, 2013, 10:06:22 PM
Hi Yuri,
Would you kindly give an example as mine still does not work?
Title: Re: possessive case in a line of text
Post by: shankle on August 18, 2013, 11:28:24 AM
This is the error in GoAsm that I get from GetDateFormatEx.

datein    db   12 DUP (0)
LOCAL stm:SYSTEMTIME

    invoke GetDateFormatEx, LOCALE_NAME_SYSTEM_DEFAULT,DATE_LONGDATE,\
      addr stm,NULL,addr datein,12,NULL

line 1797 of assembler source file -
Inappropriate or missing operand to the numeric
LOCALE_NAME_SYSTEM_DEFAULT, DATE_LONGDATE, addr stm,
NULL, addr datein, 12, NULL
Title: Re: possessive case in a line of text
Post by: dedndave on August 18, 2013, 12:22:34 PM
it may be that LOCALE_NAME_SYSTEM_DEFAULT and/or DATE_LONGDATE
are not defined in windows.inc
Title: Re: possessive case in a line of text
Post by: shankle on August 18, 2013, 12:40:37 PM
That is probably it. But I can't get around in the GoAsm headers very easily.


Title: Re: possessive case in a line of text
Post by: dedndave on August 18, 2013, 12:49:15 PM
to make it easy, use NotePad

highlight the string LOCALE_NAME_SYSTEM_DEFAULT with the mouse cursor
right-click - Copy
open windows.inc with NotePad
Edit menu - Find
in the Find edit box, right-click - Paste
click on the Find Next button
Title: Re: possessive case in a line of text
Post by: shankle on August 18, 2013, 01:39:13 PM
To the best of my knowledge there is no "windows inc" in GoAsm.
I think it is called "Windows.h". Anyway I searched there for "getdateformat and
Getdateformatex" and neither were there.

Maybe my headers are not up to date.....
Title: Re: possessive case in a line of text
Post by: Yuri on August 18, 2013, 03:48:51 PM
DATE_LONGDATE is already defined, the other one is not. You can add these lines to winnls.h (just before the last #endif in the file):

#define LOCALE_NAME_USER_DEFAULT            NULL
#define LOCALE_NAME_INVARIANT               L""
#define LOCALE_NAME_SYSTEM_DEFAULT          L"!x-sys-default-locale"

Unfortunately there is a bug in GoAsm due to which the use of LOCALE_NAME_SYSTEM_DEFAULT will not work for the x64 build of the program. I will report the bug in another thread.

So I used LOCALE_NAME_USER_DEFAULT for the example.

#define LINKFILES
#include <windows.h>


DATA SECTION

datein  DW 32 DUP 0


CODE SECTION

Start:
    invoke GetDateFormatEx, LOCALE_NAME_USER_DEFAULT, DATE_LONGDATE, NULL, NULL, addr datein, sizeof datein / 2, 0
    invoke MessageBoxW, NULL, addr datein, L"Test", MB_OK
    ret
Title: Re: possessive case in a line of text
Post by: dedndave on August 18, 2013, 07:43:04 PM
hiya Jack
i didn't know that GoAsm used ".h" files - a very nice feature   :t
and, the constants are probably where they belong, too
in the masm32 package, nearly all constants have been moved into windows.inc/winextra.inc
that probably doesn't apply for the GoAsm headers

the function prototypes are not defined in windows.h
the functions themselves are in kernel32.dll
but, the original prototypes and constants are in Datetimeapi.h
so, in the GoAsm headers, they are likely to be in either Datetimeapi.h or Kernel32.h

if you open the MSDN webpage for GetDateFormat...
http://msdn.microsoft.com/en-us/library/windows/desktop/dd318086%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/dd318086%28v=vs.85%29.aspx)

then, scroll down a bit, there is a section that tells you where it is prototyped
most of the date/time functions are in kernel32.dll, and are prototyped in Datetimeapi.h
Title: Re: possessive case in a line of text
Post by: shankle on August 18, 2013, 10:04:48 PM
I added the lines to "winnls.h"
Found where GetDateFormat is defined. Unable to find where GetDateFormatEx is defined.

Changed datein  to dw 32 DUP 0
Used your example of GetDateFormatEx.
My program still stalls at GetDateFormatEx.
Title: Re: possessive case in a line of text
Post by: Yuri on August 19, 2013, 12:15:10 AM
What happens if you assemble my example as a standalone program? Does it work? What do you mean by "stalls"?

GoAsm doesn't need any function definition for GetDateFormatEx.
Title: Re: possessive case in a line of text
Post by: shankle on August 19, 2013, 02:25:41 AM
Here is a test program of GetDateFormatEx.
It proves that this API works but the output is obviously wrong.
Why this API causes problems in my other program remains a mystery.

;-----------------------------------------------
;   btestprodg.asm   - GoAsm 64-bit
;   8-18-2013 using Windows 7 pro 64-bit   

#define LINKFILES
#define codejps
#define WIN64
#INCLUDE windows.h

.const
#ifndef LPSTR
  #if !x64
   #define LPSTR dd
  #else
   #define LPSTR dq
  #endif     
#endif 
CommandLine LPSTR  ?

DATA SECTION
colorbk          dq       00ff0000h      ; blue
hBrush           dq       0
hdc              dq       0
hInstance        dq       0   

datein           dw   32 DUP (0)
msg4             db   'in message loop',0
msg5             db   'error in return value',0
AppName          db   "Test of GetDateFormatEx",0
szDisplayName    db   "Test of GetDayeFormatEx",0         
eswh             db   0

; test begin code
testmsg   db  'testing GetDateFormatEx',0
; test end code

.code
start:
   invoke GetModuleHandleA, NULL
   mov    Q[hInstance],rax
   invoke GetCommandLine
   invoke WinMain, [hInstance],NULL,[CommandLine],SW_SHOWDEFAULT
   invoke ExitProcess,rax   
   
WinMain:
    FRAME hInst,hPrevInst,CmdLine,CmdShow
   LOCAL wc:WNDCLASSEXA,msg:MSG,hWnd,RR:RECT     
   mov   D[wc.cbSize],SIZEOF WNDCLASSEXA
   mov   D[wc.style],CS_BYTEALIGNWINDOW | CS_HREDRAW | CS_VREDRAW
   mov   rax,offset WndProc   
   mov   Q[wc.lpfnWndProc],rax   
   mov   D[wc.cbClsExtra],NULL
   mov   D[wc.cbWndExtra],NULL
   push  [hInst]
   pop   [wc.hInstance]
   invoke LoadIcon,NULL,IDI_APPLICATION
   mov   Q[wc.hIcon], rax   
    invoke LoadCursor,NULL,IDC_ARROW
   mov   Q[wc.hCursor],rax
   invoke CreateSolidBrush,[colorbk]     
    mov   Q[hBrush],rax
   mov   Q[wc.hbrBackground],rax
   mov   Q[wc.lpszMenuName],NULL
   mov   Q[wc.lpszClassName],offset szDisplayName
   mov   Q[wc.hIconSm],0
   
    invoke RegisterClassEx, addr wc
    invoke SystemParametersInfo, SPI_GETWORKAREA, 0, addr RR, 0       
    INVOKE CreateWindowEx, NULL,addr szDisplayName,addr AppName,\
    WS_OVERLAPPEDWINDOW,[RR.left],[RR.top],[RR.right],\
         [RR.bottom],NULL,NULL,[hInst],NULL           
    mov  [hWnd],rax
 
    INVOKE ShowWindow,[hWnd], SW_SHOWNORMAL
    INVOKE UpdateWindow, [hWnd]

; ===============================================================
;  Loop until PostQuitMessage is sent
; ===============================================================
L1:
    INVOKE GetMessageA,addr msg,0,0,0
    test eax,eax       
    jz >L3             
    cmp eax,-1
    je >L2
    INVOKE TranslateMessage,addr msg
    INVOKE DispatchMessageA,addr msg
    jmp L1             
L2:   
    invoke MessageBox, [hWnd], addr msg4, addr msg5, MB_OK ;true
L3:                     
    ret
ENDF

WndProc:
    FRAME  hWnd,iMsg,wParam,lParam
    LOCAL ps:PAINTSTRUCT
         
.WM_PAINT         
    cmp D[iMsg],WM_PAINT
     jne >>.WM_DESTROY
    cmp B[eswh],1
     je >>.pqm     
    mov B[eswh],1 
    invoke BeginPaint, [hWnd],addr ps
    mov [hdc],rax             
    invoke GetDateFormatEx, LOCALE_NAME_USER_DEFAULT,DATE_LONGDATE,\
      NULL,NULL,addr datein,sizeof datein /2,NULL
    invoke MessageBox, NULL, addr datein, addr testmsg, MB_OK ;true       
    invoke EndPaint, [hWnd],addr ps
    ret             

.GetOut
.WM_DESTROY         
     cmp D[iMsg],WM_DESTROY
      jne >.default       
.pqm                          
    invoke PostQuitMessage,NULL
    jmp >>.END
.default         
    invoke DefWindowProc, [hWnd],[iMsg],[wParam],[lParam]
ret 
.END
    xor rax,rax   
    ret
ENDF
Title: Re: possessive case in a line of text
Post by: Yuri on August 19, 2013, 03:26:35 AM
Quote from: shankle on August 19, 2013, 02:25:41 AM
Here is a test program of GetDateFormatEx.
It proves that this API works but the output is obviously wrong.
GetDateFormatEx uses Unicode strings, so you need MessageBoxW to display its output correctly.
Title: Re: possessive case in a line of text
Post by: dedndave on August 19, 2013, 04:16:14 AM
that would certainly explain a lot of trouble   :P

i generally ignore MS warnings about older functions becoming useless because they are still supported for backward compatibility reasons
this one may be an exception
if you want to support both older and newer OS's, it may be best to get the windows version and write code both ways
Title: Re: possessive case in a line of text
Post by: shankle on August 20, 2013, 03:25:06 AM
Sample code above works and puts out a date to the MessageBox.
But if I make changes to it as I need in a production program it does not work.
I did make the changes to the "Winnls.h" as instructed.

;-----------------------------------------------
;   btestprog.asm   - GoAsm 64-bit
;   8-19-2013 using Windows 7 pro 64-bit   

#define LINKFILES
#define codejps
#define WIN64
#INCLUDE windows.h

.const
#ifndef LPSTR
  #if !x64
   #define LPSTR dd
  #else
   #define LPSTR dq
  #endif     
#endif 
CommandLine LPSTR  ?

DATA SECTION
colorbk          dq       00ff0000h      ; blue
hBrush           dq       0
hdc              dq       0
hInstance        dq       0   
hNFont           dq       0   
colortxt         dd       00ffffffh      ; white
datein           dw   32 DUP (0)
msg4             db   'in message loop',0
msg5             db   'error in return value',0
AppName          db   "Test of GetDateFormatEx",0
szDisplayName    db   "Test of GetDateFormatEx",0         
eswh             db   0
headng1          db   "Test Heading",0
szTimesNR        db   "Ariel",0

.code
start:
   invoke GetModuleHandleA, NULL
   mov    Q[hInstance],rax
   invoke GetCommandLine
   invoke WinMain, [hInstance],NULL,[CommandLine],SW_SHOWDEFAULT
   invoke ExitProcess,rax   
   
WinMain:
    FRAME hInst,hPrevInst,CmdLine,CmdShow
   LOCAL wc:WNDCLASSEXA,msg:MSG,hWnd,RR:RECT     
   mov   D[wc.cbSize],SIZEOF WNDCLASSEXA
   mov   D[wc.style],CS_BYTEALIGNWINDOW | CS_HREDRAW | CS_VREDRAW
   mov   rax,offset WndProc   
   mov   Q[wc.lpfnWndProc],rax   
   mov   D[wc.cbClsExtra],NULL
   mov   D[wc.cbWndExtra],NULL
   push  [hInst]
   pop   [wc.hInstance]
   invoke LoadIcon,NULL,IDI_APPLICATION
   mov   Q[wc.hIcon], rax   
    invoke LoadCursor,NULL,IDC_ARROW
   mov   Q[wc.hCursor],rax
   invoke CreateSolidBrush,[colorbk]     
    mov   Q[hBrush],rax
   mov   Q[wc.hbrBackground],rax
   mov   Q[wc.lpszMenuName],NULL
   mov   Q[wc.lpszClassName],offset szDisplayName
   mov   Q[wc.hIconSm],0   
    invoke RegisterClassEx, addr wc
    invoke SystemParametersInfo, SPI_GETWORKAREA, 0, addr RR, 0       
    INVOKE CreateWindowEx, NULL,addr szDisplayName,addr AppName,\
    WS_OVERLAPPEDWINDOW,[RR.left],[RR.top],[RR.right],\
         [RR.bottom],NULL,NULL,[hInst],NULL           
    mov  [hWnd],rax 
    INVOKE ShowWindow,[hWnd], SW_SHOWNORMAL
    INVOKE UpdateWindow, [hWnd]

L1:
    INVOKE GetMessageA,addr msg,0,0,0
    test eax,eax       
    jz >L3             
    cmp eax,-1
    je >L2
    INVOKE TranslateMessage,addr msg
    INVOKE DispatchMessageA,addr msg
    jmp L1             
L2:   
    invoke MessageBox, [hWnd], addr msg4, addr msg5, MB_OK ;true
L3:                     
    ret
ENDF

WndProc:
    FRAME  hWnd,iMsg,wParam,lParam
    LOCAL ps:PAINTSTRUCT
         
.WM_PAINT         
    cmp D[iMsg],WM_PAINT
     jne >>.WM_DESTROY
    cmp B[eswh],1
     je >>.pqm     
    mov B[eswh],1 
    invoke BeginPaint, [hWnd],addr ps
    mov [hdc],rax             
    invoke SetTextColor, [hdc],[colortxt]    ; text color white
    invoke SetMapMode, [hdc],MM_TEXT
    invoke SetBkMode, [hdc],TRANSPARENT
    invoke  CreateFont, 25,10,0,0,FW_DEMIBOLD,FALSE,FALSE,FALSE,\
           DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
           PROOF_QUALITY,FF_MODERN,addr szTimesNR
    mov   [hNFont],rax
    invoke  SelectObject, [hdc],[hNFont]
    invoke TextOut, [hdc],200,200,addr headng1,12
   
    invoke GetDateFormatEx, LOCALE_NAME_USER_DEFAULT,DATE_LONGDATE,\
      NULL,NULL,addr datein,sizeof datein /2,NULL
    invoke GetCommandLine
    mov [CommandLIne], rax
    invoke TextOutW, [hdc],800,30,addr datein,rax
;    invoke MessageBoxW, NULL, addr datein, L"testmsg", MB_OK ;true       
    invoke EndPaint, [hWnd],addr ps
    ret             

.GetOut
.WM_DESTROY         
     cmp D[iMsg],WM_DESTROY
      jne >.default       
.pqm                          
    invoke PostQuitMessage,NULL
    jmp >>.END
.default         
    invoke DefWindowProc, [hWnd],[iMsg],[wParam],[lParam]
ret 
.END
    xor rax,rax   
    ret
ENDF
Title: Re: possessive case in a line of text
Post by: wjr on August 20, 2013, 07:01:11 AM
You may want to save the pointer to the CommandLine:


invoke GetCommandLine
mov    [CommandLine],rax


Instead of L"datein" use:


invoke TextOutW, [hdc], 800, 30, ADDR datein, rax


where rax has the number of characters just returned from GetDateFormatEx. This should work, if it doesn't then I think you may be using GoAsm 0.58.0.0. Try version 0.58.0.2 which has fixes for some ADDR issues.
Title: Re: possessive case in a line of text
Post by: shankle on August 20, 2013, 12:30:56 PM
Thank you for responding WJR.
I made the changes you recommended as in the above example.
I was running GoAsm 58.0.1. As best as I can tell I am now running 58.0.2.

The above example still does not work.
Title: Re: possessive case in a line of text
Post by: Yuri on August 20, 2013, 01:51:04 PM
It works fine for me (with the changes).
Title: Re: possessive case in a line of text
Post by: shankle on August 20, 2013, 08:34:29 PM
Thank you all for your help.
The test program(btestprog) still does not work BUT the production program does.
So I am happy and will drop the problem with the test program.
Nothing is ever easy.....