flat assembler
Message board for the users of flat assembler.

Index > Windows > Building variables

Author
Thread Post new topic Reply to topic
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun 04 Dec 2013, 17:59
I check the name of a pendrive with GetVolumeInformation.
The information is stored in "lpVolumeNameBuffer".
ok.

If the pendrive is not the one I want to use for backups I give out a messagebox.

Something like...
invoke MessageBoxA,NULL,err_message,err_caption,MB_ICONWARNING+MB_OKCANCEL

;GetVolume Params
lpVolumeNameBuffer dd ?,0
etc.

err_caption db 'ERROR MSG',0
err_message db 'Wrong Pendrive - Continue ??',0

Now the question:
How can I build a string which contains err_message AND lpVolumeNameBuffer.

Something like...

err_message db 'Wrong Pendrive ' + [lpVolumeNameBuffer]

Whatever possibility I try gives an error message from the compiler.
I use fasmw.exe

The only solution I find, is to write the var lpVolumeNameBuffer after var err_message and not to finish err_message with ,0
Post 04 Dec 2013, 17:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 04 Dec 2013, 18:03
You can use the wsprintf API. Just remember that it is a C-Call convention function.
Post 04 Dec 2013, 18:03
View user's profile Send private message Visit poster's website Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun 04 Dec 2013, 18:20
yes thanks, but I want to use the messagebox. And why does Bill G. say "Do not use" wsprintf ?
Post 04 Dec 2013, 18:20
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 04 Dec 2013, 18:29
clamicun,

For simple string concatenation lstrcpy() / lstrcat() will suffice. wsprintf() can be used to construct more complex strings. Those functions have to be used carefully, they don't know output buffer size and easily can overflow it. FormatMessage() is safer in that sense.
Post 04 Dec 2013, 18:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 04 Dec 2013, 18:34
baldr wrote:
wsprintf() can be used to construct more complex strings. Those functions have to be used carefully, they don't know output buffer size and easily can overflow it.
Actually wsprintf limits the output to 1024 characters. This is not stated anywhere in the official docs. Although that limit is possibly different on other OS versions.
Post 04 Dec 2013, 18:34
View user's profile Send private message Visit poster's website Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun 04 Dec 2013, 18:56
My problem continues...

How do I get the 2 vars (lpVolumeNameBuffer and/or lpOut from wsprintf) into the err_message ?

Example ?
Post 04 Dec 2013, 18:56
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 04 Dec 2013, 19:28
clamicun,

That's easy:
Code:
        cinvoke wsprintf, err_message, fmt_err_msg, lpVolumeNameBuffer
;...
fmt_err_msg TCHAR 'Wrong Pendrive "%s" - Continue ??',0
err_message TCHAR 100 dup ?    
Aren't you familiar with printf() family?
Post 04 Dec 2013, 19:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 04 Dec 2013, 19:55
baldr wrote:
clamicun,

That's easy:
Code:
        cinvoke wsprintf, err_message, fmt_err_msg, lpVolumeNameBuffer
;...
fmt_err_msg TCHAR 'Wrong Pendrive "%s" - Continue ??',0
err_message TCHAR 100 dup ?    
I think you will need brackets around lpVolumeNameBuffer (i.e. [lpVolumeNameBuffer]) since it is defined as: lpVolumeNameBuffer dd ?
Post 04 Dec 2013, 19:55
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 04 Dec 2013, 21:46
revolution wrote:
I think you will need brackets around lpVolumeNameBuffer
Definitely, mea culpa. I thought about static VolumeNameBuffer TCHAR MAX_PATH+1 dup ? but copy-pasted something slightly different. Wink
Post 04 Dec 2013, 21:46
View user's profile Send private message Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun 05 Dec 2013, 16:45
YES, it works - without brackets. I understand the "%s" is lpVolumeNameBuffer.
Thank you guys a lot!
clamicun from Germany
Post 05 Dec 2013, 16:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 05 Dec 2013, 17:07
clamicun wrote:
YES, it works - without brackets.
Then I think your buffer is too small, only 4 bytes of storage. Be careful you are not overwriting something that is after the buffer. Also the 'lp' in front of the name is confusing since it usually stands for Long Pointer, and what you have is not a Long Pointer but is a buffer.
Post 05 Dec 2013, 17:07
View user's profile Send private message Visit poster's website Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun 05 Dec 2013, 17:35
ok. I'll consider that.
Post 05 Dec 2013, 17:35
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.