Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Size of stack affect Windows dialog

jansson
Beginner
5,001 Views
Hi,

I have a problem calling the Windows function GetOpenFileName() from my program.
What hapens when I call it depends on the stack size I requested.

When I set the size of Linker->System->stack reserve size to

200 M it opens the dialog box and I can sellect a file after about 3 s. (Debug compiled)
300 M the call stals for a while, do not show a dialog box, but returns in about 7 s.
400 M call do not return, I waited at least 60s.

I attach my Win32, Quickwin Project showing this behavior.

I use this call in my OpenMP project and there I need to set a large stack to start/run my program.
Can somone enlighten me if this is a feature, a Windows bug of a compiler bug?
Or am I doing something wrong?

Is there a workaround for the large stack size needed to start my program?

My setup:
Core i7 , 4 GB memory
windows 7 64 bit.
vs2010
Compiling with Intel Visual Fortran Compiler XE 12.0.2.154 [IA-32]...

Regards,Magnus

EDIT:
If i just after GetOpenFileName insert
iret=CommDlgExtendedError()
I get iret=0 for 200M and iret=2 for 300M.
Futher I noticed that for 400M it do return after 140s with iret=2
googling I find at msdn.microsoft.com
--
CDERR_INITIALIZATION 0x0002

The common dialog box function failed during initialization. This error often occurs when sufficient memory is not available.

--

What units are used when setting stack size?

Could I be out of some special sort of windows memory?




0 Kudos
31 Replies
Steven_L_Intel1
Employee
3,155 Views
I can't reproduce this problem. No matter what I set the stack to (the units are in bytes and the maximum is about 1GB, even on x64), the dialog opens immediately and closes as soon as I click the button. Can anyone else try this?
0 Kudos
psantos
Beginner
3,155 Views
Hello to everyone,

I tried the attached project and I can't see what you described. No problema at all (dialog opens immediately and closes when I click the button). I tested stack sizes from 100mb till 1gb. I'm running Visual Fortran Compiler XE 12.0.2.154 [IA-32] under win7 64bit.

Pedro
0 Kudos
jansson
Beginner
3,155 Views
Hi,

I now let four of my colleagues download (from the Forum) and run this project and they see the same strange behavior changing with stack size.

We all have Win 7 Pro(English with swedish keyboard) , VS2010 Pro(English), and Visual Fortran Compiler XE 12.0.2.154, but the rest of the spec varies.

Switching to English keyboad and rebooting did not help. Compiled and run inside and outside VS2010.


This beats me. Do anyone have any idea for something for me to test?

Best Regards,
Magnus

0 Kudos
Steven_L_Intel1
Employee
3,155 Views
Reboot into "Safe Mode" and see if the problem persists. You may have some background software, such as an antivirus product, interfering.
0 Kudos
jansson
Beginner
3,155 Views
Thanks for the idea, but it did not help.

Its strange behaviour persist in Windows "Safe Mode" both running VS2010 as normal user and Administrator. The behaviour is identical for 100m and 200M stack size but for 300M it do not return with an error in several minutes.

Regards,
Magnus
0 Kudos
anthonyrichards
New Contributor III
3,155 Views
Perhaps you should now post the code that you use to fill the OpenFileName structure for the call to GetOpenFileName? Have you tried running in Debug mode to see what value is used for the structure size?
0 Kudos
jansson
Beginner
3,155 Views
Hi,

The source code for filling in the OFN structure are seen in Source1.f90 in the project I attached to the first post, was this what you asked for?

The ofn%lStructSize= sizeof(ofn) = 88 in Debug mode.

Here is the content of OFN when calling GetOpenFileName
- ofn {...} TYPE(T_OPENFILENAME)
ofn%LSTRUCTSIZE 88 INTEGER(4)
ofn%HWNDOWNER 0 INTEGER(4)
ofn%HINSTANCE 0 INTEGER(4)
ofn%LPSTRFILTER 14321088 INTEGER(4)
ofn%LPSTRCUSTOMFILTER 0 INTEGER(4)
ofn%NMAXCUSTFILTER 0 INTEGER(4)
ofn%NFILTERINDEX 1 INTEGER(4)
ofn%LPSTRFILE 14321344 INTEGER(4)
ofn%NMAXFILE 256 INTEGER(4)
ofn%LPSTRFILETITLE 14321600 INTEGER(4)
ofn%NMAXFILETITLE 256 INTEGER(4)
ofn%LPSTRINITIALDIR 14321856 INTEGER(4)
ofn%LPSTRTITLE 14320832 INTEGER(4)
ofn%FLAGS 524326 INTEGER(4)
ofn%NFILEOFFSET 0 INTEGER(2)
ofn%NFILEEXTENSION 0 INTEGER(2)
ofn%LPSTRDEFEXT 0 INTEGER(4)
ofn%LCUSTDATA 0 INTEGER(4)
ofn%LPFNHOOK 13308576 INTEGER(4)
ofn%LPTEMPLATENAME 0 INTEGER(4)
ofn%PVRESERVED 0 INTEGER(4)
ofn%DWRESERVED 0 INTEGER(4)
ofn%FLAGSEX 0 INTEGER(4)


