Click here to Skip to main content
15,914,447 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
foxele22-May-04 17:21
foxele22-May-04 17:21 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
Maxwell Chen22-May-04 22:18
Maxwell Chen22-May-04 22:18 
Generalcreating an application that runs in the background Pin
shals16921-May-04 18:36
shals16921-May-04 18:36 
GeneralRe: creating an application that runs in the background Pin
Dominik Reichl22-May-04 0:53
Dominik Reichl22-May-04 0:53 
Generalbinary contents in a CString Pin
(Steven Hicks)n+121-May-04 17:54
(Steven Hicks)n+121-May-04 17:54 
GeneralRe: binary contents in a CString Pin
Andrew Quinn AUS21-May-04 22:57
Andrew Quinn AUS21-May-04 22:57 
GeneralRe: binary contents in a CString Pin
Prakash Nadar22-May-04 2:10
Prakash Nadar22-May-04 2:10 
GeneralRe: binary contents in a CString Pin
Gary R. Wheeler23-May-04 12:35
Gary R. Wheeler23-May-04 12:35 
Personally, I would modify your Download function to return an object, something like the following:
class DownloadObject {
public:
    DownloadObject(char *text);
    DownloadObject(unsigned char *data,int size);
    ~DownloadObject();
    enum Type { Text, Binary };
    Type GetType() const;
    bool GetAsText(CString &text) const;
    bool GetAsBinary(unsigned char **binary,int *size);
private:
    Type _Type;
    unsigned char *_Data;
    int _Size;
};
This object contains an arbitrary sequence of bytes, that the creator of the object (e.g. the Download function) can specify to be of type 'Text' or 'Binary'. The creator specifies the type of object based on which constructor he uses. When the object is returned to the caller of the Download function, that function can determine the type of data using the supplied member functions, something like this:
DownloadObject *Download(CString URL);
//...
DownloadObject *object = Download(example_URL);
CString text;
unsigned char *data;
int size;
if (object != NULL) {
    switch (object->GetType()) {
        case DownloadObject::Text:
            object->GetText(text);
            //...
            break;
        case DownloadObject::Binary:
            object->GetBinary(&data,&size);
            //...
            break;
    }
    delete object;
}
Note that I've modified the definition of the Download function to return a pointer to a DownloadObject. If the return value is NULL, that can be an error indication.

I think this is a better approach than overloading the CString class. While CString does let you store binary data of arbitrary length which includes '\0' characters, it's primary purpose is to hold text data. Using it to contain binary data confuses the programmers who come after you.


Software Zen: delete this;
GeneralRe: binary contents in a CString Pin
(Steven Hicks)n+123-May-04 13:06
(Steven Hicks)n+123-May-04 13:06 
General32 bpp images w/ controls Pin
alex.barylski21-May-04 16:39
alex.barylski21-May-04 16:39 
GeneralRe: 32 bpp images w/ controls Pin
Prakash Nadar21-May-04 16:43
Prakash Nadar21-May-04 16:43 
GeneralRe: 32 bpp images w/ controls Pin
John R. Shaw22-May-04 17:14
John R. Shaw22-May-04 17:14 
GeneralExecute program QU Pin
DNFSB21-May-04 15:47
DNFSB21-May-04 15:47 
GeneralRe: Execute program QU Pin
Prakash Nadar21-May-04 16:41
Prakash Nadar21-May-04 16:41 
GeneralRe: Execute program QU Pin
DNFSB22-May-04 14:26
DNFSB22-May-04 14:26 
GeneralUser created menu, using New Selection. Pin
Eversman21-May-04 14:19
Eversman21-May-04 14:19 
QuestionCapturing keyboard input from inside a background WMP9 COM plugin? Pin
IGx8921-May-04 13:47
IGx8921-May-04 13:47 
AnswerRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
Michael Dunn21-May-04 14:06
sitebuilderMichael Dunn21-May-04 14:06 
GeneralRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
IGx8921-May-04 15:45
IGx8921-May-04 15:45 
AnswerRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
Blake Miller25-May-04 15:42
Blake Miller25-May-04 15:42 
GeneralRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
IGx8925-May-04 16:05
IGx8925-May-04 16:05 
Generalraw data to bitmap Pin
Snillet2k21-May-04 12:17
Snillet2k21-May-04 12:17 
GeneralRe: raw data to bitmap Pin
John R. Shaw22-May-04 17:51
John R. Shaw22-May-04 17:51 
GeneralUnknown Usr Breakpoint causes program halting!?!?! Pin
Wheatbread21-May-04 10:57
Wheatbread21-May-04 10:57 
GeneralRe: Unknown Usr Breakpoint causes program halting!?!?! Pin
Alexander M.,23-May-04 9:50
Alexander M.,23-May-04 9:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.