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 


Config.ini

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Euzinho Dassilva
Advanced Cheater
Reputation: 0

Joined: 08 Sep 2007
Posts: 62

PostPosted: Tue Oct 30, 2007 1:08 pm    Post subject: Config.ini Reply with quote

Hi,

Anyone knows how to create INI Files to config a system?

Like the (famous?) file config.ini, loaded at Application initialize with some instructions to config or determinate some actions to specific (or no) areas of the system, like positioning, window size, language file (if application supports) ...

Note: With Visual Basic

Note 2: I really want to learn and no only to know if anyone knows how to do.
Back to top
View user's profile Send private message  
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8580
Location: 127.0.0.1

PostPosted: Tue Oct 30, 2007 1:50 pm    Post subject: Reply with quote

Create a new module and add:

Code:
Option Explicit

'
' API Declarations
'
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long

'
' Global Defines
'
Global strINIFile As String


'
' ReadINI
' Reads A Value From An INI Section
'
Public Function ReadINI(Section, KeyName As String) As String
    Dim sRet As String
    sRet = String(255, Chr(0))
    ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), strINIFile))
End Function

'
' WriteINI
' Writes A Value To An INI Section
'
Public Function WriteINI(sSection As String, sKeyName As String, sNewString As String) As Integer
    Dim r
    r = WritePrivateProfileString(sSection, sKeyName, sNewString, strINIFile)
End Function


Then inside your function, such as a command button, you can use something like this:

Code:
Private Sub Command1_Click()

    '
    ' Set Path To INI File
    '
    strINIFile = App.Path & "\config.ini"

    '
    ' Read Value From INI File
    '
    Dim strReadValue As String
    strReadValue = ReadINI("section", "Key1")

    '
    ' Write New Value To INI
    '
    WriteINI "section", "Key1", "NewValue"

End Sub


Mind you this is a very basic way of doing this.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website  
Euzinho Dassilva
Advanced Cheater
Reputation: 0

Joined: 08 Sep 2007
Posts: 62

PostPosted: Thu Nov 01, 2007 12:45 pm    Post subject: Reply with quote

Well, thank you for answer, but the code have some errors listed by VB Express, look

And, about the example usage, I can read the configs on load and write with a click button?

Or both "methods" must be in same event, like _click?
Back to top
View user's profile Send private message  
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Nov 01, 2007 12:50 pm    Post subject: Reply with quote

You're using VB.net, take a look here

http://pinvoke.net/default.aspx/kernel32/WritePrivateProfileString.html

http://pinvoke.net/default.aspx/kernel32/GetPrivateProfileString.html
Back to top
View user's profile Send private message  
Euzinho Dassilva
Advanced Cheater
Reputation: 0

Joined: 08 Sep 2007
Posts: 62

PostPosted: Fri Nov 02, 2007 7:21 am    Post subject: Reply with quote

These example can be added in a normal .VB file? Or must be in a Module?
Back to top
View user's profile Send private message  
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8580
Location: 127.0.0.1

PostPosted: Fri Nov 02, 2007 8:08 am    Post subject: Reply with quote

Check out these classes for VB.NET:

http://www.codeproject.com/vb/net/INIFileClass.asp
http://www.codeproject.com/vb/net/VbNetClassIniFile.asp
http://www.codeproject.com/useritems/ini_File_Class_invbnet.asp

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website  
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Nov 02, 2007 9:40 am    Post subject: Reply with quote

http://nini.sourceforge.net/ is good.
Back to top
View user's profile Send private message  
Euzinho Dassilva
Advanced Cheater
Reputation: 0

Joined: 08 Sep 2007
Posts: 62

PostPosted: Sat Nov 03, 2007 4:54 am    Post subject: Reply with quote

Wiccaan, the second link that you post it's a fantastic class.

Thanks a lot, man. I'll +rep you for this help

The others answers are good too, but I believe be right +rep only one member, per topic, the member that really solved the question.
Back to top
View user's profile Send private message  
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8580
Location: 127.0.0.1

PostPosted: Sat Nov 03, 2007 4:56 am    Post subject: Reply with quote

Euzinho Dassilva wrote:
Wiccaan, the second link that you post it's a fantastic class.

Thanks a lot, man. I'll +rep you for this help

The others answers are good too, but I believe be right +rep only one member, per topic, the member that really solved the question.


Not a problem, glad I could help. Smile

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website  
Euzinho Dassilva
Advanced Cheater
Reputation: 0

Joined: 08 Sep 2007
Posts: 62

PostPosted: Sat Nov 03, 2007 7:36 am    Post subject: Reply with quote

Well, I decided to use the second link. But there is some problems when I save the config file. Many times I must delete manually the file to generate a new and updated config.ini.

You know if exists another class with these resources (or more) but more efficient in this aspects?
Back to top
View user's profile Send private message  
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8580
Location: 127.0.0.1

PostPosted: Sat Nov 03, 2007 7:52 am    Post subject: Reply with quote

Euzinho Dassilva wrote:
Well, I decided to use the second link. But there is some problems when I save the config file. Many times I must delete manually the file to generate a new and updated config.ini.

You know if exists another class with these resources (or more) but more efficient in this aspects?


The class should rewrite to the file if it exists. I'd say recheck the example code and make sure you are fully using the class correctly for opening and saving the file while editing it.

A few other examples:
http://www.mentalis.org/soft/class.qpx?id=6
http://www.developer.com/net/asp/article.php/3287991

If you still have issues, you could always use XML files instead as they are more of a standard now-adays when it comes to holding configuration information and such.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website  
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
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