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

DLLMain in Fortran

Ilie__Daniel
Beginner
1,235 Views
Hello!

How can I use the DLLMain WinAPI in a Fortran DLL? Do I reference it from another function which is exported to the main program?

I want to check if the parent process has detached from the DLL successfully.

Thank you for any suggestions.

Daniel.
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,235 Views
You write your own function called DllMain. This is called by Windows when the DLL is attached or detached. Such a function would start out as follows:

[fortran]function DllMain (hInstDLL, fdwReason, lpReserved)
!DEC$ ATTRIBUTES STDCALL, DECORATE, DLLEXPORT, ALIAS:"DllMain" :: DllMain
USE IFWINTY
IMPLICIT NONE
integer(BOOL) :: DllMain
integer(HANDLE), intent(IN) :: hinstDLL
integer(DWORD), intent(IN) :: fdwReason
integer(LPVOID), intent(IN) :: lpReserved[/fortran]
It would return a result of TRUE if successful or FALSE if unsuccessful. (Note that these are not the Fortran LOGICAL values .TRUE. and .FALSE.)

View solution in original post

0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,236 Views
You write your own function called DllMain. This is called by Windows when the DLL is attached or detached. Such a function would start out as follows:

[fortran]function DllMain (hInstDLL, fdwReason, lpReserved)
!DEC$ ATTRIBUTES STDCALL, DECORATE, DLLEXPORT, ALIAS:"DllMain" :: DllMain
USE IFWINTY
IMPLICIT NONE
integer(BOOL) :: DllMain
integer(HANDLE), intent(IN) :: hinstDLL
integer(DWORD), intent(IN) :: fdwReason
integer(LPVOID), intent(IN) :: lpReserved[/fortran]
It would return a result of TRUE if successful or FALSE if unsuccessful. (Note that these are not the Fortran LOGICAL values .TRUE. and .FALSE.)
0 Kudos
Ilie__Daniel
Beginner
1,235 Views
Steve,

Thank you! You're a star.

Sure, TRUE and FALSE are the ones declared in IFWINTY.

Thanks again. I can finally make sure the DLL frees the memory.

Daniel.
0 Kudos
Reply