Solved

WriteProfileString trying to save an array to registry ...

Posted on 2000-04-24
9
571 Views
Last Modified: 2008-03-10
Win32 Api, Visual C++

Array is nndata[48]


void CW1Dlg::SaveProfile()
{
      CWinApp* app = AfxGetApp();
      app->WriteProfileString("profile", "somedata", XXXXXX.GetXXX());
}

something like this. But i dont know how to get the array in there. I still cannot work with this MSDN library. I find nothing usefull in there.

Thanks for any help.
0
Comment
Question by:peter_b
  • 5
  • 4
9 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2744542
What you mean by XXXXX.GetXXXX() is unclear.   The last parameter should be a pointer to a NUL terminated character string that is to be written to the file/registry.  Like

char nndata[48] = "Data to be written";

app->WriteProfileString("profile", "somedata",nndata);

Does that help?   Let me know if you have any questions.
0
 

Author Comment

by:peter_b
ID: 2744639
app->WriteProfileString("profile", "somedata",nndata);

ok but i tried to indicate that there are 48 values in the array. So how do I add all the 48 ?
int i;
for (i = 0; i < 48; i++)
{
app->WriteProfileString("profile", "somedata",nndata[i]);
}

or how ?
will they be in one string ? (hmm i just see nndata is a float what to do then ?)

0
 
LVL 22

Expert Comment

by:nietod
ID: 2744693
Your loop would work, but each time it sets the value, it overwrites the old value, so the first 47 value are all lost and only the last value is saved.

>> will they be in one string ?
No.  You can create a long string that has all those values concatenated together (in whatever format you want) and write that string 1 time.

>> (hmm i just see nndata is a float what to do then ?)
You can't write a float directly to the file/registry.  this is only for writting text.  You can convert the float to an ASCII string that _represents_ the float's value in ASCII digits.  Then you can write this string to the file.  You can use sprintf() to convert the float to a string that represents it.

like

char S[20];
double D = 123.456;
sprintf(S,"%6.4f",D);
0
 

Author Comment

by:peter_b
ID: 2744745
tell me when to stop please as you allready answered my question but as a beginner i am happy if i can learn something.
if i understood it goes like this ??

int i;
float nndata[49] = "";
for (i = 0; i < 48; i++)
{
nndata[49]= nndata[49] + nndata[i]);
}
String newnndata;
sprintf(newnndata,"%6,4f",nndata[49])
app->WriteProfileString("profile", "somedata",newnndata);

"%6,4f" <-- what is this ?
not sure if my concatenate is a concatenate :)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 22

Expert Comment

by:nietod
ID: 2744860
This is VERY basic C programming concepts.   If you don't understand it, you probably need to spend some time studying an introductory C programming text.  Then when you understand the language, try to program in windows in the language.  Trying to learn windows programmin and try to learn C/C++ programming are two very difficult tasks.  it is best to do them seperately, rather than at the same time.

>> float nndata[49] = "";
No.  if it is an array of floats, it cannot be initialized to a string literal like "".  Only to floating point values.

>> nndata[49]= nndata[49] + nndata[i]);
This adds up all the numbers in the array and stores the total in the last one.  Is that what you want?  Do you want the total value to be stored in the file?  or d you want all 48 values to be stored?   (Note also that it stores the total in the 50th position in the array, but there are only 49 positions that are valid, so this is also an error.)

>> "%6,4f" <-- what is this ?
sprintf() generates a string that represents the value in the floatingpoint number (or whatever is passsed to sprintf().)  These are standard formatting codes that tell sprintf() how you want the string it gererates to look.  These are explained in any C text book.
0
 

Author Comment

by:peter_b
ID: 2744986
Well you are right but as I do this for fun i just want to achieve a goal some programming piece to work. Now for example i am modifying a small app a friend wrote (he has no time to work on it). If I am able to save some data to the registry and recover them I am happy. Much more fun than to read examples of virtual cashing mashines, even if it would take 1,5 minutes for a pro like you and a week for me.
Hope you are not offended if i keep on asking stupid questions in the C/C++ section that seems to be yours :) .


0
 
LVL 22

Expert Comment

by:nietod
ID: 2745082
>> you are not offended if i keep on asking
>> stupid questions
I am not offended and answering questions is why we are here, but I really do think you are going about it the wrong way.  You need to learn C/C++ first (or another language), then windows.  Learning them both at the same time is asking too much of anybody.

In addition, looking over example code is not the best way to learn either.  You are missing VERY basic concepts--like chapter 1 stuff about C.  That is why you really need to start out with a good tex book or two.
0
 

Author Comment

by:peter_b
ID: 2745142
"C++ how to program" i guess from the PAQ ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2745175
That is a good one for the basics--although there are many others.  It definitely doesn't do well in the advanced features, but that shouldn't matter to you for at least a year.  
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

707 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

15 Experts available now in Live!

Get 1:1 Help Now