(C++) Class for reading Windows-INI-like files

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
xray
Posts: 231
Joined: Fri Feb 02, 2007 1:06 pm
Location: Germany, Munich
Contact:

Post by xray »

Nothing is perfect!

By the way really nice class, thanks for sharing with us!

And I recommend modifying getValueB method that it also recognize also integer 1/0 as true/false.

cheers
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

how the hell do you make this thing work.

I keep getting linker errors from a couple ini functions and I tried to include it every way I know how.. including how the website describes.

yet I can't shake these damn linker errors... any ideas??
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Midnight wrote:how the hell do you make this thing work.

I keep getting linker errors from a couple ini functions and I tried to include it every way I know how.. including how the website describes.

yet I can't shake these damn linker errors... any ideas??
Hmm quite possibly could we get some code, or possibly just a .zip to download your work environment. And possibly an explanation of those linker errors you are getting. Or even better the exact linker errors copied from your IDE's console window. Thanks.
TheQuestion = 2B || !2B
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

well the code is the example on the website

the errors where with addsomething.. but it's how I'm linking I think.

I've tried #pragma.. I've tried adding inireader.lib as a dependancy.. you know the spot where irrlicht examples does irrlicht.lib.. I've tried without that also and just include the folder like irrlicht.

I've tried adding inireader.h and not adding it.. I've tried it all.

I'm using msvc express 2005.

seem to have misplaced my code I'll post again if needed when i find it.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

IIRC the examples are full of typos. Just go line by line check every method call is calling the right method, e.g Add / add etc..
Or post the errors you get and the code that's causing it.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

