View Full Version: Beginner needs help.

C++ Learning Community > win32 api C++ programming > Beginner needs help.


Title: Beginner needs help.
Description: C++ forms application, need help.


NeO - January 28, 2007 07:33 PM (GMT)
Hi people, I am new to C++ programming and am trying to create a small application.

I don't know where to start explaining here. Ok, the application is going to be a backup application, it will copy the contents of one folder to another folder. The source and destination paths need to be read in from an INI file. I am using CIniReader.h by Aisha Ikram CodeGuru page for this.

My winformsapp.cpp:

CODE
// winformsapp.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include "CIniReader.h"

using namespace winformsapp;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1());


CIniReader m_IniReader;
m_strINIFile = ".\backset.ini";
m_IniReader.setINIFileName (m_strINIFile);

return 0;
}


CIniReader.h:

CODE
#pragma once

//
// CIniReader- Header File
//
class CIniReader
{
public:
 // method to set INI file name, if not already specified
 void setINIFileName(CString strINIFile);

 // methods to return the lists of section data and section names
 CStringList* getSectionData(CString strSection);
 CStringList* getSectionNames();

 // check whether the section exists in the file
 BOOL sectionExists(CString strSection);

 // updates the key value, if key already exists,
 // else creates a key-value

pair
 long setKey(CString strValue, CString strKey,
             CString strSection);

 // give the key value for the specified key of a section
 CString getKeyValue(CString strKey,CString strSection);

 // default constructor
 CIniReader()
 {
   m_sectionList = new CStringList();
   m_sectionDataList = new CStringList();
 }

 CIniReader(CString strFile)
 {
   m_strFileName = strFile;
   m_sectionList = new CStringList();
   m_sectionDataList = new CStringList();
 }

 ~CIniReader()
 {
   delete m_sectionList;
   delete m_sectionDataList;
 }

private:
 // lists to keep sections and section data
 CStringList *m_sectionDataList;
 CStringList *m_sectionList;

 CString m_strSection;
 long m_lRetValue;

 // ini file name
 CString m_strFileName;
};



My main form currently has nothing related to the CIniReader.h or anything of that sort in it, merely a button which pops up a text box so i wont include it here for now.

First of all, how do I create an instance of the header file?

When I compile my project with those files I get 70 errors but the main cause seems to be the fact that the "m_strINIFile" at the bottom of the winformsapp.cpp isn't defined.

