473,725 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Integrating FILE * and int file handles

I currently have some code for an application that is running on Win32.
I have tried to keep anything not directly gui related as separate as
possible for portability reasons, including file access. Now has come
the time to try and implement the program on a Windows CE platform.
Problem is, that the MFC CArchive class uses an integer file pointer and
calls to open, close etc and my file handling class is doing everything
with FILE *, such as fopen, fclose etc...

Am I correct in thinking that (as mentioned in the Microsoft Help files)
that file handles returned by open(...) are not ANSI compatible meaning
I should try and stick with my existing code using FILE *? Is there any
way to translate an integer file handle returned by open(...) to a FILE
* that I can use with my existing code?

I am hoping to (at some stage) go to a Palm platform as well so am
trying to avoid any platform specific code where possible. Unfortunately
this alsmo means stripping it any STL code and overriding dynamic_cast
for some platforms (ie: Windows CE)

Any advice would be much appreciated.

Thanks in advance

Woody
Jul 22 '05 #1
12 2593
Woodster wrote:

Any advice would be much appreciated.


You should probably address this to one of the CE newsgroups:
microsoft.publi c.win32.program mer.wince is appropriate. But in brief,
the libraries that come with MS's compilers for CE are missing much of
what's in the C++ standard library. You can work around what's missing,
or you can buy a third-party library (like ours) that provides a
complete C++ standard library.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #2
> You should probably address this to one of the CE newsgroups:
microsoft.publi c.win32.program mer.wince is appropriate. But in brief,
the libraries that come with MS's compilers for CE are missing much of
what's in the C++ standard library. You can work around what's missing,
or you can buy a third-party library (like ours) that provides a
complete C++ standard library.


I would have put it in a Windows or CE group however I am trying to get
my file handling routines platform independent. The dynamic_cast and
STL stuff I have pretty much got sorted out so far. it is just the file
handling that I need to organise. As far as I can tell, the open and
close functions are MS only so I am trying to get a FILE * out of an int
file handle that I can pass to my generic code.

Regards

Woodster
Jul 22 '05 #3
Woodster wrote:
You should probably address this to one of the CE newsgroups:
microsoft.publi c.win32.program mer.wince is appropriate. But in brief,
the libraries that come with MS's compilers for CE are missing much of
what's in the C++ standard library. You can work around what's missing,
or you can buy a third-party library (like ours) that provides a
complete C++ standard library.


I would have put it in a Windows or CE group however I am trying to get
my file handling routines platform independent. The dynamic_cast and
STL stuff I have pretty much got sorted out so far. it is just the file
handling that I need to organise. As far as I can tell, the open and
close functions are MS only so I am trying to get a FILE * out of an int
file handle that I can pass to my generic code.

Regards

Woodster


FILE*-based API (the corresponding header file is stdio.h) is a part of
the standard I/O library as defined by ANSI C. C++ has inherited it, so
it is standard C++. It is neither the most efficient nor the most
convenient of the options, but it is very portable.
Beware: not everything that may be found in stdio.h is standard C++ (or C).
One example is the curious int fileno(FILE*).

File I/O based on open, close and so on is not defined in the standard
C++ or C. It is a part of POSIX though (not MS), so it has good portability
too. There is no standard way to "convert" between the two APIs.

Denis
Jul 22 '05 #4
In article <40************ ***@yahoo.remov ethis.ca>,
RE************* ********@yahoo. removethis.ca says...
FILE*-based API (the corresponding header file is stdio.h) is a part of
the standard I/O library as defined by ANSI C. C++ has inherited it, so
it is standard C++. It is neither the most efficient nor the most
convenient of the options, but it is very portable.
Beware: not everything that may be found in stdio.h is standard C++ (or C).
One example is the curious int fileno(FILE*).

File I/O based on open, close and so on is not defined in the standard
C++ or C. It is a part of POSIX though (not MS), so it has good portability
too. There is no standard way to "convert" between the two APIs.

Denis


In this case, I may be better off converting my existing code from FILE
* to int file handles. You said that using FILE * was neither efficient
or convenient. How does that compare with the int file handles and
related functions?

My file handling is rather simple so have not really had any troubles
but I am interested in what you mean mean by "nor the most convenient"

I will need to do a bit of a search to ensure that the int file handles
are supported by gcc (for PALM development) before going ahead and
converting my code across.

Woodster
Jul 22 '05 #5
Woodster wrote:

In article <40************ ***@yahoo.remov ethis.ca>,
RE************* ********@yahoo. removethis.ca says...
FILE*-based API (the corresponding header file is stdio.h) is a part of
the standard I/O library as defined by ANSI C. C++ has inherited it, so
it is standard C++. It is neither the most efficient nor the most
convenient of the options, but it is very portable.
Beware: not everything that may be found in stdio.h is standard C++ (or C).
One example is the curious int fileno(FILE*).

