Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Saving 2 documents in 1 file

Posted on 1999-07-22
8
Medium Priority
?
178 Views
Last Modified: 2013-11-20
How can I save to different doctuments in one file. To be more spicific, I want to save a bitmap file in a file followed by some other data of different kind. Now, the saving is not the problem, since I can copy the bitmap to a new file and append my data to the end of the new file. The problem is when I read the file. Since the end of bitmap is not indicated by the end of file flag (because I added my data,) how could I determine the end of the bitmap. And how could this "mixed" file work with MFC's "open document" functions, such as, for example, LoadBitmap()?
Thank you.
0
Comment
Question by:Zainal062797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Expert Comment

by:malmq
ID: 1311000
I would try to come up with some separator (a character sequence you pick), write the bitmap, the separator, and then the file.

You would definitely have to override the open and close documents to get this to work.

Another idea?  Store the bitmap as a link (a path to the bitmap) in the file.  Retrieve that link and then open up the rest of the file.

I'll stay tuned for other ideas
0
 
LVL 2

Expert Comment

by:lucidity
ID: 1311001
you could try CAB files, they will also compress the contecnt and encrypt them
0
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1311002
i think add a tag to every block you write to file is a good idea.

eg:
struct
{
   int type;
   int length;
......
}
in write precedure , write the tag first and then write the data block.
when you read , you can read the tag first and then judge what type the next data is.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:speedup
ID: 1311003
try to study the struct bitmapheaderinfo. you can find the width, height, pixels(how many bits per pixel). then you can calculate the length of the bitmap file(width*height*pixels + length of header). then you can read the data by your own function.
0
 

Author Comment

by:Zainal062797
ID: 1311004
I was thinking of doing that myself, but I was hopping I could avoid this tedious manual method.
0
 
LVL 1

Accepted Solution

by:
speedup earned 400 total points
ID: 1311005
but you have to do that.
or try this:
create a memfile of the bitmap section of your mixed file.
and you can load your bitmap as if it's a pure bitmap file.
0
 

Author Comment

by:Zainal062797
ID: 1311006
How can I make a memefiel? And how about writing to it? Can you elaborate a little bit More please?

Thank you
0
 
LVL 1

Expert Comment

by:speedup
ID: 1311007
sample codes go here:
      HANDLE hfile=CreateFile(svPath,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
      if(hfile==INVALID_HANDLE_VALUE) return NULL;
      
      // Create a file mapping
      HANDLE hmapping;
      hmapping=CreateFileMapping(hfile, NULL, PAGE_READONLY, 0, 0, NULL);

      // Close file handle since we don't need it anymore
      CloseHandle(hfile);

      // Map file mapping object to memory image
      void *baseaddr;
      DWORD length = width*height*pixels;//NOTE:the size of the bmp file.
      baseaddr=MapViewOfFile(hmapping,FILE_MAP_READ,0,0,length);
      if(baseaddr==NULL) {
            CloseHandle(hmapping);
            return NULL;
      }
      const void *lpvBits = (const void *)baseaddr;
      HBITMAP hBitmap = CreateBitmap( width, height, cPlanes, cBitsPerPel, lpvBits);
      .......
      // Close file mapping
      UnmapViewOfFile(baseaddr);
      CloseHandle(hmapping);

Regards
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

670 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