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

Save file by fortran code in Windows 7

baldas10
Beginner
2,491 Views
I have a code to save a file in Window. The code provide to open the window to select the directory to save.

subroutine SAVE_FILE(filter_spec,titolo_open,exes,file_spec,initial_file,&
initial_dir_file,status)

use comdlg32

implicit none

integer status

character*256 initial_file,initial_dir_file,filter_spec,file_spec
character*100 titolo_open,exes

type(T_OPENFILENAME) ofn

! *****************************************************************************

ofn%lStructSize = sizeof(ofn)
ofn%hwndOwner = null !GETHWNDQQ(QWIN$FRAMEWINDOW)
ofn%hInstance = null
ofn%lpstrFilter = loc(filter_spec)
ofn%lpstrCustomFilter = null
ofn%nMaxCustFilter = 0
ofn%nFilterIndex = 1 ! Specifies initial filter value
ofn%lpstrFile = loc(initial_file)
ofn%nMaxFile = 256
ofn%lpstrFileTitle = LOC(file_spec)
ofn%nMaxFileTitle = 256
ofn%lpstrInitialDir = loc(initial_dir_file) !NULL ! Use Windows default directory
ofn%lpstrTitle = loc(titolo_open)
ofn%nfileOffset = 0
ofn%nFileExtension = 0
ofn%lpstrDefExt = loc(exes)
ofn%Flags = 0
ofn%lpfnHook = null
ofn%lpTemplateName = null

status = GetSaveFileName(ofn)

return
end


For this subroutine, no problem has been registered in Windows XP.

In Windows 7 (32 and 64 bit), in any case, the window to select the directory not allowed the selection. In particular, the selection of button "save" not produce any effect and the whole program not respond.

What is the problem? Any function are not compatible with W7?

Thank you in advance!
0 Kudos
16 Replies
anthonyrichards
New Contributor III
2,491 Views
We cannot see what values you supply for the subroutine arguments. It would help if we could see them.

Make sure all your strings are null-terminated. We also ened to see your filter arrray.

The filter string must be an array of pairs of null-terminated strings, terminated byTWO null characters. To quote:
"
lpstrFilter
Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.

The first string in each pair is a display string that describes the filter (for example, "Text Files"), and the second string specifies the filter pattern (for example, "*.TXT"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.TXT;*.DOC;*.BAK"). A pattern string can be a combination of valid filename characters and the asterisk (*) wildcard character. Do not include spaces in the pattern string.

The system does not change the order of the filters. It displays them in the File Types combo box in the order specified in lpstrFilter.

If lpstrFilter is NULL, the dialog box does not display any filters."

0 Kudos
Steven_L_Intel1
Employee
2,491 Views
I will comment that there is a sample provided for GetOpenFileName (GetSaveFileName would be the same) in the "Win32" samples zip file.
0 Kudos
tropfen
New Contributor I
2,491 Views
Hello,

have a look at those threads:

http://software.intel.com/en-us/forums/showthread.php?t=81022

http://software.intel.com/en-us/forums/showthread.php?t=80721

both showing a connection between the dialog and the stack reserve size. This is a problem i only have with Vista and win 7


Frank

0 Kudos
anthonyrichards
New Contributor III
2,491 Views
We are still waiting for more information on the arguments you supply to the subroutine. Then we will be able to try and reproduce your problem.
0 Kudos
baldas10
Beginner
2,491 Views
Hi,
this is a example for the call of subroutine.

Thanks



subroutine SAVE_FILE_Q(ANNULLA)

use DFLOGM
use comdlg32

implicit none


character*100 FILE_IN_CUI_SALVARE,VAR,FILE_ES
character*100 titolo_open,exes
character*250 DIRECTORY_SAVE
character*256 filter_spec,file_spec,pathname

type (dialog) dlg

! *****************************************************************************

SAVE_FILE_NAME=OLD_FILE_NAME

OLD_FILE_NAME = NOME(:len_trim(NOME)-4) // ".q22"C

! *****************************************************************************

filter_spec = "Network File (*.q22)"C//"*.q22"C
titolo_open = "Save Q22 file"C
exes = "*.q22"C

status = 0
call SAVE_FILE(filter_spec,titolo_open,exes,file_spec,OLD_FILE_NAME,&
pathname1,status)
0 Kudos
Les_Neilson
Valued Contributor II
2,491 Views

First impressions :
you are concatenating two C strings

[bash]filter_spec = "Network File (*.q22)"C//"*.q22"C[/bash]

Won't SAVE_FILE only see "Network File (*.q22)" ?
By the way since both strings are literals you don't need to concatenate, just have one string - null terminated.

Secondly (may be a typing mistake) but you call SAVE_FILE with pathname1 instead of pathname.

This is why it is a good thing toattach the actual code rather than an abridged typed version.
Les
0 Kudos
anthonyrichards
New Contributor III
2,491 Views
You are ignoring the instruction
"lpstrFilter
Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters."
You may do better to code the following:

character(21) filter_spec(3)

filter_spec(1)="Network File (*.q22)"C ! string is 20 characters + null terminator
filter_spec(2)=" *.q22"C ! string is 20 characters + null terminator
filter_spec(3)=""C//""C ! or use char(0)//char(0)

In the subroutine, you will have to declare filter_spec as an array of three, 21-character strings, then specify the following when filling your T_OPENFILENAME structure (call it FRED say)

FRED%LPSTRFILTER =LOC(FILTER_SPEC(1))
FRED%LPSTRCUSTOMFILTER=NULL
FRED%NMAXCUSTFILTER =NULL
FRED%NFILTERINDEX =1

See if that works.
0 Kudos
baldas10
Beginner
2,491 Views
Dear Anthony,
with your suggestion the problem is the same.
0 Kudos
baldas10
Beginner
2,491 Views
I try to remove the double C strings, but this not resolv the problem.

Thanks,
Baldas
0 Kudos
anthonyrichards
New Contributor III
2,491 Views
Are you using multithreading?
Are you using COM (CoInitialize)?
0 Kudos
baldas10
Beginner
2,491 Views
Dear Anthony,
I not use multithreading, but I'm not sure of this.
0 Kudos
anthonyrichards
New Contributor III
2,491 Views
It maybe that you will have to try and start using the new Common Item Dialogs
(see http://msdn.microsoft.com/en-us/library/bb776913%28v=vs.85%29.aspx).

To quote:
"Starting with WindowsVista, the Common Item Dialog supersedes the older Common File Dialog when used to open or save a file. The Common Item Dialog is used in two variations: the Open dialog and the Save dialog. These two dialogs share most of their functionality, but each has its own unique methods."

In which case it looks like you will have to get into the IVF Module Wizard and COM!
If you know some Visual Basic, it would be worth writing some VB code to use the new common dialog class, get it to work, and then translate the VB code into Fortran code using Module Wizard code for calling interface methods obtained by using the module wizard on the appropriate type library. Or There is sample C++ code supplied in the link above.

It would be nice if Intel could generate a sample which illustrates the use of IFileDialog, IFileOpenDialog, and IFileSaveDialog. !
0 Kudos
onkelhotte
New Contributor II
2,491 Views
Quoting tropfen
Hello,

have a look at those threads:

http://software.intel.com/en-us/forums/showthread.php?t=81022

http://software.intel.com/en-us/forums/showthread.php?t=80721

both showing a connection between the dialog and the stack reserve size. This is a problem i only have with Vista and win 7


Frank


Hi,

we moved to Windows7 as well and weve had the problem that the GetOpenFileName and GetSaveFileName just opened once, but not when we called our subroutine for the second time.

COMMDLGEXTENDEDERROR returned 2, which is CDERR_INITIALIZATION (0x0002 in CDERR.h).

When I set the Stack Reserve Size to 0 our subroutines worked just fine. But why? :-)

Has anyone tried using the new CommonFileDialog for Windows7?

Markus

0 Kudos
onkelhotte
New Contributor II
2,491 Views
Is there a sample of IFileDialog etc. in the making or has anybody tried it succesfully for him-/herself?

Markus
0 Kudos
IanH
Honored Contributor III
2,491 Views
This post has my incomplete attempt from a while back.

The existing Win32 api's are pretty fundamental to the majority of Win32 GUI apps out there. If there was a bug in Windows that broke them I'd expect it to receive a reasonable amount of attention.
0 Kudos
onkelhotte
New Contributor II
2,491 Views
Hi there,

are there any samples of the IFileDialog so far? We still have problems using the old GETOPENFILENAME method.

Markus
0 Kudos
Reply