473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Call fortran dll from C#

I am trying to call a fortran dll from c# code. But i get the following error message.An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B). Could any one please tell me where I am going wrong? The codes are given below.

Fortran code

Expand|Select|Wrap|Line Numbers
  1. !  lwing.f90 
  2. !
  3. !  FUNCTIONS/SUBROUTINES exported from lwing.dll:
  4. !  lwing - subroutine 
  5. !
  6. ! Expose subroutine lwing to users of this DLL
  7.   !
  8.   !DEC$ ATTRIBUTES DLLEXPORT::lwing
  9.  
  10.   ! Variables
  11. SUBROUTINE lwing(span,dfuse,lenw)
  12. !-------------------------------------------------------------------
  13. ! This subroutine calculates the wing length in cantilever position
  14.  
  15. !Input arguments: span- wing span
  16. !                 dfuse- Fuselage diameter
  17. !Output Arguments: lenw- Length of wing in cantilever position
  18. !-------------------------------------------------------------------
  19. IMPLICIT NONE
  20. REAL, INTENT(IN)::dfuse,span
  21. REAL, INTENT(OUT)::lenw
  22.  
  23.  
  24. lenw=(span-dfuse)/2;
  25.  
  26. END SUBROUTINE lwing

C# Code
Expand|Select|Wrap|Line Numbers
  1. namespace ggg
  2. {
  3.     public class Model
  4.     {
  5.         [DllImport("lwing.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Winapi)] /* Import from DLL, the C# compiler provides a rudimentry check of the signature */
  6.         public static extern void lwing(ref double span,ref double dfuse,ref double lenw);
  7.         static void Main()
  8.         {
  9.             double a = 1;
  10.             double b = 1;
  11.             double c = 1;
  12.             lwing(ref a,ref b,ref c);
  13.         }
  14.     }
  15. }
May 12 '10 #1

✓ answered by libishkb

I changed the 'Platform Target' from the properties of my C# project from 'AnyCPU' to 'x86'.

4 5146
Plater
7,872 Expert 4TB
Try getting rid of this section:
CallingConvention = CallingConvention.Winapi
May 12 '10 #2
I changed the 'Platform Target' from the properties of my C# project from 'AnyCPU' to 'x86'.
May 13 '10 #3
Plater
7,872 Expert 4TB
Did that turn out to be the solution?
May 17 '10 #4
yes strangely it was....
May 18 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: To Forum | last post by:
hi, how can i use existing library in Fortran for my C++ program. I have try f2c but it is rather cubersome... Can I compile the Fortran code into Object file and then link to C++ code? My thanks...
6
by: Adrian | last post by:
I am trying to pass the address of a C++ function into a Fortran routine to enable the Fortran routine to call this C++ function. I have to do it this way as our build process does not allow...
2
by: Ray J. | last post by:
I have a C++ program written and compiled on Solaris 8 with gcc. With gcc lets me compile fortran code along with the C++ program to be able to call the fortran code as a subroutine. The...
11
by: Cottonwood | last post by:
I want to call a GNU-Fortran-library from a GNU-C++ source. Is that possible at all? If yes, what is to be done to link the program? I get an error message that says that the module MAIN_ cannot...
21
by: Cottonwood | last post by:
I want to call a C module from a Fortran program. Whatever I tried - the linker could not find the C module. I know about the leading underscore and switched even that off. I abstracted everything...
1
by: hanhaner | last post by:
hey, there I am new to Python and C++. Now I am trying to call some fortran subroutines in python code. I was told the good way is to write a c++ interface. I am not quite sure how to do it. ...
0
by: hanhaner | last post by:
hey, there I am new to Python and C++. Now I am trying to call some fortran subroutines in python code. I was told the good way is to write a c++ interface. I am not quite sure how to do it. ...
8
by: Luna Moon | last post by:
Hi all, As a C/C++ programmer, there are a few reasons to use Fortran: (1) Fortran is very similar to Matlab and easy to port; (2) Fortran has support of complex numbers and vectorized numbers...
4
by: nitusa | last post by:
Hey Everyone, I am doing a VB6 to C# conversion and everything was going smoothly until I realized that I needed to call a Fortran 77 (.for) .dll inside my code. I have looked through everything...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.