QUOTE
1>Compiling...
1>winformsapp.cpp
1><project path hidden>\winformsapp\CIniReader.h(10) : error C2061: syntax error : identifier 'CString'
1><project path hidden>\winformsapp\CIniReader.h(13) : error C2143: syntax error : missing ';' before '*'
1><project path hidden>\winformsapp\CIniReader.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(13) : error C2061: syntax error : identifier 'CString'
1><project path hidden>\winformsapp\CIniReader.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(13) : warning C4183: 'getSectionData': missing return type; assumed to be a member function returning 'int'
1><project path hidden>\winformsapp\CIniReader.h(14) : error C2143: syntax error : missing ';' before '*'
1><project path hidden>\winformsapp\CIniReader.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(14) : warning C4183: 'getSectionNames': missing return type; assumed to be a member function returning 'int'
1><project path hidden>\winformsapp\CIniReader.h(17) : error C2146: syntax error : missing ';' before identifier 'sectionExists'
1><project path hidden>\winformsapp\CIniReader.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(17) : error C2061: syntax error : identifier 'CString'
1><project path hidden>\winformsapp\CIniReader.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(17) : warning C4183: 'sectionExists': missing return type; assumed to be a member function returning 'int'
1><project path hidden>\winformsapp\CIniReader.h(23) : error C2144: syntax error : 'long' should be preceded by ';'
1><project path hidden>\winformsapp\CIniReader.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(23) : error C2061: syntax error : identifier 'CString'
1><project path hidden>\winformsapp\CIniReader.h(27) : error C2146: syntax error : missing ';' before identifier 'getKeyValue'
1><project path hidden>\winformsapp\CIniReader.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(27) : error C2061: syntax error : identifier 'CString'
1><project path hidden>\winformsapp\CIniReader.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(27) : warning C4183: 'getKeyValue': missing return type; assumed to be a member function returning 'int'
1><project path hidden>\winformsapp\CIniReader.h(36) : error C2146: syntax error : missing ')' before identifier 'strFile'
1><project path hidden>\winformsapp\CIniReader.h(36) : error C2146: syntax error : missing ';' before identifier 'strFile'
1><project path hidden>\winformsapp\CIniReader.h(36) : error C2460: 'CIniReader::CString' : uses 'CIniReader', which is being defined
1><project path hidden>\winformsapp\CIniReader.h(7) : see declaration of 'CIniReader'
1><project path hidden>\winformsapp\CIniReader.h(36) : error C2059: syntax error : ')'
1><project path hidden>\winformsapp\CIniReader.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(36) : error C2473: 'strFile' : looks like a function definition, but there is no parameter list.
1><project path hidden>\winformsapp\CIniReader.h(38) : error C2065: 'strFile' : undeclared identifier
1><project path hidden>\winformsapp\CIniReader.h(38) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(38) : error C2864: 'CIniReader::m_strFileName' : only static const integral data members can be initialized within a class
1><project path hidden>\winformsapp\CIniReader.h(39) : error C2061: syntax error : identifier 'CStringList'
1><project path hidden>\winformsapp\CIniReader.h(39) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(39) : error C2864: 'CIniReader::m_sectionList' : only static const integral data members can be initialized within a class
1><project path hidden>\winformsapp\CIniReader.h(40) : error C2061: syntax error : identifier 'CStringList'
1><project path hidden>\winformsapp\CIniReader.h(40) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(40) : error C2864: 'CIniReader::m_sectionDataList' : only static const integral data members can be initialized within a class
1><project path hidden>\winformsapp\CIniReader.h(43) : error C2588: '::~CIniReader' : illegal global destructor
1><project path hidden>\winformsapp\CIniReader.h(45) : error C2065: 'm_sectionList' : undeclared identifier
1><project path hidden>\winformsapp\CIniReader.h(45) : error C2541: 'delete' : cannot delete objects that are not pointers
1><project path hidden>\winformsapp\CIniReader.h(46) : error C2065: 'm_sectionDataList' : undeclared identifier
1><project path hidden>\winformsapp\CIniReader.h(46) : error C2541: 'delete' : cannot delete objects that are not pointers
1><project path hidden>\winformsapp\CIniReader.h(32) : error C2061: syntax error : identifier 'CStringList'
1><project path hidden>\winformsapp\CIniReader.h(33) : error C2061: syntax error : identifier 'CStringList'
1><project path hidden>\winformsapp\CIniReader.h(51) : error C2143: syntax error : missing ';' before '*'
1><project path hidden>\winformsapp\CIniReader.h(51) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(51) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(51) : error C2040: 'm_sectionDataList' : 'int *' differs in levels of indirection from ''unknown-type''
1><project path hidden>\winformsapp\CIniReader.h(52) : error C2143: syntax error : missing ';' before '*'
1><project path hidden>\winformsapp\CIniReader.h(52) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(52) : error C2086: 'int CStringList' : redefinition
1><project path hidden>\winformsapp\CIniReader.h(51) : see declaration of 'CStringList'
1><project path hidden>\winformsapp\CIniReader.h(52) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(52) : error C2040: 'm_sectionList' : 'int *' differs in levels of indirection from ''unknown-type''
1><project path hidden>\winformsapp\CIniReader.h(54) : error C2146: syntax error : missing ';' before identifier 'm_strSection'
1><project path hidden>\winformsapp\CIniReader.h(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(58) : error C2146: syntax error : missing ';' before identifier 'm_strFileName'
1><project path hidden>\winformsapp\CIniReader.h(58) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(58) : error C2086: 'int CString' : redefinition
1><project path hidden>\winformsapp\CIniReader.h(54) : see declaration of 'CString'
1><project path hidden>\winformsapp\CIniReader.h(58) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1><project path hidden>\winformsapp\CIniReader.h(59) : error C2059: syntax error : '}'
1><project path hidden>\winformsapp\CIniReader.h(59) : error C2143: syntax error : missing ';' before '}'
1><project path hidden>\winformsapp\CIniReader.h(59) : error C2059: syntax error : '}'
1>.\winformsapp.cpp(21) : error C2146: syntax error : missing ';' before identifier 'm_IniReader'
1>.\winformsapp.cpp(21) : warning C4551: function call missing argument list
1>.\winformsapp.cpp(21) : error C2065: 'm_IniReader' : undeclared identifier
1>.\winformsapp.cpp(22) : error C2065: 'm_strINIFile' : undeclared identifier
1>.\winformsapp.cpp(23) : error C2228: left of '.setINIFileName' must have class/struct/union
1>        type is ''unknown-type''


I have tried defining this as a string but that doesnt seem to help, any ideas? Thanks



adeyblue - January 29, 2007 12:26 AM (GMT)
Most of those errors are because CString isn't defined. CString is an MFC datatype (I'm guessing this is the MFC version, almost everybody who makes their own string class calls it CString) so you'll have to include stdafx.h and afxwin.h at the top of CIniReader.h

Note that if you're using Visual C++ 2005 Express Edition, you can't readily use MFC so you'll have to find something else to use.

NeO - January 29, 2007 12:30 AM (GMT)
I'm using Visual Studio 2005. Apparently I'm using the wrong type of app, mine apparently is a .NET and i should be using MFC? How do i do this differently?

adeyblue - January 29, 2007 11:31 AM (GMT)
In plain C/C++ you can use the functions GetPrivateProfileString and friends (http://msdn2.microsoft.com/en-us/library/ms724353.aspx). As for MFC or .Net, there might be more convenient functions but I've no idea, I've never used them.

If you don't have to use an INI-style file though, then why not just write the source and destination paths to a file and read them back, you don't have to do any major parsing that way.




Hosted for free by InvisionFree