Solved

Streams and Memory files

Posted on 1997-06-09
9
196 Views
Last Modified: 2013-11-20
I use a libary that convert file formats but it only use file handles (FILE) as parameters and I dont want to write it as a file but to memory.Are the any way I can send it a FILE parameter but let it write the data to memory so I can read it without writing a file first.The function I call look like this "BOOL SaveFile(FILE * OutFile)"Can I create a memory file and send it's handle to the function? How do I do that?
0
Comment
Question by:401980
  • 4
  • 4
9 Comments
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302034
There are several ways of doing this :
If you want to do it the MFC way , try using the CMemFile which has been derived from CFile itself.

If you want to use native SDK try browsing the MSDN or VC++ CD for memory mapped files. The ftp.microsoft.com used to have a native C++ sample demonstrating mem-mapped file i/o which was in MMFILE.EXE check it out if it still exists.
0
 

Author Comment

by:401980
ID: 1302035
The m_hFile data member of the CFile class gives the variable of type UINT and I need the FILE structure used in I/O streams.I thought of using CMemFile but how do I get a FILE Structure
0
 
LVL 4

Expert Comment

by:AVaulin
ID: 1302036
For what purposes do you need just FILE structure? What fields do you use and how?
0
 
LVL 4

Accepted Solution

by:
mbhakta earned 50 total points
ID: 1302037
As I said , please download the MMFILE.EXE from the Microsoft sit e and see how it is implemented. It not a real nice idea to reject the answer without proper investigation.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:401980
ID: 1302038
The Libary that I use take the FILE struct as a parameter and write the data to the file. I dont now what it is using of the FILE structure.How the lib works is I open a bitmap file and send the the FILE structure to it as parameter. Then I create another file but with a jpeg extention and call another function that requir a FILE structure as parameter (that is now the file that I just created) and it use that structure to write a JPEG file. But I dont want to create a file on disk but in memory so I can send it as a data stream. On the long run I want to convert a BMP file that are in a CLongBin class to jpeg and put that also in a CLongBin class with out creating files. The only way I can see how I can do that are to create memory files or do you have better way or libary or code that can convert BMP to JPEG.
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302039
There is a freeware code from the JPEG group on the net. This code is the infrastructure of the JPEG file. It supports conversion from favourite formats like BMP, GIF etc. to JPG and vice versa. Try exploring the code in there. Also as I pointed out MMFILE example ( WHICH YOU HAVE BEEN IGNORING) would be a way to solve your aches, the CMemoryMappedFile is derived from CMemFile which is inturn derived from CFile. If you are not interested in following some instructions I have been telling you , then Adios!!!

0
 

Author Comment

by:401980
ID: 1302040
I looked at the memfile (The first time you wrote about it) but how can I get a FILE struct from the CMemoryMappedFile (memfile)to send to the lib function that requir a pointer to a FILE struct?I have looked at the JPEG freeware code on the net but it looks to complicated to use.Sorry if you think I ignore your help because I think this is an excelend system helping people and I would not ignore your help.  
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302041
If you use CFile you won't need FILE structure anymore. CFile is a MFC replacement for FILE. You can pass CFile* as a parameter to the functions from hereon. Check for samples on the VC++ CD to see the integration issues.
0
 

Author Comment

by:401980
ID: 1302042
It does not work. The function return FALSE. But it does not sound write to send a pointer of CFile while it wants a pointer to a FILE struct.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 92
Process filename extension 3 172
viewing source code from eclipse 13 88
centeredAverage challenge 8 130
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now