Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:03:23+00:00 2026-05-30T10:03:23+00:00

MFC CArray was Serialized and saved to a database. I need to read this

  • 0

MFC CArray was Serialized and saved to a database. I need to read this data into a C# project. I am able to retrieve the data as byte[] from the database. I then write the byte[] to a MemoryStream. Now I need to read the data from the MemoryStream.

Someone has apparently solved this before, but did not write their solution.

http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/17393adc-1f1e-4e12-8975-527f42e5393e

I followed these projects in my attempt to solve the problem.

http://www.codeproject.com/Articles/32741/Implementing-MFC-Style-Serialization-in-NET-Part-1

http://www.codeproject.com/Articles/32742/Implementing-MFC-Style-Serialization-in-NET-Part-2

The first thing in the byte[] is the size of the array, and I can retrieve that with binaryReader.readInt32(). However, I cannot seem to get back the float values. If I try binaryReader.readSingle() or

public void Read(out float d) {
    byte[] bytes = new byte[4];
    reader.Read(bytes, m_Index, 4);
    d = BitConverter.ToSingle(bytes, 0);
}

I do not get back the correct data. What am I missing?

EDIT Here is the C++ code that serializes the data

typedef CArray<float, float> FloatArray;
FloatArray floatArray;
// fill floatArray
CSharedFile memoryFile(GMEM_MOVEABLE | GMEM_ZEROINIT);
CArchive ar(&memoryFile, CArchive::store); 
floatArray.Serialize(ar);
ar.Close();

EDIT 2

By reading backward, I was able to get all of the floats, and was also able to determine that the size for CArray is byte[2], or Int16. Does anyone know if this is always the case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:03:25+00:00Added an answer on May 30, 2026 at 10:03 am

    Using the codeproject articles above, here is a C# implementation of CArray which will allow you to deserialize a serialized MFC CArray.

    // Deriving from the IMfcArchiveSerialization interface is not mandatory
    public class CArray : IMfcArchiveSerialization {
        public Int16 size;
        public List<float> floatValues;
    
        public CArray() {
            floatValues = new List<float>();
        }
    
        virtual public void Serialize(MfcArchive ar) {
            if(ar.IsStoring()) {
                throw new NotImplementedException("MfcArchive can't store");
            }
            else {
                // be sure to read in the order in which they were stored
                ar.Read(out size);
    
                for(int i = 0; i < size; i++) {
                    float floatValue;
                    ar.Read(out floatValue);
                    floatValues.Add(floatValue);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write an std::iterator for the CArray<Type,ArgType> MFC class. This is
The MFC CArray class has two template parameters (from MSDN ): template < class
In MFC, wWinMain is defined in appmodul.cpp . This file is built into mfc90ud.dll
This is my first MFC application away from VC6, and I feel a little
I have some old code that uses qsort to sort an MFC CArray of
Previously, I used to use MFC collection classes such CArray and CMap . After
MFC doc/view architecture, GDI drawing/printing. I have a DIB backbuffer I need to display
So I have this MFC dialog program I am working with. The dialogs are
I have a C++/MFC application I need to restructure. The app used to process
The application is of MFC. Sometimes I need to activate the window and display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.