News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

possessive case in a line of text

Started by shankle, July 26, 2013, 06:55:07 AM

Previous topic - Next topic

shankle

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

it may be that LOCALE_NAME_SYSTEM_DEFAULT and/or DATE_LONGDATE
are not defined in windows.inc

shankle

That is probably it. But I can't get around in the GoAsm headers very easily.



dedndave

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

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

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

dedndave

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

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

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

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

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.

dedndave

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

#27
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

wjr

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.

shankle

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.