Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help: Invalid Parameter Used error Pin
nudma13-Aug-08 4:36
nudma13-Aug-08 4:36 
GeneralRe: Help: Invalid Parameter Used error Pin
Rashmi_Karnam13-Aug-08 9:57
Rashmi_Karnam13-Aug-08 9:57 
GeneralRe: Help: Invalid Parameter Used error Pin
nudma14-Aug-08 4:43
nudma14-Aug-08 4:43 
QuestionString or binary data would be truncated. The statement has been terminated. Pin
laziale12-Aug-08 3:47
laziale12-Aug-08 3:47 
AnswerRe: String or binary data would be truncated. The statement has been terminated. Pin
vikas amin12-Aug-08 5:28
vikas amin12-Aug-08 5:28 
Questionrowchanged event and update error Pin
catborise12-Aug-08 3:10
catborise12-Aug-08 3:10 
AnswerRe: rowchanged event and update error Pin
catborise13-Aug-08 1:53
catborise13-Aug-08 1:53 
QuestionNeed Help Calling A Fortran 77 (.for) DLL Pin
Nitusa12-Aug-08 3:03
Nitusa12-Aug-08 3:03 
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 I have found using Google and have still been unable to get it to successfully work. Currently the following call works about 75% of the time, but the other 25% of the time my program just calls the .dll and then it simply exits; no error/exception occurs, it just quits without executing anymore code. As you can see I have tried multiple ways to catch/generate error messages. I have no Fortran experience and I was told to leave the Fortran code alone, since it has been around and working since the 70’s.

From what I can tell the Fortran code only has one subroutine. I have included the header/parameters below:

SUBROUTINE FORTRANCALLA(INPUTL, TABLEL, NAMEL2, COMMAL, LOADL)
EXTERNAL F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F20

!DEC$ ATTRIBUTES DLLEXPORT :: FORTRANCALLA
!DEC$ ATTRIBUTES STDCALL, ALIAS: 'FORTRANCALLA' :: FORTRANCALLA
!DEC$ ATTRIBUTES REFERENCE :: INPUTL
!DEC$ ATTRIBUTES REFERENCE :: TABLEL
!DEC$ ATTRIBUTES REFERENCE :: NAMEL2
!DEC$ ATTRIBUTES REFERENCE :: COMMAL
!DEC$ ATTRIBUTES REFERENCE :: LOADL

CHARACTER(80), INTENT(IN) :: INPUTL
CHARACTER(80), INTENT(IN) :: TABLEL
CHARACTER(80), INTENT(IN) :: NAMEL2
CHARACTER(4), INTENT(IN) :: COMMAL
CHARACTER(80), INTENT(IN) :: LOADL


It appears C++ was used to wrap the .for file and generate a .dll which was called in the VB6 program using the following code:

Call Fortran.FORTRANCALLA(infilecalc, tablecalc, destination2, format, loadcond)

Public Declare Sub FORTRANCALLA Lib "Name.dll" _
(ByVal INPUTL As String, ByVal TABLEL As String, ByVal NAMEL2 As String, ByVal COMMAL As String, ByVal LOADL As String)

It appears that the VB6 program also has problems with the call, but not as frequently. However, it also handles the failed .dll call much better and does not crash. If possible I would just like my program not to fatally crash.

Here is the code I am currently working with and I am calling the exact same .dll that is currently being used in the VB6 version:

static class Fortran
{
[DllImport("Name.dll")]
private static extern bool FORTRANCALLA(
StringBuilder infilecalc,
StringBuilder tablecalc,
StringBuilder destination2,
StringBuilder format,
StringBuilder loadcond);

public static void Calculate(string infilecalc, string tablecalc, string destination2, string format, string loadcond)
{
string tempOutputPath = FileMod.GetTemporaryDirectory() + "NameTemp.tmp";

StringBuilder bldrInFileCalc = new StringBuilder(infilecalc, 80);
StringBuilder bldrTableCalc = new StringBuilder(tablecalc, 80);
StringBuilder bldrDestination2 = new StringBuilder(tempOutputPath, 80);
StringBuilder bldrFormat = new StringBuilder(format, 4);
StringBuilder bldrLoadCond = new StringBuilder(loadcond, 80);

try
{
if (!FORTRANCALLA(bldrInFileCalc, bldrTableCalc, bldrDestination2, bldrFormat, bldrLoadCond))
MessageBox.Show(new System.ComponentModel.Win32Exception().ToString());
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}

//FORTRANCALLA(bldrInFileCalc, bldrTableCalc, bldrDestination2, bldrFormat, bldrLoadCond);

File.Copy(tempOutputPath, destination2, true);
File.Delete(tempOutputPath);
}
}

Right now I cannot find a pattern to the crashes. I could work with the same files, making identical calls to the .dll, and sometimes it works sometimes it doesn't. At first I thought it was something to do with memory allocation, but I don't think that is the case because sometimes it crashes on the first call. Sometimes it only crashes once, sometimes it crashes multiple uses in a row, and sometimes you can make many calls before it starts crashing again.

Does anyone have any ideas? Because I am officially out of ideas...

Thanks,
Nitsua
QuestionRegistering to an event on a wcf web service Pin
Lior Zat12-Aug-08 2:37
Lior Zat12-Aug-08 2:37 
AnswerRe: Registering to an event on a wcf web service Pin
c242312-Aug-08 3:47
c242312-Aug-08 3:47 
GeneralRe: Registering to an event on a wcf web service Pin
Lior Zat13-Aug-08 20:17
Lior Zat13-Aug-08 20:17 
Questionhow can i resolve System.Collections.ListDictionaryInternal Pin
koolprasad200312-Aug-08 2:26
professionalkoolprasad200312-Aug-08 2:26 
AnswerRe: how can i resolve System.Collections.ListDictionaryInternal Pin
leppie12-Aug-08 2:30
leppie12-Aug-08 2:30 
Questionenumeration of Active Sockets Pin
damcg12-Aug-08 2:07
damcg12-Aug-08 2:07 
AnswerRe: enumeration of Active Sockets Pin
leppie12-Aug-08 2:28
leppie12-Aug-08 2:28 
GeneralRe: enumeration of Active Sockets Pin
damcg12-Aug-08 3:01
damcg12-Aug-08 3:01 
GeneralRe: enumeration of Active Sockets Pin
leppie12-Aug-08 3:12
leppie12-Aug-08 3:12 
GeneralRe: enumeration of Active Sockets Pin
damcg12-Aug-08 3:55
damcg12-Aug-08 3:55 
QuestionIntermittent Code behind Errors in C#.net Pin
AnuVM12-Aug-08 1:53
AnuVM12-Aug-08 1:53 
AnswerRe: Intermittent Code behind Errors in C#.net Pin
Christian Graus12-Aug-08 1:57
protectorChristian Graus12-Aug-08 1:57 
QuestionURL escape issue Pin
George_George12-Aug-08 1:13
George_George12-Aug-08 1:13 
AnswerRe: URL escape issue Pin
Christian Graus12-Aug-08 1:56
protectorChristian Graus12-Aug-08 1:56 
GeneralRe: URL escape issue Pin
George_George12-Aug-08 1:59
George_George12-Aug-08 1:59 
GeneralRe: URL escape issue Pin
Christian Graus12-Aug-08 2:48
protectorChristian Graus12-Aug-08 2:48 
GeneralRe: URL escape issue Pin
George_George12-Aug-08 3:01
George_George12-Aug-08 3:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.