Problems with calling dll from vba

Yobanlong

New Member
Joined
Sep 18, 2008
Messages
39
I have made a program in Fortran, compiled it as a dll and call it from Excel. That has worked fine for several years.

Recently I upgraded my Fortran compiler, and now I get the error Message "Bad DLL calling convention".

My old compiler was Compaq Visual Fortran Prof ed 6.6 a used from an early version of Microsoft Visual Studio.

My new compiler is Intel Visual Fortran used in Visual Studio 2010 Shell.

The two versions of Visual studio are almost identical to use. I have made a wery simple 1-file test project (one f90 file) and when I compile it on the old compiler it works, on the new one it doesent. I have testet both Excel 97 (under XP) and Excel 2010 under Win 7. The result is the same, the version of the dll made with the old compiler works, the new one does not.

Does anybody know if there is a trick with the new Fortran compiler that I am missing.

I have made a very simple project for testing. The Fortran code is simply:

Code:
SubRoutine Demo(Number)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAL : "Demo" :: Demo
Integer Number
Number=Number+5
End Subroutine Demo

The Excel code calling the dell looks like:
Code:
Private Sub CmdRun_Click()  ' I have made a button
Number=7
Call Demo(Number)
MsgBox (Number)
End Sub

And in Module 1 I have declared:
Code:
Declare Sub Demo Lib "Demo.dll" (Number as Integer)
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I don't know that much will help.

Since you did not specify the full path to the DLL, did you put in c:\Windows\System32? I suppose that your registered it with Regsvr32?

Sometimes, DLL's can be referenced in VBE's Tools > References. A TLB can sometimes be used as the reference.
 
Upvote 0
Yes. I put dlll's in C:\Windows\System32 on WinXP and in C:\Windows\SysWOW64 on Win7.

It works when I compile the dll on the old compiler, both on winXP and Win7. But if I compile it in the new compiler, it doesent work on either win-versions.

The strange thing is that the dll is actually called and when I debug the parameter Number has got the new value, but the vba code stops when returning from the dll.

I know this is a really tricky case, but has anybody sucessfully made a dll with the newest Intel Fortran compiler?
 
Upvote 0

Forum statistics

Threads
1,224,396
Messages
6,178,394
Members
452,844
Latest member
Shebl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top