473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Fixed character length problem calling Fortran DLL

I am calling a Fortran DLL that has a declaration like: character * 260
variablename. I do not have the Fortran code. A path to a file is
passed to the DLL.

C# does not have a fixed character length. I can use vba or vb6 with
Dim variablename as String * 260 and it works. However, I can not get
this to work in C#. The DLL returns a value denoting that the file is
not found. I even concatenated spaces to the string to make sure it
had 260 characters. No luck.

I have no idea how to pass this required parameter to the Fortran DLL
with C#.

Any ideas? Thank you.

Nov 17 '05 #1
2 4976

This example is slightly different but it might help. In RAS I can dial a
modem by passing this C struct to a raw WIN32 API. The C struct contains
several char arrays of fixed length:

typedef struct _RASDIALPARAMS {
DWORD dwSize;
TCHAR szEntryName[RAS_MaxEntryName + 1];
TCHAR szPhoneNumber[RAS_MaxPhoneNumber + 1];
TCHAR szCallbackNumber[RAS_MaxCallbackNumber + 1];
TCHAR szUserName[UNLEN + 1];
TCHAR szPassword[PWLEN + 1];
TCHAR szDomain[DNLEN + 1] ;
DWORD dwSubEntry;
ULONG_PTR dwCallbackId;
} RASDIALPARAMS;
The equivalent C# code looks like this:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
class RasDialParams
{
public int dwSize=Marshal.SizeOf(typeof(RasDialParams));
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
public string szEntryName = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPhoneNumber + 1)]
public string szPhoneNumber = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxCallbackNumber + 1)]
public string szCallbackNumber = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxUserName + 1)]
public string szUserName = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPassword + 1)]
public string szPassword = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDomain + 1)]
public string szDomain = null;
public int dwSubEntry = 0;
public int dwCallbackId = 0;
}

"AlanL" wrote:
I am calling a Fortran DLL that has a declaration like: character * 260
variablename. I do not have the Fortran code. A path to a file is
passed to the DLL.

C# does not have a fixed character length. I can use vba or vb6 with
Dim variablename as String * 260 and it works. However, I can not get
this to work in C#. The DLL returns a value denoting that the file is
not found. I even concatenated spaces to the string to make sure it
had 260 characters. No luck.

I have no idea how to pass this required parameter to the Fortran DLL
with C#.

Any ideas? Thank you.

Nov 17 '05 #2
Thank you. This got me pointed in the right direction. The Fortran
DLL liked the following. Thanks again.

[StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct DataFiles
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)] public string
Fan;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)] public string
Fin;
public DataFiles(string Fan, string Fin)
{
this.Fan = Fan;
this.Fin = Fin;
}
}

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sascha T. | last post by:
Hi! I have desperately searched google and its groups in vain. Hope you can help with my problem. I need to call some ancient Fortran objects by C++-main program with the latest Intel Compiler...
12
by: Bigdakine | last post by:
I don't know if this is the right forum for this, and if not please suggest one which fits. I have to call a fortran sub routine from a C main program. The fortran subroutine statement is ...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
5
toxicpaint
by: toxicpaint | last post by:
Hi, I'm sure there is a really easy way to do this and I'm just being silly, but is there a way that I can get a text box to stop people typing when it hits its maximum character length. I've...
2
by: tomamil | last post by:
does anyone has an idea how to do it?
5
by: HowHow | last post by:
I am using Access 2000. I have few tables with primary keys, for example, StaffID, OrgID, CourseID and BookingID. In order for me to recognize my IDs easily later, I want to set a fixed character in...
1
by: ramanak | last post by:
Hi, I want generate random password. it should contain at least 1 upper case letter, 1 digit, 6 character length. I can use Membership.GeneratePassword(-, -), but its not having numbers some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.