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

problem with FindWindow

Jiri_P_
Beginner
4,230 Views
Hallo
I'm not able to compile this code.
program SEC_TEST
use ifwin
implicit none
character*(256) title
integer :: hwnd
hwnd = findwindow(null, title)
end program SEC_TEST
I always obtain the next error message:

Generic procedure reference has two or more specific procedure with the same type/rank/keyword signature. [FINDWINDOW]

Can anybody tell me why? I'm using IVF10.0.26 and VS2003.

Thanks Jiri

0 Kudos
31 Replies
jimdempseyatthecove
Honored Contributor III
2,935 Views

Jiri,

The best way to go about solving these problems for yourself is to search the IVF include directory for the interface declarations. In user32.f90 (the module that creates user32.mod) you will find the declaration for FindWindow. To-wit:

INTERFACE FindWindow
FUNCTION FindWindow_G1( &
lpClassName, &
lpWindowName)
use ifwinty
integer(HANDLE) :: FindWindow_G1 ! HWND
!DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'FindWindowA' :: FindWindow_G1
!DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpClassName
character*(*) lpClassName ! LPCSTR lpClassName
!DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpWindowName
character*(*) lpWindowName ! LPCSTR lpWindowName
END FUNCTION
FUNCTION FindWindow_G2( &
lpClassName, &
lpWindowName)
use ifwinty
integer(HANDLE) :: FindWindow_G2 ! HWND
!DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'FindWindowA' :: FindWindow_G2
integer(LPVOID) lpClassName ! LPCSTR lpClassName
!DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpWindowName
character*(*) lpWindowName ! LPCSTR lpWindowName
END FUNCTION
END INTERFACE

The 2nd template is the one you are attempting to call. When using the interfaces you will find that FORTRAN compilers do not promote variables with the same viggor as does C++.

I think you may find that if you change your code to

integer(HANDLE) :: hwnd
If that fails then also add/change
integer(LPVOID) :: myNULL
hwnd = findwindow(myNULL, title)
Jim Dempsey
0 Kudos
Jiri_P_
Beginner
2,935 Views
Dear Jim
Thank you for your reply. It was good idea to look at user32.f90 for FindWindow interface declaration. I found out there is two functions in this interface. I used one of them (FindWindow_G1) and compilation was successful.
I would like to use "Save as" dialog in the console application.
The reason of using this function is that I try to find out hwnd of console because dialog appears behind the console and I can switch between dialog and console. This solved my problem only partly. Now I can't switch to console until save or cancel button is pressed but dialog still appears behind the console.
Today I have analyzed some other source codes and I found out next things:
1) ofn%hwndOwner = GETFOREGROUNDWINDOW() is sufficient and much more simpler smiley [:-)]
2) If there isn't any output to console (write, print, type) before calling dialog this dialog appears in front of console. But I need some output before.
Any suggestion?
0 Kudos
Steven_L_Intel1
Employee
2,934 Views
Jiri,

You should not use FindWindow_G1 in your code. Unfortunately, there is an error in the declaration in the module that makes the generic reference ambiguous. I'll have that fixed in a future release. You can keep using the _G1 name for now, though I will agree that GetForegroundWindow() is a better choice.

I don't underatand your second question. If this is a console application, the console window should appear immediately even without any output.
0 Kudos
Jiri_P_
Beginner
2,935 Views

Hallo Steve

Regaring my second question. There was a little misunderstanding. You are right. Console appears immediately after runing exe file. But after this when I try to open dialog "Save as" the placing of this dialog depends on whether there was any output to console before opening this dialog. If there was any output dialog "Save as" appears behind the console.If there wasn't any output dialog "Save as" appears in front the console.

Sorry for my English.

Jiri

