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 6024341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:08:28+00:00 2026-05-23T04:08:28+00:00

Language: C++, MFC Problem: I am attempting to pass a function some pointers to

  • 0

Language: C++, MFC

Problem: I am attempting to pass a function some pointers to variables that are contained within an array, but the compiler doesn’t seem to agree with how I’m doing it. Here is my code:

Header File:

CString m_strTop;
CString m_strLeft;
CString m_strRight;
CString m_strBottom;

CString *var[4];

Source File:
Constructor()

CString *var[4] = {
  &m_strTop
, &m_strLeft
, &m_strRight
, &m_strBottom
};

Source File:
DoDataExchange()

void FSC_3DPersp::DoDataExchange(CDataExchange* pDX)
{
   CSAPrefsSubDlg::DoDataExchange(pDX);

   for(int i = 2001, j = 0; i <= 2004, j < 4; i++, j++)
   {
       DDX_Text(pDX, i, &var[j]); // 'i' is the ID of the textbox
   }
} 

— What DDX_Text expects —

void AFXAPI DDX_Text(
   CDataExchange* pDX,
   int nIDC,
   CString& value 
);

I wanted to do my DataExchange this way because in several of my files, I have upwards of 75 variables, and using a loop significantly condenses the code, and simplifies things.

I know that the problem I’m having is that I’m just feeding DDX_Text the wrong parameters, but I know that it takes CStrings. However, I’m pretty sure I’m not referencing them correctly.

Any help would be greatly appreciated!

~ Jon

  • 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-23T04:08:29+00:00Added an answer on May 23, 2026 at 4:08 am

    Instead of

    DDX_Text(pDX, i, &var[j]);
    

    use

    DDX_Text(pDX, i, *(var[j]));
    

    As you already have a level of indirection there.

    About this:

    for(int i = 2001, j = 0; i <= 2004, j < 4; i++, j++)
    

    I’m not sure if you are aware that the condition you set there will mean the right one, because that’s how comma operator works. You should either leave the left one out as it will never get to be false when the j < 4 expression is right to it, or use the && operator to be more clear.

    I assume you use Visual Studio to do MFC programming, so I suggest set a breakpoint on that line and make sure that your array is initialized correctly. If it is, then the problem is somewhere else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Language: C# 2.0 or later I would like to register context handlers to
My language is PHP, but the algorithm should be fairly universal. I have an
my primary language is spanish, but I use all my software in english, including
I am writing an MFC application that doesn't use .NET (CLR support is set
LANGUAGE: C#, System: Windows7, Excel 2007 I want to create a .DBF from some
Language = C#.NET Anything that is between [STX] and [ETX] must be accepted rest
why is the default language set in my android emulator some asian language? where
I'd like to use Fortran to solve a numerical problem, but I'm not sure
I have a HtmlView inside my MFC program where I display some data in
It's been quite some time now that I've been coding in C++ and I

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.