Regards,
Magnus
0 Kudos
Steven_L_Intel1
Employee
3,155 Views
Magnus, do you still have this problem?
0 Kudos
acar
Beginner
3,155 Views
I have been having these problems as well - see recent thread GetOpenFileName and GetSaveFileName. I'm running on W7 also. I had missed a CloseThread call in a subsequently called thread which seems to have had something to do with this issue BUT the reason that this cured the problem is not clear as the stack size value I had chosen was 100MB, i.e. well below the 2GB limit.
0 Kudos
Steven_L_Intel1
Employee
3,155 Views
For what it's worth, the stack limit is 1GB on Windows, even on x64.
0 Kudos
anthonyrichards
New Contributor III
3,155 Views
With IVF Composer, VS2005 runnning on 32-bit Windows XP Pro, I have no problem opening and closing the Open File dialog. I note that under Properties..linker...stack reserved size = 300000000 by default, all other entries zero or 'default'.

P.S. I thought that a QuickWin 'main' program thread had to contain a 'do nothing' loop like so:

iret=GetOpenFileName( ofn )

write(6,*) 'File name = ',szfile(1:LEN_TRIM(szfile))

do while(.true.)
call sleepqq(500)
end do
end program


This will leave your seperate main Quickwin thread established after the call to GetOpenFileName. That's the thread that does all the work. That loop is missing from your code.

P.P.S. Although I can confirm that the hook procedure is called and the WM_INITDIALOG message is intercepted, I cannot get the SetWindowPos function to reposition the GetOpenFileName window when I use non-zero X and Y values and change the flags value to SWP_SHOWWINDOW, i.e.

bret = SetWindowPos( hDlg, f2, X, Y, 400, 700, SWP_SHOWWINDOW)

appears to be ignored. The window appears in the default top left corner location always.
Commenting out all your code between CASE(WM_INITDIALOG) and CASE DEFAULT except FileHookProc=1 has no discernable effect.

The reason turns out to be that you should be using

bret = SetWindowPos( GetParent(hDlg), f2, 400, 400, 600, 900, IOR(SWP_NOSIZE, SWP_SHOWWINDOW))

if you want to affect the position of the actual dialog box, which is the parent of the (invisible) child window that receives the hooked message.
0 Kudos
tropfen
New Contributor I
3,155 Views
Hello,

i can reproduce the problem. But it depends on the windows version.

Using:
- Win XP Prof (German) 32 bit i cannot reproduce (even with higher stacksizes)
- Win Vista Prof (German) 32 bit
---- Stacksize 200MByte the main dialog is openning and notings happens
---- Stacksize 300MByte the main dialog is openning and 5 seconds later the close dialog appears

- Win 7 Prof (German) 64 bit
---- Stacksize 200 MByte GetOpenFileName works witin a second
---- Stacksize 300 MByte GetOpenFileName opens after approx. 5-7 seconds
---- Stacksize 400 MByte the main dialog is openning and 5 seconds later the close dialog appears

The Program is compiled with IVF Version 11.1. and VS 2008 Standard (German). But if i remenber correctly i had this problem with IVF 10.X and VS 2005 Standard (German) too.


I have this problem for a long time. I have devloped a visualisation tool were i need to set the stack to 600MByte.

If any one can find the reason, that would be helpfull.

As fare as i can understand is jansson (Magnus) a user with swedish specifics. I am german. Is there any one in this group with also non english layout? Can he reproduce or not reproduce the problem?

Frank
0 Kudos
anthonyrichards
New Contributor III
3,155 Views
It's a QUickWin project, No? Have you added the DO WHILE loop as suggested?

Have you tried GetFileNameFromBrowse instead?
0 Kudos
tropfen
New Contributor I
3,155 Views
Hello,

adding the lines:

do while(.true.)
call sleepqq(500)
end do

