Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29415 Discussions

integration question (strings) -- newcomer

jcage333
Beginner
1,141 Views
hello,

i am trying to integrate fortran exe with an atl dll (c++).

what i want to do is from the fortran app to call a function of the dll, pass string into it, modify it (in c++) and then return it to fortran.

i dont want to return it as a return value of the function but pass it as a pointer, so that it will be imediately available to the fortran app after the dll call.

i have no experience with fortran, read many posts here, tried things out and with the interface wizard and managed to pass the string where in the dll the argument is a BSTR. However, if i change the BSTR, after return of the function the original fortran string is not changed.

i have access to the dll (c++) and can use any interface (BSTR was just an experiment. i can use char * if necessary or whatever.

in your opinion, what is the best types in both fortran and c++ that i can use to achieve this? i know for sure but it has to be passed by ref somehow so that i can change the string within the c++ dll. But how do i make it to be available in fortran after the return of the c++ function in the dll?

thank you in advance for your help.

p.s. my experience in fortran is next to nothing so please be as descriptive as you can

Regards,

JC
0 Kudos
3 Replies
jcage333
Beginner
1,141 Views
hello again,

sorry to disturb again but i have been trying today again to solve the problem but i didnt get anywhere...

can anyone please tell me if what i try to do is possible? or am i wasting my time with the BSTRs and gotta find another way of doing it?

thank you in advance

regards

jc
0 Kudos
Steven_L_Intel1
Employee
1,141 Views
BSTRs are really more for VB. Yes, what you want to do is possible. Fortran will pass a CHARACTER variable as an address and a length. The address can be looked at as a char* in C, but Fortran won't know to look for a trailing NUL unless you code it yourself with an INDEX call after thr return.

See the mixed-language programming chapter of the User Manual for more details.
0 Kudos
jcage333
Beginner
1,141 Views
Hello and thank you for your reply,

So far i can pass the fortran string to BSTR of the atl object. The opposite seems to be the problem, ie alter the BSTR in the ATL object in a way that changes will be imediately available to the fortran program.

Also, i have managed to do it using straight win32 api and works ok. I created the interface (not using the wizard) and put my functions in the a static C .lib that calls varius visual objects.

The reason i was insisting to an ATL / OLE / COM technology is that you can do visual stuff at a higher level instead of coding message loops...

The mixed language manual stuff, when it comes to BSTR are more 'call fortran from vb' oriented while i try to do the opposite...

In any case, if you have / find any example of this please let me know.


Regards

JC
0 Kudos
Reply