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

DLL creation problem

jean_galy
Beginner
378 Views
Hi all,

I've been testing a simple *.dll creation in IFC9:


subroutine test_dll()

! Expose subroutine test_dll to users of this DLL

!DEC$ ATTRIBUTES DLLEXPORT::test

INTEGER I
DO 2 I=1,100
WRITE (*,8)I
8 FORMAT(I4)
2 CONTINUE

end subroutine test_dll

compiled with the following options:
/nologo /Zi /Od /module:"$(INTDIR)/" /object:"$(INTDIR)/" /traceback /check:bounds /libs:dll /threads /dbglibs /c
/dll

then I've tried to call the sub in a VB.net project:

Declare Sub test Lib "test_dll" ()

Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
Call test()
End Sub
End Class


Then I got a message saying that it can't find the entry point test in the test.dll
Obviously it finds teh dll file but not the entry point.

What am I doing wrong?

Many thanX for your help,


Jean
0 Kudos
5 Replies
Jugoslav_Dujic
Valued Contributor II
378 Views
To call a VF dll from VB, you have to use STDCALL calling convention (AFAIK VB doesn't support IVF's default __cdecl). Either compile the dll with /iface:cvf, or add STDCALL attribute. (Also note that STDCALL implies ByVal, but /iface:cvf implies ByRef).

Also, you have to export the symbol "test" undecorated. Add ALIAS:"test" to !DEC$ATTRIBUTES.

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
378 Views
Several problems here. Start the routine this way:

subroutine test()

! Expose subroutine test to users of this DLL

!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"test",DLLEXPORT::test


1. Routine name didn't match
2. VB wants STDCALL as the calling mechanism
3. VB is case-sensitive and looks for the exact name, not wanting the STDCALL name decoration.
0 Kudos
jean_galy
Beginner
378 Views

Hi Jugoslav,

ThanX for your quick reply.

I'm afraid to say that I'm quite a beginner and do not follow completely your answer.

Could you please provide me a detailed example how to do it?

Many thanks,

Cheers,

Jean

0 Kudos
Jugoslav_Dujic
Valued Contributor II
378 Views
This should work (but untested):

subroutine test_dll(j)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, ALIAS:"test_dll":: test_dll
!DEC$ ATTRIBUTES REFERENCE:: j

INTEGER:: j

INTEGER I
J = 0
DO I=1,100
J = J + i
END DO

end subroutine test_dll
======================================================
Declare Sub test_dll Lib "test_dll" (ByRef j As Integer)

Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
Dim J As Integer 'Or Long, depending on VB version

Call test_dll(J)

End Sub
Jugoslav<.a>
0 Kudos
jean_galy
Beginner
378 Views

I'll try it out...

Many thanX

Jean

0 Kudos
Reply