The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: purpleendurer on November 01, 2009, 09:36:17 AM

Title: Question about enuming schedule job (Unicode string)
Post by: purpleendurer on November 01, 2009, 09:36:17 AM
First, I create a Schedule Job with AT command.

at 18:35 "xcopy.exe"


Then, Run my program to display the JobID & Command of the Schedule Job.

The JobID "00000001" is right, but the Command is not  "xcopy.exe"

the Command  is a  Pointer to a Unicode string that contains the name of the command, batch program, or binary file to execute.

%S is in vain?

I felt at a loss.



Here is my code:
Quote

.586
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE

INCLUDE \masm32\include\windows.inc

INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib

INCLUDE \masm32\include\Netapi32.inc
INCLUDELIB \masm32\lib\Netapi32.lib

INCLUDE \masm32\include\user32.inc
INCLUDELIB \masm32\lib\user32.lib


.DATA?

dwLeftBeforeCall dword ?
dwRead dword ?
dwJobCount dword ?
pBuf dword ?    ;ponter to AT_ENUM
Buf512 byte 512 dup(?)


.DATA

szCation db "ScheduleJob", 0
szFmt db "%08lu %S", 0


.CODE

start:

    mov dwLeftBeforeCall, 0

    invoke NetScheduleJobEnum, NULL, addr pBuf, MAX_PREFERRED_LENGTH, addr dwRead\
                        , addr dwJobCount, addr dwLeftBeforeCall

    mov edi, pBuf
    .while (dwRead > 0)
        push edi

        lea eax, (AT_ENUM ptr [edi]).Command

        invoke wsprintf, addr Buf512, addr szFmt, (AT_ENUM ptr [edi]).JobId, eax

        invoke MessageBox, NULL, addr Buf512, addr szCation, NULL

        pop edi
        add edi, sizeof AT_ENUM
        dec dwRead
    .endw

    .IF (pBuf != NULL)
            invoke NetApiBufferFree, pBuf
    .ENDIF

    invoke ExitProcess, 0
END start


Title: Re: Question about enuming schedule job (Unicode string)
Post by: purpleendurer on November 05, 2009, 03:24:25 PM
I had worked it out.


The define of AT_ENUM in windows.inc of MASM32 is incorrect.

The right is:

_AT_ENUM struct
    JobId       dd      ?
    JobTime     dd      ?
    DaysOfMonth dd      ?
    DaysOfWeek  UCHAR   ?
    Flags       UCHAR   ?
    align1      db      ?
    align2      db      ?
    Command     dd      ?
_AT_ENUM ends


I modified the code:

.586
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE

INCLUDE \masm32\include\windows.inc

INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib

INCLUDE \masm32\include\Netapi32.inc
INCLUDELIB \masm32\lib\Netapi32.lib

INCLUDE \masm32\include\user32.inc
INCLUDELIB \masm32\lib\user32.lib


_AT_ENUM struct
    JobId       dd      ?
    JobTime     dd      ?
    DaysOfMonth dd      ?
    DaysOfWeek  UCHAR   ?
    Flags       UCHAR   ?
    align1      db      ?
    align2      db      ?
    Command     dd      ?
_AT_ENUM ends


.DATA?

dwLeftBeforeCall dword ?
dwRead dword ?
dwJobCount dword ?
pBuf dword ?    ;ponter to AT_ENUM
Buf512 byte 512 dup(?)


.DATA

szCation db "ScheduleJob", 0
szFmt db "%08lu %S", 0


.CODE

start:

    mov dwLeftBeforeCall, 0

    invoke NetScheduleJobEnum, NULL, addr pBuf, MAX_PREFERRED_LENGTH, addr dwRead\
                        , addr dwJobCount, addr dwLeftBeforeCall

    mov edi, pBuf
    .while (dwRead > 0)
        push edi


        invoke wsprintf, addr Buf512, addr szFmt, (_AT_ENUM ptr [edi]).JobId, (_AT_ENUM ptr [edi]).Command

        invoke MessageBox, NULL, addr Buf512, addr szCation, NULL

        pop edi
        add edi, sizeof _AT_ENUM
        dec dwRead
    .endw

    .IF (pBuf != NULL)
            invoke NetApiBufferFree, pBuf
    .ENDIF

    invoke ExitProcess, 0
END start
Title: Re: Question about enuming schedule job (Unicode string)
Post by: six_L on November 05, 2009, 04:07:23 PM
see it http://msdn.microsoft.com/en-us/library/aa370247%28VS.85%29.aspx
Title: Re: Question about enuming schedule job (Unicode string)
Post by: ecube on November 05, 2009, 04:23:58 PM
yeah masm32 needs alot of updates on structures, we should have a thread for any people find incorrect so hutch can make the changes for future versions, infact I'll go start that.
Title: Re: Question about enuming schedule job (Unicode string)
Post by: Vortex on November 07, 2009, 09:12:28 AM
Hi purpleendurer,

The structure alignment problem is a known issue. Here (http://www.masm32.com/board/index.php?topic=12353.0), you can find a scheduler API demo.