Click here to Skip to main content
15,914,642 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Datagridview Move Up/Down buttons? Pin
rxsid21-Nov-07 6:55
rxsid21-Nov-07 6:55 
QuestionString.Formate with { character Pin
Aftab Sindhi17-Nov-07 6:55
Aftab Sindhi17-Nov-07 6:55 
AnswerRe: String.Formate with { character Pin
Luc Pattyn17-Nov-07 8:17
sitebuilderLuc Pattyn17-Nov-07 8:17 
GeneralRe: String.Formate with { character Pin
Aftab Sindhi18-Nov-07 19:28
Aftab Sindhi18-Nov-07 19:28 
GeneralRe: String.Formate with { character Pin
Luc Pattyn19-Nov-07 1:17
sitebuilderLuc Pattyn19-Nov-07 1:17 
QuestionProblem with Private Font Collection Pin
bob_up17-Nov-07 4:38
bob_up17-Nov-07 4:38 
AnswerRe: Problem with Private Font Collection Pin
supercat917-Nov-07 10:10
supercat917-Nov-07 10:10 
QuestionInterface FORTRAN90 to VisualBasic - DLL Pin
Sergio2santos17-Nov-07 1:59
Sergio2santos17-Nov-07 1:59 
Hello!
Thanks in advance to anyone that may post a response to this question.
I am trying to figure out how to do the following: Build a DLL in Fortran-PowerStation4.0 (FORTRAN 90) and then call it from Visual Basic 2005 Express Edition.

I have created the FORTRAN DLL and I am able to call it from Visual Basic. Here it is the code that I wrote.

The Fortran dll:
<br />
<br />
SUBROUTINE square(a)<br />
   !MS$ATTRIBUTES DLLEXPORT, ALIAS:'Square'::Square<br />
   real*4 a<br />
   a = a*a<br />
END SUBROUTINE<br />
<br />



The Visual Basic code:
<br />
<br />
Public Class FortranLab<br />
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
        Dim a As Single<br />
        a = 4<br />
        Call Square(a)<br />
        TextBox1.Text = Str$(a) + vbLf + TextBox1.Text<br />
    End Sub<br />
End Class<br />
<br />
<br />
Module Global1<br />
    Declare Sub Square Lib "c:\FORTDLL\Debug\FORTDLL.dll" (ByVal a As Single)<br />
End Module<br />
<br />



THE PROBLEM!
However, the code fails on the call of Square(a), and gives the following error…
“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

I have tried different data, e.g. using only integers, integer and single, ect… But I get always the same error. I have this idea that the error comes from an incompatibility of data types between Fortran and VB. I have looked for documentation on how to best interface data types between Fortran and VB …. without luck.



Stack trace for this error:
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="FortranLab"
StackTrace:
at WindowsApplication1.Global1.Square(Single a)
at WindowsApplication1.FortranLab.Button1_Click(Object sender, EventArgs e) in C:\FortranVB\VB-FORT.vb:line 10
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
AnswerRe: Interface FORTRAN90 to VisualBasic - DLL Pin
Luc Pattyn17-Nov-07 2:24
sitebuilderLuc Pattyn17-Nov-07 2:24 
AnswerRe: Interface FORTRAN90 to VisualBasic - DLL Pin
DQNOK19-Nov-07 12:55
professionalDQNOK19-Nov-07 12:55 
GeneralRe: Interface FORTRAN90 to VisualBasic - DLL Pin
Sergio2santos19-Nov-07 14:21
Sergio2santos19-Nov-07 14:21 
GeneralRe: Interface FORTRAN90 to VisualBasic - DLL Pin
DQNOK20-Nov-07 3:55
professionalDQNOK20-Nov-07 3:55 
Question[2008] Make a Documents.FixedPage from an XML literal? Pin
Duncan Edwards Jones17-Nov-07 0:33
professionalDuncan Edwards Jones17-Nov-07 0:33 
QuestionHow to search a PDF document Pin
midnightshifting16-Nov-07 21:19
midnightshifting16-Nov-07 21:19 
AnswerRe: How to search a PDF document Pin
DigiOz Multimedia17-Nov-07 4:55
DigiOz Multimedia17-Nov-07 4:55 
QuestionRestart System when printing Report in VB.net Pin
mashouri16-Nov-07 19:51
mashouri16-Nov-07 19:51 
AnswerRe: Restart System when printing Report in VB.net Pin
DigiOz Multimedia17-Nov-07 4:51
DigiOz Multimedia17-Nov-07 4:51 
QuestionHandling Valuemember of Combox placed in a grid Pin
infotools16-Nov-07 19:04
infotools16-Nov-07 19:04 
AnswerRe: Handling Valuemember of Combox placed in a grid Pin
deathbat20-Nov-07 13:37
deathbat20-Nov-07 13:37 
GeneralRe: Handling Valuemember of Combox placed in a grid Pin
infotools23-Nov-07 22:26
infotools23-Nov-07 22:26 
QuestionReassigning a control's parent Pin
The ANZAC16-Nov-07 18:45
The ANZAC16-Nov-07 18:45 
AnswerRe: Reassigning a control's parent Pin
Christian Graus16-Nov-07 20:28
protectorChristian Graus16-Nov-07 20:28 
QuestionConnecting to SQL Pin
tellytub16-Nov-07 17:58
tellytub16-Nov-07 17:58 
AnswerRe: Connecting to SQL Pin
Abhijit Jana16-Nov-07 21:31
professionalAbhijit Jana16-Nov-07 21:31 
Questionsaving table Pin
cj433116-Nov-07 10:29
cj433116-Nov-07 10:29 

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.