Win32 API & FORTRAN

Win32 API & FORTRAN

Trying to build a gui for a program, using Lawrence's book. Have built program (V6.1) but cannot get the common dialog boxes to run. Keep getting an invalid lStructSize error.
Any help would be gratefully received.

9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Well, some code fragments would help us better recognize what's going on. In any case, the best method is to use CVF SIZEOF function to fill in the members, e.g.

TYPE(T_PRINTDIALOG):: PD
...
PD%lStructSize = SIZEOF(PD)

You'll find many structures containing size of themselves in Windows API. The reason is forward compatibility -- if additional members which bring additional functionality will be specified in future Windows versions, the API function will recognize by sizeof whether the caller is "old" and use defaults for the new members; if sizeof corresponds to "new" specification, new members will be also used.

Jugoslav
www.xeffort.com

Sorry for missing code, is as follows:

TYPE(T_OPENFILENAME):: Ofn
......
integer*4 function InitializeOpen(hWnd)
! intitialize open file name structure
use PLOT32Globals
use comdlg32
use comctl32
implicit none
integer(4) hWnd
szfilter = "PLOT32 data files(*.txt)" &
// char(0) // "*.txt" // char(0)
Ofn%lStructSize = sizeof(Ofn)
Ofn%hwndowner = hWnd
Ofn%hinstance = ghinstance
Ofn%lpstrfilter = LOC(szfilter)
Ofn%LPSTRCUSTOMFILTER = NULL
Ofn%NMAXCUSTFILTER = 0
Ofn%NFILTERINDEX = 1
Ofn%LPSTRFILE = LOC(szFileName)
Ofn%NMAXFILE = LEN(szFileName)
Ofn%LPSTRFILETITLE = loc(szTitleName//".txt"C)
Ofn%NMAXFILETITLE = 256
Ofn%LPSTRINITIALDIR = NULL
Ofn%LPSTRTITLE = null
Ofn%FLAGS = NULL
Ofn%NFILEOFFSET = NULL
Ofn%NFILEEXTENSION = NULL
Ofn%LPSTRDEFEXT = loc("*.txt"C)
Ofn%LCUSTDATA = NULL
Ofn%LPFNHOOK = NULL
Ofn%LPTEMPLATENAME = NULL
initializeOpen = 1
return
end

As I said before I took this code from Lawerence's book, but it returns the following error:
"The lStructSize member of a structure for the corresponding common dialogbox is invalid"

Hopefully this explains my problem further?

Unfortunately no -- that code looks correct so the problem must be somewhere else. Did you verify with the debugger that Ofn is not corrupted somehow before call to GetOpenFileName?

Jugoslav
www.xeffort.com

I have an idea on this.

1. Install the 6.1A update and rebuild your application. Does the problem persist?

2. If it persists, what value is being stored in the structure size field?

Steve

Steve - Intel Developer Support

Hi, Thanks for your answers.
Have updated to version 6.1A, however to no avail.

Not sure of how to get debug info for windows programs - can happily debug console programs but have never built windows programs before!

have added the main calling code below incase this highlights any ideas?

Thanks

integer function MainWndProc ( hWnd, mesg, wParam, lParam )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'MainWndProc' :: MainWndProc
!DEC$ ENDIF

use user32
use Plot32Globals

implicit none

integer*4 hWnd
integer*4 mesg
integer*4 wParam
integer*4 lParam

include 'resource.fd'

interface
integer*4 function InitializeOpen(hWnd)
integer(4) hWnd
end function
end interface

! Variables
integer(4) ret, i, iret
character(SIZEOFAPPNAME) lpszName, lpszHelpFileName, lpszContents, lpszMessage
character(SIZEOFAPPNAME) lpszHeader
logical(4) bret
integer(4) hMenu
integer(4) ierror
integer(4) hwndEdit

select case ( mesg )

! WM_DESTROY: PostQuitMessage() is called
case (WM_DESTROY)
call PostQuitMessage( 0 )
MainWndProc = 0
return
! WM_COMMAND: user command
case (WM_COMMAND)
select case ( IAND(wParam, 16#ffff ) )

case (IDM_OPEN)
! get open file dialog box
Ofn%Flags = null
bret = GETOPENFILENAME(Ofn)
! check to see if the OK button has been pressed
if(bret == 0) then
! check for error
call COMDLGER(ierror)
else
call LoadFile(hWndEdit)
!call UpdateFileMenu(hwnd)
end if
MainWndProc = 0
return

Well, if InitializeOpen has never been actually called it's hard to expect that OFN was appropriately filled in.

Jugoslav
www.xeffort.com

Thanks for all of your help!!

Sometimes not able to see the obvious!

You debug a Windows program exactly as you do a console program. Why do you think there's a difference?

Steve

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today