Author Topic: possessive case in a line of text  (Read 14928 times)

shankle

  • Member
  • ****
  • Posts: 835
Re: possessive case in a line of text
« Reply #15 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

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: possessive case in a line of text
« Reply #16 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

shankle

  • Member
  • ****
  • Posts: 835
Re: possessive case in a line of text
« Reply #17 on: August 18, 2013, 12:40:37 PM »
That is probably it. But I can't get around in the GoAsm headers very easily.



dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: possessive case in a line of text
« Reply #18 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

shankle

  • Member
  • ****
  • Posts: 835
Re: possessive case in a line of text
« Reply #19 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.....

Yuri

  • Member
  • **
  • Posts: 175
Re: possessive case in a line of text
« Reply #20 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):
Code: [Select]
#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.
Code: [Select]
#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

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: possessive case in a line of text
« Reply #21 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

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

shankle

  • Member
  • ****
  • Posts: 835
Re: possessive case in a line of text
« Reply #22 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.

Yuri

  • Member
  • **
  • Posts: 175
Re: possessive case in a line of text
« Reply #23 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.

shankle

  • Member
  • ****
  • Posts: 835
Re: possessive case in a line of text
« Reply #24 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

Yuri

  • Member
  • **
  • Posts: 175
Re: possessive case in a line of text
« Reply #25 on: August 19, 2013, 03:26:35 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.

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: possessive case in a line of text
« Reply #26 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

shankle

  • Member
  • ****
  • Posts: 835
Re: possessive case in a line of text
« Reply #27 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
« Last Edit: August 20, 2013, 12:28:19 PM by shankle »

wjr

  • Member
  • **
  • Posts: 209
    • WJR's website
Re: possessive case in a line of text
« Reply #28 on: August 20, 2013, 07:01:11 AM »
You may want to save the pointer to the CommandLine:

Code: [Select]
invoke GetCommandLine
mov    [CommandLine],rax

Instead of L"datein" use:

Code: [Select]
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.

shankle

  • Member
  • ****
  • Posts: 835
Re: possessive case in a line of text
« Reply #29 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.