using win 7 ...
and the program is lasting at least 1 min without doing anything



adding:
iret= GetFileNameFromBrowse (ofn)
instead of GetOpenFileName

is producing an error.

Frank
0 Kudos
jansson
Beginner
3,155 Views
Thanks for asking Steve.

I worked around it. I made a few local arrays STATIC, and that was enough to get stack size down to about 15M in my project. Is there another or better way using Open-MP Fortran? But now my program eats allot of memory from the start, it previously did so only while computing.

But prior to this I reproduced it in pure C in vs2010. I think this mean its not a Fortran specific problem, but C users maybe newer use this much stack, I do not know.

A detail: Is this /stack:reserve size the sum of all stacks for all threads in the process? else what entities is it limiting?

Another unimportant detail, under x64 it runs when I set stack to 1500M but not to 2000M.

Best Regards,
Magnus


0 Kudos
tropfen
New Contributor I
3,155 Views
Hello Steve,

i would like to understand the connection between stack size and GetOpenFileName. Is there a place where i can find a description?

i also can not understand the dependency with the windows version. For my test, listet above, if have used the same exe-file on the different computer.

Thanks in advance
Frank
0 Kudos
Steven_L_Intel1
Employee
3,155 Views
There is no connection. If the stack size is insufficient, the program will fail with a stack overflow error (or sometimes an access violation). A change in results or behavior due to varying the stack size or Windows version strongly suggests a coding error that is dependent on memory layout.
0 Kudos
tropfen
New Contributor I
3,155 Views
Hello Steve,

i have started a new quickwin projekt. Then i have added the given source code from the original start post. Then i have changed the stacksize. The result i have posted above.

is there an error in the given original source?

Thanks in advance
Frank
0 Kudos
Steven_L_Intel1
Employee
3,155 Views
Well, you've made things much more complicated than they need to be. You don't need the hook function at all if all you want is your dialog to be on top. Instead, as the compiler-provided sample shows, set hwndOwner to the result of calling GetForegroundWindow().

I have fixed up your source and it is below - it works fine as a QuickWin program.

[plain]program main
use comdlg32
use user32, only: GetForegroundWindow
use kernel32, only: GetCurrentDirectory
use ifport, only: SLEEPQQ
implicit none
integer :: iret,ilen
character*512 :: curwdir
character*256 :: title,szfile,szfilter,szFileTitle
TYPE (T_OPENFILENAME) ofn


title = "Open file"C
szFilter = "All files (*.*)��"C ! NB two NULL are needed at the end
szFile = "*.*�"C
szFileTitle=""
curwdir=""

ofn%lStructSize = sizeof(ofn)
ofn%hwndOwner = GetForegroundWindow()
ofn%hinstance = NULL
ofn%lpstrFilter = LOC(szFilter)
ofn%lpstrCustomFilter = NULL
ofn%nMaxCustFilter = 0
ofn%nFilterIndex = 1
ofn%lpstrFile = LOC(szFile) ! filename with full path returned in szFile
ofn%nMaxFile = len(szFile)
ofn%lpstrFileTitle = LOC(szFileTitle) ! filename only returned in szFileTitle
ofn%nMaxFileTitle = len(szFileTitle)
ofn%lpstrInitialDir = NULL
ofn%lpstrTitle = LOC(title)
ofn%Flags = IOR( OFN_EXPLORER, IOR( OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY ) )
ofn%nFileOffset = 0
ofn%nFileExtension = 0
ofn%lpstrDefExt = NULL
ofn%lCustData = 0
ofn%lpfnHook = 0 !LOC(FileHookProc) ! FileHookProc forces dialog to TOPMOST position
ofn%lpTemplateName = NULL
ofn%flagsex = 0

ilen=len(curwdir)
iret=GetCurrentDirectory(int4(ilen),curwdir)
ofn%lpstrInitialDir=LOC(curwdir)

iret=GetOpenFileName( ofn )

if (iret .eq. 0) then
type *,'No file name specified'
else
! Get length of file_spec by looking for trailing NUL
ilen = INDEX(szfile,CHAR(0))
type *,'Filespec is ',szfile(1:ilen-1)

end if

do
call SLEEPQQ(300)
end do
end program[/plain]
0 Kudos
tropfen
New Contributor I
3,058 Views
Hello Steve,

thanks a lot for providing the example. But it is not working for me. I have added 3 files as attachments. Two screenshots and my project folder.

Thanks in advance
Frank

0 Kudos
Reply