Categories

CODE
Visual C++ Programming
C++ (Non Visual C++ Issues)
Modern Windows Apps (Metro)
C++ and WinAPI
Managed C++ and C++/CLI
Visual C++ Bugs & Fixes
Graphics Programming
Multithreading
Network Programming
Driver Development
Visual Basic 6.0 Programming
Visual Basic .NET
Crystal Reports
C-Sharp Programming
Managed C++
Visual Basic .NET
ASP.NET
.NET Framework
ADO.NET
Windows Presentation Foundation (WPF) & XAML forum
Silverlight
.NET Installation and Configuration Issues
Java Programming
AJAX
Scripting - Client Side
Database
XML
Wireless/Mobile Development
Assembly
Scripting - Server Side (PHP, Perl, etc.)
Python
General Developer Topics
Project Planning, Design, and Management
Testers and Testing
Algorithms & Data Structures
General Discussion / Chit Chat
Announcements, Press Releases, & News
Feedback
Articles Suggestions
Testing Area
Programming Projects
C# Game(s) Project
Game Engine Project
C++ Coding Project
Project: Code War
Slow Chat: Talk with Microsoft Developer Teams
Slow Chat: Developing Multithreaded Applications
Slow Chat: C++0x
Slow Chat: Visual C++: Yesterday, Today, and Tomorrow
Directory Services
General Windows and DNA Programming
Windows OS Issues
Open Positions (Jobs)
Looking for Work
Visual Basic .NET FAQs
Visual Basic FAQs
CodeGuru Individual FAQs
CodeGuru Individual Visual Basic FAQs

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Visual C++ Programming

Ask questions about Windows programming with Visual C++ and help others by answering their questions.

Getting data from .ini file


Hi all,    In my application i need to to save data permanently in the sytem  to retrieve the data.  for that i am using ini file.    Here i am facing problem in getting the data    My ini file contains   [Project Name]  version = 1.0.0.45  company = XYZ    i wrote code like this to retrieve the data    GetPrivateProfileString("Project Name","version",sReturnValue,20,"C:\tis\projectsettings.ini");    but unable to get the output ,giving access violation error.    could any one pls help me to come out of this.      Thanks    tis  				  			

  				  					Most possible you did not allocate sReturnValue buffer.  				  			

  				  					You must use it like this:      	Code:  	// Declare variables  CString sBuffer, sResult;    // Read data  GetPrivateProfileString("Project name", "version", sBuffer.GetBuffer(20), 20, "C:\tis\projectsettings.ini");  sResult = sBuffer.GetBuffer(sBuffer.GetLength());  sBuffer.ReleaseBuffer();     				  			

  				  					  	  		  			  			  				  					 Originally Posted by Tischnoetentoet  					  				  				  	Code:  	// Declare variables  CString sBuffer, sResult;    // Read data  GetPrivateProfileString("Project name", "version", sBuffer.GetBuffer(20), 20, "C:\tis\projectsettings.ini");  sResult = sBuffer.GetBuffer(sBuffer.GetLength());  sBuffer.ReleaseBuffer();    			  		  	   I would rather suggest...    	Code:  	CString sBuffer;    // Read data  GetPrivateProfileString("Project name", "version", sBuffer.GetBuffer(20), 20, "C:\tis\projectsettings.ini");  sBuffer.ReleaseBuffer();   Basically no need to copy the string...   				  			

  				  					Thank you very much it is working. As Andreas suggestion when i release the buffer i am getting Assertion Failure. Could you please help me out why i am getting this failure.  				  			

  				  					  	  		  			  			  				  					 Originally Posted by tis707  					  				  				Thank you very much it is working. As Andreas suggestion when i release the buffer i am getting Assertion Failure. Could you please help me out why i am getting this failure.  			  		  	   Sorry that was my fault...pass the number of copied characters to 'ReleaseBuffer()"...    	Code:  	CString sBuffer;    // Read data  DWORD characters = GetPrivateProfileString("Project name", "version", sBuffer.GetBuffer(20), 20, "C:\\tis\\projectsettings.ini");  sBuffer.ReleaseBuffer(characters);   Also note that this function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry.  				  			

  				  					i think you need two backslashes:      "C:\\tis\\projectsettings.ini"  				  			

  				  					  	  		  			  			  				  					 Originally Posted by kkez  					  				  				i think you need two backslashes:  			  		  	   That is another thing I missed...


Related Links

runs in visual but not command
Programming mouse and keyboard events
How to change HighLight style of CImageList
GetItemData() problem
Bytes Generation
How to append the contents to the existing file usign SDK API
Can not add two pointers
Controlling the slider control
Disabling Escape key in MFC application
Adding driver data to two ListBoxes question
How to log errors from a bat file
CreateFileMapping and security
Urgent Help
Using InvokeHelper on ImageList Control
How declare global variables
CFile Using a relative path in Ctor