0 Kudos
Steven_L_Intel1
Employee
2,935 Views
Look at the sample Win32GetOpenFileName to see how to do this. You pass GetForegroundWindow() as hwndOwner.
0 Kudos
Jiri_P_
Beginner
2,935 Views
Steve
Sorry but you still don't understand me. Using of GetForegroundWindow() as hwndOwner is clear for me.
Attached you can find GetOpenFileName sample with small modification. I added the 'read' statement befor calling GetOpenFileName function. If you start program and enter any whole number you can see that 'Open' dialog appears behind the console window. You must to use 'Start without Debugging' or run this exe file from comman line or some explorer. Because if youuse debug then 'Open' dialog appears normally in front of console window.
Sorry for confusing in previous post. Read statement is input to console not output.
0 Kudos
Steven_L_Intel1
Employee
2,935 Views
It doesn't do that for me. When I build and run your program, using "Start without debugging", the filename browse window appears on top of the console window.
0 Kudos
Jiri_P_
Beginner
2,935 Views
Steve, could you send me yourexe file please? I'll test it and if it will work correctly then I have probably problem with VS2003 or compiler.
Thanks
0 Kudos
Steven_L_Intel1
Employee
2,935 Views
I can't email EXE files, even ZIPped. I have attached it here.
0 Kudos
Jiri_P_
Beginner
2,935 Views
Yes,zip isok. Thank you. I have tryed it and 'Open' dialog appeared behind the console.
Therefore I still don't understand where is the problem :-( I have done test on some other computer also and result is stil the same.
0 Kudos
Steven_L_Intel1
Employee
2,935 Views
I'd be interested to have others try the program I attached. I see the same behavior whether I run it from Visual Studio or just double-click on the EXE. I am running Windows XP.

0 Kudos
g_f_thomas
Beginner
2,935 Views

From Vista:

Console appears, no dialog, and Ctr C ing gives

forrtl: severe (24):end-of-file during read, unit -4, file CONIN$

etc

Doesn't matter whether 'run as admin' or in 'xp compatibility'.

However, the ivf sample runs just fine on 2-click :console behind dialog.

In vs 2005, run without debug: no go

In vs 2005 debug: runs fine

Gerry

0 Kudos
Steven_L_Intel1
Employee
2,935 Views
Gerry, what do you mean by "no go"?

Interesting Vista results...
0 Kudos
g_f_thomas
Beginner
2,935 Views

By 'no go' (slang)I meanit doesn't happen or work. What does happen is the console appears, stuff is written to it, and then it disappears,all in the blink of an eye.

Gerry

0 Kudos
Steven_L_Intel1
Employee
2,935 Views
Gerry, did you build the program from source or just run my EXE from VS? The behavior you describe is odd.
0 Kudos
g_f_thomas
Beginner
2,935 Views

Steve, it seems to behave as I would expect. With the exe you posted earlier all I did was 2-click it. Since that didn't do muchI went to the ivf samples folder and rebuilt the project in vs in both debug and release mode. Debugging both (yes, the debugger snivels about the absence of debug symbols but no matter) displayed the open dialog on top of the console. Ditto on 2-clicking the exes from explorer. Running the release in vs from debug/run without debugging behaved like the exe you posted earlier. Is this what is odd? It must be the weather or ...

Gerry

0 Kudos
Steven_L_Intel1
Employee
2,935 Views
What I find odd is the behavior where the console window disappears instantly. I don't see how that would happen.
0 Kudos
Les_Neilson
Valued Contributor II
2,935 Views

Steve,

I ran your exe (also under Windows XP)
The console appeared, I entered a number, then the File Open dialog appeared. No problems here.

Les

0 Kudos
g_f_thomas
Beginner
2,935 Views

Ditto on Vista, provided you enter a number when the console appears. However the source in the ivf samples folder doesn't expect keyboard input to kick start the app. Has something changed in the source for the posted exe over that generated by rebuilding the ivf samples source?

Gerry

0 Kudos
Steven_L_Intel1
Employee
2,827 Views
Gerry, reread the thread. The EXE I posted was modified to prompt for input.
0 Kudos
Reply