File I/O based on open, close and so on is not defined in the standard
C++ or C. It is a part of POSIX though (not MS), so it has good portability
too. There is no standard way to "convert" between the two APIs.

Denis
In this case, I may be better off converting my existing code from FILE
* to int file handles. You said that using FILE * was neither efficient
or convenient. How does that compare with the int file handles and
related functions?


The Standard I/O (FILE-based) is buffered, the POSIX I/O (open() etc.) is
not (not supposed to be). The latter requires you to select buffer sizes
manually. If you do it right for the task at hand, you may notice better
performance than with the standard I/O; if you don't, the performance may
deteriorate quite a lot.
With the standard I/O you don't have to worry about that. It is perfectly
adequate for a great many uses.
There are other, less portable ways that can be both much faster and much
easier to use (memory mapped files), specifically for random access, but
we are drifting off-topic here.
My file handling is rather simple so have not really had any troubles
but I am interested in what you mean mean by "nor the most convenient"

I had the C++ file-based streams (<fstream>) in mind. They are superior
to the ANSI C I/O library in several aspects of usage.

Denis
Jul 22 '05 #6
In article <40************ ***@yahoo.remov ethis.ca>,
RE************* ********@yahoo. removethis.ca says...
The Standard I/O (FILE-based) is buffered, the POSIX I/O (open() etc.) is
not (not supposed to be). The latter requires you to select buffer sizes
manually. If you do it right for the task at hand, you may notice better
performance than with the standard I/O; if you don't, the performance may
deteriorate quite a lot.
With the standard I/O you don't have to worry about that. It is perfectly
adequate for a great many uses.
There are other, less portable ways that can be both much faster and much
easier to use (memory mapped files), specifically for random access, but
we are drifting off-topic here.
My file handling is rather simple so have not really had any troubles
but I am interested in what you mean mean by "nor the most convenient"

I had the C++ file-based streams (<fstream>) in mind. They are superior
to the ANSI C I/O library in several aspects of usage.


Denis,

Thanks a lot for the information. I have done very little work with
templates so have not done anything with fstream to date. A quick check
however seems to indicate that the use of fstream (along with a lot of
other usefuly - supposedly ANSI standard stuff) has been thoughtfully
(sic) omitted by Microsoft for their Embedded Visual C++.

I am really beginning to get used to finding out that Microsoft in their
infinite wisdom has left out yet another standard item from their
implementation of C++. Looks like I will just need to through a whole
pile of "if defined"'s at my code in order to get it all up and running
under Pocket PC which I was hoping to avoid in favour of plactfrom
independent code / ANSI standard code. It is now maybe time to go to
Windows CE forums/groups and find out how developers of other
applications that run on platforms including PocketPC handle this
situation.

Thanks again for your responses to date however,

Woodster
Jul 22 '05 #7
"Woodster" <mi****@127.0.0 .1> wrote in message
news:MP******** *************** *@news.westnet. com.au...
I have done very little work with
templates so have not done anything with fstream to date. A quick check
however seems to indicate that the use of fstream (along with a lot of
other usefuly - supposedly ANSI standard stuff) has been thoughtfully
(sic) omitted by Microsoft for their Embedded Visual C++.

I am really beginning to get used to finding out that Microsoft in their
infinite wisdom has left out yet another standard item from their
implementation of C++. Looks like I will just need to through a whole
pile of "if defined"'s at my code in order to get it all up and running
under Pocket PC which I was hoping to avoid in favour of plactfrom
independent code / ANSI standard code. It is now maybe time to go to
Windows CE forums/groups and find out how developers of other
applications that run on platforms including PocketPC handle this
situation.


If you're willing to pay extra, you can get a complete Standard C/C++
library to supplement the eVC++ environments. That can quickly prove
to be cheaper than doctoring your code to adapt to disparate subsets.
See our web site.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #8
"Denis Remezov" <RE************ *********@yahoo .removethis.ca> wrote in
message news:40******** *******@yahoo.r emovethis.ca...
Woodster wrote:

In article <40************ ***@yahoo.remov ethis.ca>,
RE************* ********@yahoo. removethis.ca says...
FILE*-based API (the corresponding header file is stdio.h) is a part of the standard I/O library as defined by ANSI C. C++ has inherited it, so it is standard C++. It is neither the most efficient nor the most
convenient of the options, but it is very portable.
Beware: not everything that may be found in stdio.h is standard C++ (or C). One example is the curious int fileno(FILE*).

File I/O based on open, close and so on is not defined in the standard
C++ or C. It is a part of POSIX though (not MS), so it has good portability too. There is no standard way to "convert" between the two APIs.
Well, actually damn near every OS these days includes some form
of the original open/close/read/write interface pioneered by
Unix and standardized as Posix. It is indeed part of the Microsoft
environment.

