|
Hi!!
For INI file:
[SECTION1]
KEY1=500
KEY2=VALUE
[SECTION2]
KEY3=500
KEY4=100
[SECTION3]
KEY5=xyz
The corresponding XML file would be:
<SECTION1>
<KEY1>500</KEY2>
<KEY2>VALUE</KEY2>
</SECTION1>
<SECTION2>
<KEY3>500</KEY3>
<KEY4>100</KEY4>
</SECTION1>
<SECTION3>
<KEY5>xyz</KEY5>
</SECTION3>
"If you change then change for the good."
|
|
|
|
|
Try this one...
{
FILE *fpr,*fpw;
CHAR buffer[50];
DWORD nSize=50;
LPTSTR lpszReturnBuffer;
CHAR buff[50];
fpr = fopen("C:\\SWATI.INI","r");
fpw = fopen("C:\\Ss.txt","w");
lpszReturnBuffer = buff;
fprintf(fpw,"");
memset(buffer, 0x00, 50);
GetPrivateProfileSectionNames(buffer,nSize,"C:\\SWATI.INI");
char* pBuffer = buffer;
int nWrite = 0;
while(strlen(pBuffer) > 0){ // For all Section Name
nWrite = fprintf(fpw,"\n<%s>",pBuffer); // Print the SectionName < SECTION >
memset(buff, 0x00, 50);
GetPrivateProfileSection(pBuffer,buff,nSize,"C:\\SWATI.INI");
char* pBuff = buff;
int nWrt = 0;
while(strlen(pBuff) > 0){ // For all KEY=VALUE
CString strToken;
strToken = pBuff; // The the KEY with Value "KEY=VALUE"
// Find the = character inside the string
INT nPosEql = strToken.Find('=');
if(nPosEql == -1){
break;
}
CString strKey = strToken.Left(nPosEql); // Get the Key
CString strVal = strToken.Mid(nPosEql + 1); // Get the value
fprintf(fpw, "\t\n<%s>", strKey); // Print <KEY>
fprintf(fpw, "%s", strVal); // Print VALUE
fprintf(fpw, "</%s>", strKey); // Print </KEY>
pBuff = pBuff + strlen(pBuff) + 1; // Move to next key
}
fprintf(fpw,"\n</%s>",pBuffer); // Print the </SECTION>
pBuffer = pBuffer + strlen(pBuffer) + 1; //Move to next section
}
fclose(fpr);
fclose(fpw);
}
|
|
|
|
|
Hi!!!!!!!!!!!!
Yes, it`s working.
Thanx a lot for ur kind support.
"If you change then change for the good."
|
|
|
|
|
I have to create a console text menu that is written from values from an INI file.
The menu entry would be something like:
1) Pencil
2) Pen
3) Typwriter
Select choice -->
The INI file has
[Writing Tools]
1 = Pencil
2 = Pen
3 = Typewriter
Can you modify the example to create a buffer (or array of struct) that uses this? I don't need values written to an output file.
Thanks
Jer 29:11
|
|
|
|
|
The output buffer from GetPrivateProfileSectionNames is filled with all the section names and are seperated by a null character. The last section name is followed by two null characters. Similarly output buffer in GetPrivateProfileSection is also filled with all the key name, value pairs seperated by null character.
So modify your program accordingly...
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
XMinds
|
|
|
|
|
HI!!
Could u plz tell me how to modify the program , to print all the section names.
Thanx
"If you change then change for the good."
|
|
|
|
|
Checkout this URL.
http://www.codeguru.com/Cpp/data/data-misc/inifiles/article.php/c4577/
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
XMinds
|
|
|
|
|
Using INI files is one of the simpilist things in the world. If you read the documentation, you'll note that the names returned by GetPrivateProfileSectionNames() are each null terminated, that means when you pass it to GetPrivateProfileSection(), it only sees the first one in the list. You need to take into account the return value of GetPrivateProfileSectionNames(), which is the number of characters retreived, and parse it to get each section name.
Example of what GetPrivateProfileSectionNames() should return: "SECTION1\0SECTION2\0SECTION3\0\0".
The same applies to what is returned by GetPrivateProfileSection(). In your case the buffer should actualy contain something like: "KEY1=500\0KEY2=VALUE\0\0". This is anouther case where you need to pay attention to the return value, and manualy parse buffer.
Some Notes:
1) There are other functions that read the specific values given the section and key names, they are easier to use. This assumes that your program already knows the section names and the key names.
2) After the first call the .INI is loaded into memory, so there is almost no overhead associated with reading the file on subsiquent calls. Because it is already loaded into memory space.
3) Your code is written in 'C' not 'C++', so you should provide a define statement ("#define") that specifies the maximum size of the buffer. That way you can change it by simply changing the value defined. In this case you do have a second option, if you dinamicaly allocate the buffer and the value return is rediculously high, then the value returned is actualy the negitive size of the required buffer. The only reason that it is rediculoulsy high, is that both functions return a DWORD, which is unsigned. If you take that value and convert it to a long and subtract it from 0, then you should have the required number of bytes needed to hold all the data, at which point you can reallocate the buffer and recall the function.
What all the above amounts to, is that you need to read and understand the documentation, before you use the functions. It also means that I have never had a reason to use those two particular functions, because of note 1.
I hope you understand what I said, because it is very important that you understand what I consider the fundamentals of programming. After a while you'll be seeing these things in your sleep.
Good Luck,
John R. Shaw
INTP
Every thing is relative...
|
|
|
|
|
Hello -
I think my problem stems from converting a project from an earlier version (6.0?) to MS Visual C++ 7.1. Everything compiles and links (with warnings 4075 and 4098 [conflicting lib]) just fine. These errors didn't occur in 6.0 though.
The program runs fine until the end where Windows encounters an error. The debugger says a user breakpoint was called from the code. Additionally, a thread has exited with a code 0. It also says that the variable 'temp' is being used without being defined.
I hope this wasn't too vague. Thanks in advance for any help!
Chris
|
|
|
|
|
I am not sure what is going on, but both of these appear to be warnings, if they where not then they would be much higher values, or much lower in decimal (negative). That is the Most Significant Bit (MSB) would be set. If I am correct and slapping a 'C' in front of the number gives the actual messages you are seeing, then C4098 (Level 1) progably just copies the return value to a register, which is simple to fix. I am suprised that 'C++' did not report that as an error. The other warning, and it is a warning, C4075 (Level 1) has to do with the order in which global objects are created. That one worries me a little, but there is a good chance that the initializations are occuring in an order that that will do no harm.
As for the value 'temp', that depends on how it is being used. If it is not in your code then you can probably ingnore it.
If the thread is exiting with code 0, then that means nothing went wrong while executing that thread. That does not mean that some thing could not go wrong.
The fact that the code from Microsoft stopped at a user defined break point does not mean there is an error in your code.
What you need to do is test the code compiled in realise mode. That is more difficult, but we do not get warnings when running in realise mode, only errors (if we are lucky).
The first version a Bounds Checker I bought, allowed me to reject an out sourced program repeatedly until they gave me the source code. It took me five minutes to figure out why Bounds Checker was objecting to the program. My manager did not believe me util I said "if I was to do this, the program would crash". He said "Ok do it", when I did the whole system crashed.
What you are seeing are warnings, that does not mean you can ignore them. What it means is that you should understand them, at least well enough to realise if they are actualy a problem or not.
Blast, I did it again! I tend to get carried away with my explinations. I do not know if any of the above helped you, but I hoped it did.
Good Luck,
INTP
Every thing is relative...
|
|
|
|
|
Hey thanks. I'll try that realise mode.
|
|
|
|
|
Hi All,
I am implementing Drag n Drop between My Namespace extension and Windows folders.The data in "My Namespace extension" does not exist on the user's machine. When the user drags a file from "My Namespace extension" and drops it on a windows folder, I am downloading that file to a specific directory on the users machine and from there putting it in the DataObject.
But the whole thing is not working. I am getting the following error message.
"Cannot Copy file: cannot read from source file or disk"
Can someone tell me what could be going wrong here?
Thanks and Regards,
Anil
|
|
|
|
|
It would depend on from where you are trying to download the data?
just a wild guess, are you trying to put a namespace extention interface for a symbian phone ?
|
|
|
|
|
I am downloading the data from a database
|
|
|
|
|
What actually happens is I am putting the information about the file in my implementation of IDataObject and in the GetData function of IDataObject, I am using that information to communicate with Applet which in turn will download that File from the Database to the client machine.
Hope I am clear now.
Thanks and Regards,
Anil
|
|
|
|
|
There are several things to be considered while performing this operation. Its not easy as it seems. When a Drop event occurs in the Windows folder, It will immediately start querying for the type and the IDataObject.
You can implement this functionality by implementing the file->copy process in IDataObject::GetData(...)
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
XMinds
|
|
|
|
|
Jagadeesh, thats exactly what I am doing here, I am dowloading the file in the Getdata method and am putting it in the STGMEDIUM structure there...but still something seems to be missing....
|
|
|
|
|
In my MDI project. MainFrame has a m_CoolBarCtrl, m_TabCtrl and m_DirTreeCtrl. they are all dynamically created. in the Create funcation specify parent CWnd.
m_CoolBarCtrl parent is MainFrame
m_TabCtrl parent is m_CoolBarCtrl
m_DirTreeCtrl parent is m_TabCtrl
When user click on a abc.cpp file in the DirTree, I want to notify the main frame to open this file.
How can I implement this? Please give me a direction.
|
|
|
|
|
Use AfxGetMainWnd() and dynamic_cast to obtain a valid pointer to CMainFrame. Then Call the method to open the file. Thats it!!!
Alternatively you can send a message to the Mainframe HWND and handle it accrodingly in your CMainFrame class. But I suggest using the first approach.
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
XMinds
|
|
|
|
|
hi,
How to Resize Dialog and Controls when Desktop resolution is changed, in VC++ Dialog based application?.
Thax,
Om
|
|
|
|
|
You need to handle WM_DISPLAYCHANGE message and then resize your dialog accordingly.
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
XMinds
|
|
|
|
|
in addition to above post you can check WM_SETTINGCHANGE [Windows] tooo
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow cheers, Alok Gupta VC Forum Q&A :- I/ IV
|
|
|
|
|
Please can any one help me by providing any VC++ project wid source code. It can be as simple as possible.If the person can also provide wid the documentation of the same project that will be great.In case if no documentation is avail no rpblem,main is teh project.Please....
COOKIE
|
|
|
|
|
This site is full of projects with source code!!!
Checkout C++/MFC section.
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Sure! Lets see, select file->new->projects->Win32 Console Application and follow the prompts. You now have VC++ source code that is as simple as possible.
Sorry, but you need to be more specific as to your requirements. There are hundreds of articles at CP and a great many of them cover what you are looking for. Even if you went to the CP home page and clicked a link at random along the left edge of the screen, the odds are good that you will hit a link that meets your requirments.
INTP
Every thing is relative...
|
|
|
|