Solved

C++ File Dialogs & IO

Posted on 1998-04-15
7
199 Views
Last Modified: 2013-12-26
I've done a bit of Mac Programming, and am a Reasonable  C++ programmer.

How do use the standard Dialog box for the saving and loading of Classes?

For example, in the following class, how would I implement the loadFile, and saveFile methods? Also, please provide the function you would use to initialize the toolbox.

class      myClass
{
      public:
      unknown            loadFile(unknown);
      unknown            saveFile(unknown);

      private:
      string      myString;
      int            myInt;      
};
0
Comment
Question by:rozell
  • 4
  • 3
7 Comments
 

Author Comment

by:rozell
ID: 1291745
Edited text of question
0
 

Author Comment

by:rozell
ID: 1291746
Adjusted points to 150
0
 
LVL 2

Expert Comment

by:roov
ID: 1291747
>how would I implement the loadFile methods?
short numTypes = -1;
SFTypeList typeList;
StandardFileReply reply;
StandardGetFile(nil, numTypes, typeList, &reply);
if (reply.sfGood) {
// user selected a file
 //reply.sfFile is an FSSpec (mac specification record) for the file to load
}

>how would I implement the saveFile methods?
StandardFileReply reply;
StandardPutFile("\pPlease select destination", "\pNo name", &reply);
if (reply.sfGood) {
 //reply.sfFile is an FSSpec (mac specification record) for the saved file
}

>Also, please provide the function you  would use to initialize the toolbox.
static InitToolbox()
{
      InitGraf((Ptr) &qd.thePort);
      InitFonts();
      InitWindows();
      InitMenus();
      TEInit();
      InitDialogs(nil);
      InitCursor();
}
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:rozell
ID: 1291748
Good, this gets me the dialog boxes, but how do I output "myString", and "myInt" to the file, and then retrieve them? I guess this is the part that is really stumping me.
0
 
LVL 2

Expert Comment

by:roov
ID: 1291749
Well, now you'd do the following, assuming the variable mySpec containg the FSSpec you've acquired.
1. Create the file, if required:
 anErr = FSpCreate(&mySpec, fileCreator, fileType, smSystemScript);
fileTpye and fileCreator can be any 4-byte constants that are meaningful to you.
2. Open it, and receive a reference to it:
short refNum = 0;
anErr = FSpOpenDF(&mySpec, fsRdWrPerm, &refNum);
form read/write permission.
3. Read /Write using:
long count = size of my buffer;
void* mybuffer = pointer to data
anErr = FSRead(refNum, &count, buffPtr);

and:
anErr = FSWrite(refNum, &count, buffPtr);

repectivly.

4. Close the file using:
anErr = FSClose(refNum);

Hope this fill out the data...
0
 

Author Comment

by:rozell
ID: 1291750
This is working, however it doesn't appear to be a C++ approach to the problem. Typically, when saving things in C++ one wants to be able to stream the data to disk. This way the programmer doesn't need to know everything about the classes he/she wishes to write to disk.

Is it possible to stream the data to disk in this manner, and if so how.
0
 
LVL 2

Accepted Solution

by:
roov earned 200 total points
ID: 1291751
In such case, the auumption must be that you know the File Specification (fspec) of the file you intend to stream to/from.
You originally requested dialogs, so that's what you got.

If you have the fspec, you can write a basic IO class for streaming, though the standard c++ io classes work if you don't need the resource fork.
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
Decoding 32 bit binary streams 6 37
ShiftLeft challenge 21 76
FizzBuzz challenge 9 76
Thin secure Windows 10 5 75
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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

21 Experts available now in Live!

Get 1:1 Help Now