And while there is no standard way to convert between file
descriptors (used by open etc.) and FILE objects (used by
fopen), there's almost always *some* way to do this in
every OS.

Denis
In this case, I may be better off converting my existing code from FILE
* to int file handles. You said that using FILE * was neither efficient
or convenient. How does that compare with the int file handles and
related functions?
Watch out! Another Embedded C++ gotcha is that file handles are *not*
integers in this OS.
The Standard I/O (FILE-based) is buffered, the POSIX I/O (open() etc.) is
not (not supposed to be). The latter requires you to select buffer sizes
manually. If you do it right for the task at hand, you may notice better
performance than with the standard I/O; if you don't, the performance may
deteriorate quite a lot.
But probably not, given the smart buffering that a typical modern OS
does for you under the hood.
With the standard I/O you don't have to worry about that. It is perfectly
adequate for a great many uses.
There are other, less portable ways that can be both much faster and much
easier to use (memory mapped files), specifically for random access, but
we are drifting off-topic here.


And into wild speculation. Chances are good that *any* of the
forms of I/O discussed so far will be good enough, absent any
performance data to the contrary.
My file handling is rather simple so have not really had any troubles
but I am interested in what you mean mean by "nor the most convenient"

I had the C++ file-based streams (<fstream>) in mind. They are superior
to the ANSI C I/O library in several aspects of usage.


From the standpoint of type checking, yes. From the standpoint of
performance, Standard C++ I/O tends to be slightly worse than
Standard C I/O. For some C++ libraries, it is *much* worse.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #9
Denis Remezov wrote:

The Standard I/O (FILE-based) is buffered, the POSIX I/O (open() etc.) is
not (not supposed to be). The latter requires you to select buffer sizes
manually. If you do it right for the task at hand, you may notice better
performance than with the standard I/O; if you don't, the performance may
deteriorate quite a lot.


You can also select buffer sizes for standard I/O, with exactly the same
consequences. One benefit of using standard I/O is that you don't have
to write the code to manage the buffering.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #10

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

Similar topics

2
2810
by: news | last post by:
We're being asked to get Quickbooks Enterprise edition for our business. We use a completely hand-made online store (PHP and mySQL) and used to simply create CSV sheets that were imported as invoices into regular Quickbooks. But I guess that's neither 100% accurate and may not even be doable in newer Quickbooks. We want to be able to integrate Quickbooks into the system without replacing our system. Has anyone done this?
3
2168
by: Sonoman | last post by:
Hi all: Is there a class or function that I could use to integrate? By integrating , I mean calculus integration. I need to get data from a sensor that gives me the acceleration of an object. In order to find the displacement for this object I need to integrate its acceleration twice. How can I achieve this with C++? Please advise.
18
20183
by: Conrad F | last post by:
Hello all, I am waiting for receipt of files in a directory. I use the FileSystemWatcher to detect when files arrive in said folder. I need to read the data from these files ASAP but the files are created and detected before writing completes and so I cannot read them until the file handle used in their creation has been released. This would be easy to get around with file renaming or other file locking mechanisms which I could use...
10
4344
by: GJP | last post by:
Hello. Ive been asked to make my own notepade for college assignment. All ig going well, but i cant get the save to work. I can get Save a (shows dialog box), i can get it to just save too, but when i try to put an IF in it to check if the file has already been saved before, it will not save.
4
5038
by: karpagam | last post by:
Since WebServices are a standardized way to invoke a method of another application over the internet, is there a way to integrate two different applications running on different platforms (Say a .NET client application, used for implementing the presentation logic, and a mainframe application that contains the business logic). Is there a way to call the .NET web service from the mainframe application / expose the buiness logic in the...
1
1711
by: apple | last post by:
i try to print image file in a directory using PrintDocument. It will raise printPage event to draw image to the printer. The file will be deleted after print and the directory will be checked every second to get new file inside it. Where should i do the delete function? The way to print image is get from msdn. Can tell me where can i refer to other better ways to print the image file. Thank you. Public fileName As String
1
5712
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
4
1685
by: RossettoeCioccolato | last post by:
I don't suppose that we have made any progress--since I last asked this question about a year ago--towards integrating driver development into the Visual Studio 8.0 build environment. The new compiler is stricter/does a much better job at spotting compile time errors than the compiler distributed with the DDK. I would much prefer to use it. After having reviewed the build log from DDKBuild it doesn't seem like this is rocket science. ...
2
2954
by: SharpCoderMP | last post by:
hi, in my app i monitor the filesystem for changes with FileSystemWatchers. When the change is detected the app performs some actions using Shell32 to obtain information from the filesystem. now the problem is that apparently the CLR not always closes the file handles immediately. this is rather annoying to the user because he's unable to change (write, delete, rename) these locked files or directories. the strangest thing is that some...
0
8888
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
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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...
0
9113
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...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
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
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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.