Building a Modeless Dialog Box in 64 bit DLL

Building a Modeless Dialog Box in 64 bit DLL

I currently have a 32 bit DLL which opens a modeless dialog box.  I want to recompile it as a 64 bit DLL but I get errors at runtime (First-chance exception at 0x772a7eb8 (ntdll.dll) in Dialog_Dll_Exe_New.exe: 0xC0000005: Access violation reading location 0xffffffffef4a0000) and the dialog box fails on initialization.  Bare-bones code is below.  Any help would be appreciated.  Thanks, Steve

  integer(4) function DllMain (hInst, ul_reason_being_called, lpReserved)
  !DEC$ IF DEFINED(_X86_)
  !DEC$ ATTRIBUTES STDCALL, ALIAS : '_DllMain@12' :: DllMain
  !DEC$ ELSE
  !DEC$ ATTRIBUTES STDCALL, ALIAS : 'DllMain' :: DllMain
  !DEC$ ENDIF
    use dll_globals
    integer(handle) hInst
    integer(dword) ul_reason_being_called
    integer(lpvoid) lpReserved
    ghInst =  hInst
    DllMain = 1
    return
  end

module dll_globals
    use iflogm
    use ifwin
    integer(handle) ghInst      ! Global instance handle for Dialog Box
    type (dialog) gdlg       ! Defines a dialog data type
  end module dll_globals

subroutine dialog_dll_64 (mode) ! DLL Entry point

  ! Expose subroutine dialog_dll_64 to users of this DLL
  !
    !DEC$ ATTRIBUTES DLLEXPORT::dialog_dll_64
    !DEC$ ATTRIBUTES STDCALL, ALIAS:'dialog_dll_64' :: dialog_dll_64
    
  ! Variables
    USE IFLOGM
    USE DLL_GLOBALS
    USE USER32
    USE KERNEL32
    INCLUDE 'resource.fd'
    EXTERNAL WinDialogQuit
    INTEGER :: MODE
    LOGICAL :: lret
    CHARACTER (LEN=40) :: VERSION, TITLE
    DATA VERSION / '5.0'/
!    
! Initializes dialog box - sets dialog box name to a Type (dialog) object called "gdlg"
!
        lret = DlgInitWithResourceHandle(IDD_DIALOG2, ghInst, gdlg)
        title = 'LAM '//trim (version) // ' - TIREM 3.14'
        CALL DLGSETTITLE (gdlg, title) 
        lret = dlgset(gdlg, IDC_STATIC1, 'Initializing LAM - TIREM')
        lret = DlgSetSub(gdlg, IDCANCEL, WinDialogQuit)
!    
! Show dialog box and declare it a modeless dialog
!
        lret = DlgModeless(gdlg, SW_SHOWNORMAL)       
!
!  Close dialog window
        call dlgexit(gdlg)
        call DlgUninit(gdlg)
!
    return

end subroutine dialog_dll_64

!****************************************************************************
!  FUNCTION: WinDialogQuit ( dlg, id, callbacktype )
!  PURPOSE:  Dialog box callback for initialization and destroy
!****************************************************************************

SUBROUTINE WinDialogQuit( dlg, id, callbacktype )
!DEC$ ATTRIBUTES DEFAULT :: WinDialogQuit

  use user32
  use iflogm

  implicit none

  type (dialog) dlg
  integer id, callbacktype
  if (callbacktype == dlg_clicked) then
    call PostQuitMessage(0)
    call dlgexit(dlg)
  endif
  END SUBROUTINE WinDialogQuit

    program Dialog_64_Exe  ! Main program which calls the DLL

  !DEC$ ATTRIBUTES DLLIMPORT::dialog_dll_64
  !DEC$ ATTRIBUTES STDCALL, ALIAS:'dialog_dll_64' :: dialog_dll_64

    use iflogm
    use dll_globals
    implicit none
    integer :: mode
    mode = 1
    call dialog_dll_64 (mode)
    stop
    end program Dialog_64_Exe

Dialog Resource file:

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Resource1.rc
//
#define IDD_DIALOG2                     103

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        104
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1003
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

 

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

It would be easier to help if you attached a zip of a solution that demonstrates the problem. The resource file you included doesn't define the dialog - the resource.h file is also needed. I tried constructing a solution for this and I could build it,but the call to DLGMODELESS failed (returned .FALSE.). This is not my area of expertise so I am not sure what is wrong. I didn't get an access violation.

Which compiler version are you using?

Retired 12/31/2016

As a tip:

 

  !DEC$ IF DEFINED(_X86_)

003
  !DEC$ ATTRIBUTES STDCALL, ALIAS : '_DllMain@12' :: DllMain

004
  !DEC$ ELSE

005
  !DEC$ ATTRIBUTES STDCALL, ALIAS : 'DllMain' :: DllMain

006

  !DEC$ ENDIF

can be replaced with because the appropriate decoration is then added by x32 or x64 (ie none) automatically. shorted and less chance of typos or wrong byte counts.

 

!DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS : 'DllMain' :: DllMain

Attached is .zip file of the solution.  I am using Parallel Studio XE 2013 with Update 1 in VS 2010 - Windows 7.  If I build the project as a 32 bit app, the dialog box will open.  If I build it as a 64 bit app, the access violation error occurs and the dialog box does not open - As you said, the DLGMODELESS call returns .FALSE..   I have tried various compiler/build settings to no avail.  thanks for the help.

- Steve

 Downloadapplication/zip Dialog_Dll_64_New.zip

You have integer(handle) ghInst but the help says integer(4) which I must say does not seem that it should be correct however perhaps the good Dr F can advise....

integer(handle) is correct. Where does it say otherwise?

Retired 12/31/2016

The topic for DlgInitWithResourceHandle in VS help, latest version compiler version. I know it is wrong I was just pointing it out

Thanks - I'll have this corrected.

Retired 12/31/2016

Quote:

chizmar wrote:

Steve,  Were you able to take a look at this solution.  I still haven't been able to figure it out.

Thanks, Steve

 

Attached is .zip file of the solution.  I am using Parallel Studio XE 2013 with Update 1 in VS 2010 - Windows 7.  If I build the project as a 32 bit app, the dialog box will open.  If I build it as a 64 bit app, the access violation error occurs and the dialog box does not open - As you said, the DLGMODELESS call returns .FALSE..   I have tried various compiler/build settings to no avail.  thanks for the help.

- Steve

 Download Dialog_Dll_64_New.zip

I was able to reproduce the problem but did not get further. I'll look at this again.

Retired 12/31/2016

Leave a Comment

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