.data
MsgBoxText db "Win32 Assembly is Great!",0
.DATA? ; Uninitialized data
CommandLine LPSTR ?
szSmtpServer LPSTR ?

.code
start:

invoke GetCommandLine
mov CommandLine,eax
invoke CommandLineToArgvW,CommandLine,0
mov szSmtpServer,eax
invoke MessageBox, NULL, addr MsgBoxText, szSmtpServer, MB_OK
...
...

this code can be compiled,but wrong when it be run.
Posted on 2003-01-01 09:38:22 by unest
Is szSmtpServer null terminated? (I don't know how CommandLineToArgvW works but maybe it doesn't null terminate the string)

shouldn't this thread be in the main section?

Just saw this on MSDN:
Besided from that CommandLineToArgvW is unicode I noticed thois at the return value section:

Return Values
If the function succeeds, the return value is a non-NULL pointer to the constructed argument list, which is an array of Unicode strings.
Posted on 2003-01-01 09:43:14 by scientica

Is szSmtpServer null terminated? (I don't know how CommandLineToArgvW works but maybe it doesn't null terminate the string)

shouldn't this thread be in the main section?



this code failed always with "invoke CommandLineToArgvW,CommandLine,0",but i don't what's wrong?or there are any different between LPTSTR and LPWSTR?


in MSDN:
LPWSTR CommandLineToArgvW(
LPCWSTR lpCmdLine, // pointer to a command-line string
int *pNumArgs // pointer to a variable that receives the
// argument count
);
Posted on 2003-01-01 09:57:24 by unest
IIRC unicode uses 1 _word_ per one character while ANSI uses 1 _byte_ per character.
Posted on 2003-01-01 10:04:50 by scientica
<<<thread moved to Main>>>
Posted on 2003-01-01 14:49:43 by Scronty

.data
MsgBoxText db "Win32 Assembly is Great!",0
.DATA? ; Uninitialized data
CommandLine LPSTR ?
szSmtpServer LPSTR ?

.code
start:

invoke GetCommandLine
mov CommandLine,eax
invoke CommandLineToArgvW,CommandLine,0
mov szSmtpServer,eax
invoke MessageBox, NULL, addr MsgBoxText, szSmtpServer, MB_OK
The second argument pNumArgs is where the number of pointers in the array will be stored. There is no mention of using NULL to ignore it. You need to add it...

.data
NumArgs dd 0

.code
invoke CommandLineToArgvW,CommandLine,addr NumArgs

CommandLine does indeed terminate with 0. However, a Unicode string must end with a WORD sized 0 with WORD alignment. The ANSI version of CommandLine is not guaranteed to do this.

The type of LPTSTR is a pointer to TSTR, and TSTR depends on whether you've selected ANSI or Unicode as the default character set. I believe the include files of MASM32 choose the ANSI defaults (which means TSTR should be interpreted as STR, not WSTR). This means your string constants can be defined by DB (as in your MsgBoxText), and that it will also work in Win9x.
Posted on 2003-01-02 16:39:29 by tenkey