473,804 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5004

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_MaxEntryNam e + 1];
TCHAR szPhoneNumber[RAS_MaxPhoneNum ber + 1];
TCHAR szCallbackNumbe r[RAS_MaxCallback Number + 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(La youtKind.Sequen tial, CharSet = CharSet.Unicode )]
class RasDialParams
{
public int dwSize=Marshal. SizeOf(typeof(R asDialParams));
[MarshalAs(Unman agedType.ByValT Str, SizeConst = RAS_MaxEntryNam e + 1)]
public string szEntryName = null;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = RAS_MaxPhoneNum ber + 1)]
public string szPhoneNumber = null;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = RAS_MaxCallback Number + 1)]
public string szCallbackNumbe r = null;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = RAS_MaxUserName + 1)]
public string szUserName = null;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = RAS_MaxPassword + 1)]
public string szPassword = null;
[MarshalAs(Unman agedType.ByValT Str, 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.Sequ ential, CharSet=CharSet .Ansi )]
public struct DataFiles
{
[MarshalAs(Unman agedType.ByValT Str, SizeConst=260)] public string
Fan;
[MarshalAs(Unman agedType.ByValT Str, SizeConst=260)] public string
Fin;
public DataFiles(strin g 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
8975
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 V8.1 on Linux 2.6.x. Compilers are properly installed and working, means, LD_LIBRARY_PATH and PATH is set correctly. Calling Fortan (example.f) from C (main.c) works fine using
12
2909
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 wload(starttime, duration, station, component, dataray, nsamp, calib, srate, samplength, datadir)
24
4867
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 multiple lines. It would appear though that every distinct set of data starts with a 'code' that is always the 25 characters long. The text is variable however. Assuming i've read the contents of the file into the string myfile, how do i split my...
5
3178
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 created an page with a notes section you see and this writes to an Access database. the problem is that Access can only take 255 characters as a maximum. I have set a MaxChar value in the properties of the text box but you can type in as much stuff as...
2
1479
by: tomamil | last post by:
does anyone has an idea how to do it?
5
2194
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 front of the auto running number, for example, S for Staff, O for Org, C for course and B for Booking followed by the running increase number everytime I enter a record. How and what should I do to get the result I want?
1
6063
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 times. Any help please? Thank you.
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.