|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Anonymous Guest
|
Posted: Fri Sep 09, 2005 5:58 am Post subject: Passing UNICODE strings from FTN95 to C++ |
|
|
Sirs,
I have a question about passing UNICODE strings from Fortran to C using FTN95.
I am familiar with the concept of declaring C functions using the STDCALL declaration and defining string arguments using the INSTRING macro � eg.
STDCALL REGTITLESTRING 'RegTitleString' (INSTRING(256))
The C function then nicely receives a C string with terminating NULL character � which works fine.
I am now trying to cater for UNICODE (double byte) character strings in my Fortran by reading them in from a resource or data file and storing them in normal Fortran character variables. These are read in using the normal READ command and are stored (with trailing blanks) in the normal way.
I have a problem using the INSTRING macro in these circumstances, as it appears that the macro truncates the string prematurely if it contains a NULL character within, which is quite likely in UNICODE.
As I am in control of the string passing in other compilers, where the string length is passed, I can strip off trailing blanks and add a double NULL at the end and the new string can be treated as a UNICODE string in the C code (when compiled using #define UNICODE).
Can you suggest a similar mechanism when using FTN95?
Thanking you in anticipation.
David Bradly
Product Development Manager
Bradly Associates Ltd Tel: +44 (116) 254 0697
"Whiteknights" E-mail : support@gino-graphics.com
Finchampstead URL : http://www.gino-graphics.com/
Berkshire
U.K. RG40 3SY
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7934 Location: Salford, UK
|
Posted: Fri Sep 09, 2005 6:59 am Post subject: Passing UNICODE strings from FTN95 to C++ |
|
|
You might try passing the string as a REF rather than an INSTRING.
The longer way would be to replace single NULLs by something else before passing the string
and then convert back again at the other end. |
|
Back to top |
|
|
Anonymous Guest
|
Posted: Fri Sep 09, 2005 7:55 am Post subject: Passing UNICODE strings from FTN95 to C++ |
|
|
Paul,
If you pass the string through as a REF, does a length get passed in any way, by value or by reference?
David |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7934 Location: Salford, UK
|
Posted: Sun Sep 11, 2005 2:16 am Post subject: Passing UNICODE strings from FTN95 to C++ |
|
|
If you export a Fortran CHARACTER variable then hidden length values will be added to the end of the argument list (one for each CHARACTER argument). Note that this is different in CVF etc were the hidden length comes immediately after the argument.
The alternative is to export an INTEGER*1 array (or even better, an INTEGER*2 array). This will be a standard Fortran array.
Regards
Paul |
|
Back to top |
|
|
Anonymous Guest
|
Posted: Tue Sep 13, 2005 10:43 am Post subject: Passing UNICODE strings from FTN95 to C++ |
|
|
Paul,
I have tried to pick up a string length (when defining a Fortran string as REF), but without success. Can you tell me where I am going wrong.
F90 code ----
!STDCALL REGTEXT 'RegText' (INSTRING(256))
STDCALL REGTEXT 'RegText' (REF)
character*12 text
text='ab defghijkl'
text(3:3)=char(0)
call regtext(text)
stop
end
C++ Code ---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define STRNCPY1(y,x,l) {int ic,il; for (il=l-1; x[il] == ' ' && il >= 0; il--) { } for (ic = 0; ic <= il; ic++) { y[ic] = x[ic]; } y[il+1] = ' | | |