The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Igor on August 20, 2010, 11:30:54 AM

Title: STD before DragQueryFile returns wrong results
Post by: Igor on August 20, 2010, 11:30:54 AM
When I use STD (set direction flag) before calling DragQueryFile it will always return 1 for number of characters in a file path, which of course is not correct.

Is this a bug or do I have to clear the flag before calling any windows api functions?


This is with 64bit code, don't know if its the same for 32bit code.
Title: Re: STD before DragQueryFile returns wrong results
Post by: dedndave on August 20, 2010, 01:55:42 PM
if you set the direction flag, you should clear it prior to calling an API
if the state needs to be preserved across the call, it's PUSHF/POPF
CLD, STD, PUSHF, POPF are surprisongly slow instructions - but that may not matter where you are using them
Title: Re: STD before DragQueryFile returns wrong results
Post by: Igor on August 20, 2010, 02:02:51 PM
Quote from: dedndave on August 20, 2010, 01:55:42 PM
if you set the direction flag, you should clear it prior to calling an API
Thanks, didn't know that :)
Title: Re: STD before DragQueryFile returns wrong results
Post by: Rockoon on September 01, 2010, 09:17:24 PM
The STDCALL calling convention defines the rule:

"the direction flag is clear on entry and must be returned clear."
Title: Re: STD before DragQueryFile returns wrong results
Post by: hutch-- on September 01, 2010, 11:09:14 PM
Long ago I learnt that if you use instructions that depend on the direction flag, set it yourself and make sure on exit that it is clear.