1>MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strncmp already defined in LIBCMT.lib(strncmp.obj)
1>MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _atoi already defined in LIBCMT.lib(atox.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
these are the current errors.. I must have changed something it was something to do with getValue2Di or something before. going to try some other linker setups and see if I can get back to that point.

what is the proper way to link it though? #pragma?
additional dependancies?
do i include inireader in my project?
the website isn't very descriptive.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

damn the lag sometimes is unbearable..

anyways I removed all except for the folder include and iinireader.h
and this is what i got.
1>Main.obj : error LNK2019: unresolved external symbol "public: class irr::core::dimension2d<int> __thiscall irr::io::IIniFileReader::SValue2Di::toDimension(void)" (?toDimension@SValue2Di@IIniFileReader@io@irr@@QAE?AV?$dimension2d@H@core@4@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "class irr::io::IIniFileReader * __cdecl irr::io::createIniFileReader(char const *,bool)" (?createIniFileReader@io@irr@@YAPAVIIniFileReader@12@PBD_N@Z) referenced in function _main
I don't really see any typo's in the code but I haven't gone over it all.. I'm using version 2.1 so I'm assuming thats the one with all the known fixes?

I check one typo report myself and the code matched so what else is there and why hasn't it been updated?
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

If I understand this linker error right you haven't linked the Irrlicht.lib.

Code: Select all

#pragma comment(lib, "Irrlicht.lib")
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

and yet I have it right there

Code: Select all

#include <Irrlicht.h>
#include <IIniFileReader.h>
 
using namespace irr;
using namespace io;
using namespace video;

#pragma comment(lib,"Irrlicht.lib")
//#pragma comment(lib,"IniReader.lib")
 
int main(int argc, char** argv)
{
	irr::io::IIniFileReader* ini = createIniFileReader("Config.ini");
 /*
	if(!ini->load())
	{
		ini->drop();
 
		// First we create an empty INI-File reader
		ini = createIniFileReaderEmpty();
 
		// now we fill the class with our default data
 
		// first we create the section device
		ini->addSection("device");
		// and than we create the keys and assign them standard values
		ini->addKeyToSection("device","antialias","true");
		ini->addKeyToSection("device","bits","32");
		ini->addKeyToSection("device","resolution","800x600");
		ini->addKeyToSection("device","stencil","true");
		ini->addKeyToSection("device","vsync","false");
		ini->addKeyToSection("device","driver","edt_opengl");
 
		// since our INI-File reader object is only stored in memory we
		// have to save it to a file.
		// to do so we first need to set a filename where to save
		ini->setSaveFileName("Config.ini");
 
		if(!ini->save())
		{
			ini->drop();
			return 1;
		}
	}
 */
	irr::SIrrlichtCreationParameters param;
 
	param.AntiAlias = ini->getValueB("device","antialias");
	param.Bits = ini->getValueI("device","bits");
	param.Fullscreen = ini->getValueB("device","fullscreen");
	param.Stencilbuffer = ini->getValueB("device","stencil");
	param.Vsync = ini->getValueB("device","vsync");
	param.WindowSize = ini->getValue2Di("device","resolution").toDimension();
	param.DriverType = ini->getValueDrv("device","driver");
 
	irr::IrrlichtDevice* device = createDeviceEx(param);
 



/*	irr::IrrlichtDevice* device = irr::createDevice(irr::video::EDT_DIRECT3D9, irr::core::dimension2d<irr::s32>(800, 600), 16, false, false, false);
*/
	irr::video::IVideoDriver* driver = device->getVideoDriver();

	while(device->run())
	{
		//all engine rendering should happen here
		if (device->isWindowActive())
		{
			driver->beginScene(true, true, irr::video::SColor(0,0,0,0));
			driver->endScene();

		}

	}


	//ini->drop();
	device->closeDevice();
	device->drop();
 
	return 0;
}
EDIT: and i just noticed i had ini->drop commented
on rebuild

Code: Select all

1>Main.obj : error LNK2019: unresolved external symbol "public: class irr::core::dimension2d<int> __thiscall irr::io::IIniFileReader::SValue2Di::toDimension(void)" (?toDimension@SValue2Di@IIniFileReader@io@irr@@QAE?AV?$dimension2d@H@core@4@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "class irr::io::IIniFileReader * __cdecl irr::io::createIniFileReader(char const *,bool)" (?createIniFileReader@io@irr@@YAPAVIIniFileReader@12@PBD_N@Z) referenced in function _main
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

The tutorials were full of typos. After MasterGod told me they were I fixed them.

The last two linker errors occur because you didn't link with inireader.lib.
If you set the dependencies it work fine for me.

Have you tried to set the Runtime Library to the same as your application uses?

The MSCV Projectfile that comes with the SDK is using Multithreaded (Debug) DLL. Try to set it to Multithreaded (Debug) if your application uses this runtime.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

1.

Code: Select all

//#pragma comment(lib,"IniReader.lib") 
Why comment?
2. Try not using it as an external lib, try adding all the source files (.h && .cpp) to the project and see if that helps.

P.S
If you try option #2 don't forget to remove that #pragma comment line.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

bug:

Code: Select all

	CIniFileReaderStub::SValue3Di CIniFileReaderStub::getValue3Di(const c8* section, const c8 *key)
	{
		stringc str = getValue(section,key);
		str.replace('x',' ');

		SValue3Di v;
		sscanf(str.c_str(),"%d %d %d",&v.Y,&v.Y,v.Z);
		return v;
	}
replace

Code: Select all

sscanf(str.c_str(),"%d %d %d",&v.Y,&v.Y,v.Z);
with
sscanf(str.c_str(),"%d %d %d",&v.X,&v.Y,&v.Z);
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

ok so... after installing directx and rebuilding irrlicht in debug to be sure and doing all the fixes i noticed on this thread.. it compiles without error.

however when it runs it loads the first two console lines irrlicht prints out about the OS and hangs.. I'm assuming it's hanging on the createfilereader part but I'm not sure.

also I included it directly into my project to achieve this.

I'm going to try rebuilding the library with the fixes and see if that works possibly. also I forgot to mention I'm using irr 1.4

has anyone else gotten this to work with msvce2005?
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

As you can see I have a long history with this code so yeah, I was able to compile it with vc8 and now that I use vc9 it compiles just fine too.
I used v1.4 and now latest revision and it works well with both versions of Irrlicht.
It also compiles on Linux and runs well so no problems there nor warnings after that last bug report few posts up.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

I'm not really sure what all thats supposed to mean.

could have tried answering my question about the linker settings but whatever I've moved on to using the engine.
Post Reply