flat assembler
Message board for the users of flat assembler.

Index > Windows > Volume Serial Number

Author
Thread Post new topic Reply to topic
Force



Joined: 12 Jun 2012
Posts: 29
Force
Hello

I wrote this code in Masm32 before... I m trying to translate it to Fasm

but there is problem for wsprintf

Can anybody help me ...how to use wsprintf in this code ?



Code:
INCLUDE "C:\Fasm\include\win32ax.inc"

.data

 AppName db "VolumeInformation of C:\",0
PathName db "C:\",0
VolumeName db 16 dup(?)
NameSize dd 50
volumeSerial dd 0
VolumeSize dd 50
VolSer db 50 dup(?)
DiskDataHex            DB "%lX",NULL
Buffer db 100 dup(?)
drvName db "Drive Name     : C:\ ",0
srNum db "Serial Number :   ",0
NL db 13,10  

    
.code            

WIN_START:
invoke GetVolumeInformation,addr PathName,addr VolumeName,addr NameSize,addr volumeSerial,addr VolumeSize,NULL,NULL,NULL
INVOKE wsprintf,ADDR VolSer,ADDR DiskDataHex,volumeSerial
invoke lstrcat,addr Buffer,addr drvName
invoke lstrcat,addr Buffer,addr VolumeName
invoke lstrcat,addr Buffer,addr NL
invoke lstrcat,addr Buffer,addr srNum
invoke lstrcat,addr Buffer,addr VolSer

invoke MessageBox,NULL,addr Buffer,addr AppName,0
    
invoke  ExitProcess, 0

.end WIN_START 

    
Post 22 Sep 2012, 21:21
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Very simple to fix error: INVOKE and ADDR must be written all lowercase. This is because these are not assembler nor preprocessor directives but a macro and a symbol respectively and since fasm is case-sensitive you get the error.
Post 22 Sep 2012, 21:56
View user's profile Send private message Reply with quote
Force



Joined: 12 Jun 2012
Posts: 29
Force
yes I solved problem by using " Cinvoke " its different function for me

at least i learned how to use it Smile


It is working Code :

Code:
INCLUDE "C:\Fasm\include\win32ax.inc"

.data

 AppName db "VolumeInformation of C:\",0
PathName db "C:\",0
VolumeName db 16 dup(?)
NameSize dd 50
volumeSerial dd 0
VolumeSize dd 50
VolSer db 50 dup(?)
DiskDataHex                DB "%lX",NULL
Buffer db 100 dup(?)
drvName db "Drive Name     : C:\ ",0
srNum db "Serial Number :   ",0
NL db 13,10  

    
.code            

WIN_START:
invoke GetVolumeInformation,addr PathName,addr VolumeName,addr NameSize,addr volumeSerial,addr VolumeSize,NULL,NULL,NULL
cinvoke wsprintf, VolSer,DiskDataHex,[volumeSerial] 
invoke lstrcat,addr Buffer,addr drvName
invoke lstrcat,addr Buffer,addr VolumeName
invoke lstrcat,addr Buffer,addr NL
invoke lstrcat,addr Buffer,addr srNum
invoke lstrcat,addr Buffer,addr VolSer

invoke MessageBox,NULL,addr Buffer,addr AppName,0
    
invoke  ExitProcess, 0

.end WIN_START 
    
Post 22 Sep 2012, 23:11
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

yes I solved problem by using " Cinvoke " its different function for me
Oh yes, sorry, in addition to the casing problem, you need to use cinvoke for variadic functions (or _cdelc functions).

Here is a simplified version of your code:
Code:
INCLUDE "C:\Fasm\include\win32axp.inc"

NL equ 13, 10
NAME_SIZE equ (MAX_PATH + 1)
.data
AppName  db "VolumeInformation of C:\",0
PathName db "D:\",0

fmt      db "Drive Name    : C:\ %s", NL,\
            "Serial Number :   %lX", 0

VolumeName   rb NAME_SIZE
volumeSerial dd 0
Buffer       rb 256
    
.code            
; I'm not using addr because it is not needed when accessing global vars.
; Using addr causes an additional instruction (LEA) to be used.

WIN_START:
invoke GetVolumeInformation, PathName,\     ; _In_opt_   LPCTSTR lpRootPathName
                             VolumeName,\   ; _Out_opt_  LPTSTR lpVolumeNameBuffer
                             NAME_SIZE,\    ; _In_       DWORD nVolumeNameSize
                             volumeSerial,\ ; _Out_opt_  LPDWORD lpVolumeSerialNumber
                             NULL,\         ; _Out_opt_  LPDWORD lpMaximumComponentLength
                             NULL,\         ; _Out_opt_  LPDWORD lpFileSystemFlags
                             NULL,\         ; _Out_opt_  LPTSTR lpFileSystemNameBuffer
                             0              ; _In_       DWORD nFileSystemNameSize

cinvoke wsprintf, Buffer, fmt, VolumeName, [volumeSerial]

invoke MessageBox, NULL, Buffer, AppName, 0
    
invoke  ExitProcess, 0

.end WIN_START    
Note that you also were passing nVolumeNameSize the wrong way, in your original code you should have used [NameSize], as it requires the content, not the address of it.
Post 23 Sep 2012, 00:02
View user's profile Send private message Reply with quote
Force



Joined: 12 Jun 2012
Posts: 29
Force
Thanks LocoDelAssemly for simplified code

i just started to learn fasm so i dunno fasm enough

in fact i m new in assembly

Force
Post 23 Sep 2012, 10:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.