Home > Software engineering >  VB to call FORTRAN DLL has a problem, and master.
VB to call FORTRAN DLL has a problem, and master.

Time:09-29

Novice, in using vb to call DLL, problems appeared in the process of transfer number, one of the variables NELEMS, assignment of 20 in vb, but come into a large and random number in FORTRAN,
FORTRAN DLL code statement:
SUBROUTINE ELEMCA (KK, IH, R01, R02, Z1, Z2, PHY1, PHY2, NELEMS , IA, NH, NNODES, NSIZE, E1 and E2, FNU1, FNU2, G, THICK, RHOS, AR, along, PHP, going, COSINE, CHECK, PHPP, ARCL, SS)
! DEC $ATTRIBUTES DLLEXPORT: : ELEMCA
! DEC $ATTRIBUTES ALIAS: "ELEMCA" : : ELEMCA
! DEC $ATTRIBUTES VALUE: : KK, IH, NELEMS , IA, NH, NNODES, NSIZE
! DEC $ATTRIBUTES REFERENCE: : R01, R02, Z1, Z2, PHY1, PHY2, E1 and E2, FNU1, FNU2, G, THICK, RHOS, AR, along, PHP, going, COSINE, CHECK, SS, PHPP, ARCL
REAL R01 (50), R02 (50), Z1 (50), Z2 (50), PHY1 (50), PHY2 (50), E1 (50), E2 (50), FNU1 (50), FNU2 (50), G (50), THICK (50), RHOS (50), AR (29), along (29), PHP (29), going (29), COSINE (29), CHECK (8, 8), SS (50)
REAL PHPP ARCL, PHPRIM
REAL PH (29), AM (8, 8), PHIMAT (8, 8)
An INTEGER K, IH, NETP NETL, NET1, I, J, KK,.net, NELEMS
The following statement is a vb code:
Private Declare Sub ELEMCA Lib "ELEMCA. DLL" (ByVal KK As an Integer, ByVal IH the As an Integer, ByRef R01 As Single, ByRef R02 As Single, ByRef Z1 As Single, ByRef Z2 As Single, ByRef PHY1 As Single, ByRef PHY2 As Single, ByVal NELEMS As Integer , ByVal IA As an Integer, ByVal NH As an Integer, ByVal NNODES As an Integer, ByVal NSIZE As an Integer, ByRef E1 As Single, ByRef E2 As Single, ByRef FNU1 As Single, ByRef FNU2 As Single, ByRef G As Single, ByRef THICK As Single, ByRef RHOS As Single, ByRef AR As Single, ByRef along As Single, ByRef PHP As Single, ByRef going As Single, ByRef COSINE As Single, ByRef CHECK As Single, ByRef PHPP As Single, ByRef ARCL As Single, ByRef SS As Single)
The calling code:
Call ELEMCA (KK, IH, R01 (1), R02 (1), Z1 (1), Z2 (1), PHY1 (1), PHY2 (1), NELEMS , IA, NH, NNODES, NSIZE, E1 (1), E2 (1), FNU1 (1), FNU2 (1), G (1), THICK (1), RHOS (1), AR (1), along (1), (1), PHP's going (1), COSINE (1), the CHECK (1, 1), PHPP, ARCL, SS (1))
Please help to answer.

CodePudding user response:

Don't be A language code is modified to B language code busywork,
Also don't use A language code to directly invoke B language code base, this complicated things so easy to get wrong,
Just make A, B language code of input and output is redirected to A text file, or modify A, B language code let it through text file input and output,
Can easily make A, B coordination between the two languages,
For example:
A will request data written to A file a.t xt, renamed after finish aa. TXT
B find aa. TXT, read its contents, call the corresponding function, and writes the results file b.t xt, after finish delete aa. TXT, changed its name to bb. TXT
Found A bb. TXT, read the content, after finish delete bb. TXT
Above can be replaced by any kind of A language or development environment, B can be replaced by any kind of with the development of A different language or development environment,
Unless A or B does not support to determine whether A file exists, file read and write and file name,
But who can name does not support to determine whether a file exists, file read and write and file name for the development of language or development environment?

The communication methods between the temporary text file sharing this process there are plenty of advantages, compared to other method only listed below I can think of now:
Loose coupling between process,
Can be on the same machine, process, also can cross machine, across the operating system, hardware platform, and even multinational,
, convenient debugging, and monitoring, only let the third party or artificial view the temporary text files,
Switch, convenient online service, need to delete or create the temporary text files,
, is convenient to realize distributed and load balancing,
Services to provide convenient, queue, queue is full and it is almost impossible to happen (unless the hard disk space full)
DE...

"Across different languages, machine, across the operating system, hardware platform, multinational, cross *. *" this suffering,
back "exchange of information using Shared plain text file" shore!

CodePudding user response:

A) need to declare A FORTRAN function STDCALL
B) pay attention to the length of the data type, the INTEGER is 2 bytes or 4 bytes? VB to use 4 bytes Long, REAL, too, with Sing in VB, Double,
  • Related