Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++]Reading data from .ini
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Mon Jan 21, 2008 12:12 pm    Post subject: [C++]Reading data from .ini Reply with quote

OK, I have a .ini file called Settings.ini and in it saids

Code:

[Positions]
X = 100
Y = 200


And I try to use this code

Code:

#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
   UINT X;
   UINT Y;
   X = GetPrivateProfileInt("Positions","X",1000,"Settings.ini");

   cout << "X is " << X;

   system("pause");
   return 0;
}


I keep getting this error. Can someone please help.

Code:
.\test.cpp(9) : error C2664: 'GetPrivateProfileIntW' : cannot convert parameter 1 from 'const char [10]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Mon Jan 21, 2008 12:40 pm    Post subject: Reply with quote

X = GetPrivateProfileInt(L"Positions",L"X",1000,L"Settings.ini");
Back to top
View user's profile Send private message
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Mon Jan 21, 2008 12:41 pm    Post subject: Reply with quote

Don't use Unicode. If you plan too, typecast.

Otherwise, just change the project settings to Multi-byte.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Jan 21, 2008 1:21 pm    Post subject: Reply with quote

You have your character set in the compiler options to unicode. If you are going to continue using unicode you can either use the TEXT( ) macro, or use the L macro for your strings:

So instead of:
"Positions"

Use:
TEXT("Positions")
Or
L"Positions"

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Mon Jan 21, 2008 2:00 pm    Post subject: Reply with quote

Thanks appalsap, adding L in front of everything does anke it work. But for some reason, it keeps saying X is 1000. That means either it can't find X or read it in the .ini. I've put the Settings.ini in the same folder as the program, but it still says X is 1000. What am I doing wrong?

I have a feeling it is going to be a very simple answer that I don't know...

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 21, 2008 3:13 pm    Post subject: Reply with quote

lpFileName

The name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.


You need to give a full file path. Put the settings.ini in Windows directory and see if it works...

"Note This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry."

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Mon Jan 21, 2008 3:22 pm    Post subject: Reply with quote

blankrider wrote:
"Note This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry."


Why are INI files deprecated in favor of the registry?
Back to top
View user's profile Send private message
mer0x
Advanced Cheater
Reputation: 0

Joined: 06 Jan 2008
Posts: 63

PostPosted: Mon Jan 21, 2008 5:38 pm    Post subject: Reply with quote

Code:

DWORD ReadKey( LPCTSTR szSection, LPCSTR szKey, LPTSTR szReturnString ){

   LPCTSTR APPNAME = "\resources.ini";
   GetPrivateProfileString(szSection,szKey,0,szReturnString,255, APPNAME);
   return true;

}
Back to top
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Mon Jan 21, 2008 8:58 pm    Post subject: Reply with quote

I don't want to type (below)

Code:
C:\\Documents and Settings\\Desktop\\Other stuff\\Blah\\Blah\\Blah


over and over again.


Can someone teach me how to use this code (below)

Code:
DWORD WINAPI GetCurrentDirectory(
  __in   DWORD nBufferLength,
  __out  LPTSTR lpBuffer
);


Can someone give me an example of it, I have no idea what this is saying right now.

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 21, 2008 9:18 pm    Post subject: Reply with quote

LPTSTR cOutputFolder = NULL;

if(GetCurrentDirectory(sizeof(cOutputFolder), cOutputFolder) = 0)
//error

else{
//the cOutputFolder has the string of the folder
}

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jan 22, 2008 6:04 am    Post subject: Reply with quote

blankrider wrote:
LPTSTR cOutputFolder = NULL;

if(GetCurrentDirectory(sizeof(cOutputFolder), cOutputFolder) = 0)
//error

else{
//the cOutputFolder has the string of the folder
}


Couple of errors with your code, you are trying to set GetCurrentDirectory to 0 instead of comparing it. You forgot the first set of braces { } for the if statement as well. Along with that you are using sizeof() on an undefined size array. The sizeof() in this case will return 4 because LPTSTR is a pointer to a string. Instead, you should write it like:

Code:
   TCHAR tszCurrentDirectory[MAX_PATH] = {0};
   if( GetCurrentDirectory( sizeof(tszCurrentDirectory), tszCurrentDirectory ) == 0 ){
      // Success
   }else{
      // Error
   }

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Tue Jan 22, 2008 6:08 am    Post subject: Reply with quote

and since the first parameter of GetCurrentDirectory is the length of the buffer of the current directory in TCHARs it should be

Code:

(sizeof(tszCurrentDirectory)/sizeof(tszCurrentDirectory[0]))


Last edited by appalsap on Tue Jan 22, 2008 6:29 am; edited 1 time in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jan 22, 2008 6:18 am    Post subject: Reply with quote

appalsap wrote:
and since the first parameter of [i]GetCurrentDirectory[i] is the length of the buffer of the current directory in TCHARs it should be

Code:

(sizeof(tszCurrentDirectory)/sizeof(tszCurrentDirectory[0]))


Whoops forgot to change that. Alternatively you could also use the _ARRAYSIZE macro for that.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Tue Jan 22, 2008 6:33 am    Post subject: Reply with quote

Wiccan in C++ you odnt need the {} after a 1 line if

if(A!=B)
MessageBox(0, "Error", "Error", MB_OK);
else
//some other 1 line thing



that would run, you only need {} with multi line conditionals

_________________
Back to top
View user's profile Send private message
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Tue Jan 22, 2008 6:40 am    Post subject: Reply with quote

blankrider wrote:
Wiccan in C++ you odnt need the {} after a 1 line if

if(A!=B)
MessageBox(0, "Error", "Error", MB_OK);
else
//some other 1 line thing



that would run, you only need {} with multi line conditionals
Yes, but if you check Wiccaan's code, he allows the user to input their own code in between the brackets, which could be more than one line of code.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites