Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6744399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:04:44+00:00 2026-05-26T12:04:44+00:00

I am new in Fortan and have a question regarding using make callback-functions available

  • 0

I am new in Fortan and have a question regarding using make callback-functions available for the whole fortran-code.

I am writing on a interface which accesses a Fortran DLL from C#.

module csWrapper
  interface
    subroutine vdiTestFuncCllBak(inputValue, retValue)
      INTEGER, INTENT(IN) :: inputValue
      INTEGER, INTENT(INOUT) :: retValue      
    end subroutine
  end interface

  procedure(vdiTestFuncCllBak), pointer :: m_vdiTestFuncCllBak
end module csWrapper

module VdiFunctionRunnerMain
  use csWrapper
  implicit none

  contains       
    integer function VdiFunctionRunner (XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak, vdiRwertCllbak, vdiCwert2Cllbak, vdiIwert2Cllbak, vdiRwert2Cllbak, vdiErsterCllBak, vdiLetzterCllBak, vdiTestFuncCllBak)
      !DEC$ ATTRIBUTES DLLEXPORT ::VdiFunctionRunner
      !DEC$ ATTRIBUTES REFERENCE :: XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak, vdiRwertCllbak, vdiCwert2Cllbak, vdiIwert2Cllbak, vdiRwert2Cllbak, vdiErsterCllBak, vdiLetzterCllBak, vdiTestFuncCllBak
      implicit none      
      external vdiCwertCllbak, vdiIwertCllbak, vdiRwertCllbak, vdiCwert2Cllbak, vdiIwert2Cllbak, vdiRwert2Cllbak, vdiErsterCllBak, vdiLetzterCllBak, vdiTestFuncCllBak

      !procedure(vdiErsterCllBak), pointer :: m_vdiErsterCllBak
      CHARACTER (len=256) XTGA
      CHARACTER (len=256) TGA, ARRAY_810(10), retValue, satzArt, satzArt2
      CHARACTER (len=256) :: cWertCallBackRet

      integer :: nrReturnValues = 1

      m_vdiTestFuncCllBak => vdiTestFuncCllBak

      call vdiTestFuncCllBak(nrReturnValues, nrReturnValues)
      call m_vdiTestFuncCllBak(1, nrReturnValues)

      VdiFunctionRunner = nrReturnValues
    end function VdiFunctionRunner

end module VdiFunctionRunnerMain

Because the Fortran-code need the possibility to use some functions of the C#-code to, a pass two delegates to the Fortran-code (vdiCwertCllbak, vdiIwertCllbak).

This works quite well when they are used in the MainFunction, so the interfacing works so far.

Now it is needed, that the c#-functions must be available from other functions outside of the MainFunction and even in different modules.

I tried to use functionpointers to deal with this problem, but always get the following error when calling m_vdiTestFuncCllBak. Calling vdiTestFuncCllBak works without problems.

It is the same behaviour when initializing the pointer in the function or in an external module.

The following c# code is called:

private void vdiTestFunc(ref int inputValue, ref int retValue)
{
  retValue = inputValue + 1;
  return;
}

The problem is, that the references of inputValue and retValue are not set when using the funtionpointer.

Does someone had the same issue before and knows a possible solution or has a link with help? I haven’t found information about that in my searches.

I am using the Intel 11 compiler.

Help is very much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:04:44+00:00Added an answer on May 26, 2026 at 12:04 pm

    A quick and dirty way would be to make a module that has a procedure pointer in it:

    module callback_module
        procedure(),pointer::p
    end module
    
    integer function MainFunction(XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak)
      !DEC$ ATTRIBUTES DLLEXPORT ::MainFunction
      !DEC$ ATTRIBUTES REFERENCE :: XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak
      use callback_module
      implicit none
    
      external vdiCwertCllbak, vdiIwertCllbak
      integer :: nrReturnValues = 1
      integer :: iWertCallBackRet = 12
      satzArt = '710.10' // char(0)
    
      p=>vdiIwertCllbak
      call vdiIwertCllbak(satzArt, 1, 2, iWertCallBackRet)
    
      MainFunction= nrReturnValues
    end function MainFunction
    
    integer function tga_810(xtga,array_810)  
      use callback_module
      character(len=256) xtga,tga,array_810(4),s, caption, inputBox
    
      call p('710' // char(0), 1, 2, retValue)
    
      tga_810 = 1
    end function tga_810
    

    EDIT:

    The access violation might be because the pointer has no associated interface.

    module callback_module
        interface
            subroutine callback_sub(arg1,arg2,...)
                !Declare all arguments as they appear in the actual callback routine
            end subroutine
        end interface
    
        procedure(callback_sub),pointer::p
    end module
    

    You’ll need to correctly define the procedure arguments for the interface.

    It might also be caused by having optional arguments. Does vdiIwertCllbak have optionals?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a new code in Fortran and hesitating between using allocatable arrays
I'm very very new to Fortran and the whole Intel compiler thing (I'm using
I'm very new to Fortran. Currently I'm writing (or trying to write) a fortran
I have a line of Fortran code, which includes some text. I'm changing the
I'm writing a preprocessor and postprocessor for Fortran input and output using FORMAT-like statements
I am using python as an interface to several fortran files in my model.
New to javascript/jquery and having a hard time with using this or $(this) to
New day, new problem :-) Code: Client Side: void abw_Closed(object sender, EventArgs e) {
New Question I am looking for a way in Javascript to get the parent
I'm new to Fortran and just doing some simple things for work. And as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.