PDA

Click to See Complete Forum and Search --> : Question for vb gurus


casparas
Jan 2nd, 2000, 10:11 PM
it's about week i'm programing with vb
and i know that there are some mystirious
API functions and i know that this api is
very usefull when working with .ini files and
registry(i'm right, ain't i?)

now what i need is the sample code
for storing and loading info from api file
with explanations PLEASE

Also Where could i find good api tutorial or something like that?

casparas
Jan 3rd, 2000, 01:54 AM
no no no no i mean how to use api to save,
load .ini files

Antonio Begue
Jan 3rd, 2000, 03:34 AM
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Public 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

'Create a project with:
3 text box
1 appname
2 Keyname
3 txtvalue

2 command buttons
1 cmdstore
2 cmdget


Private IniFileName As String

Private Sub cmdget_Click()
Dim Temp As String * 50
Dim lpAppName As String, lpKeyName As String, lpDefault As String, lpFileName As String

Dim ret As Long
lpAppName = appname.Text
lpKeyName = Keyname.Text
lpDefault = IniFileName
lpFileName = IniFileName

ret = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, Temp, Len(Temp), lpFileName)

If ret = 0 Then
Beep
Else
txtvalue.Text = Trim(Temp)
End If
End Sub

Private Sub cmdstore_Click()
Dim lpAppName As String, lpFileName As String, lpKeyName As String, lpString As String
Dim ret As Long
lpAppName = appname.Text
lpKeyName = Keyname.Text
lpString = txtvalue.Text
lpFileName = IniFileName
ret = WritePrivateProfileString(lpAppName, lpKeyName, lpString, lpFileName)

If ret = 0 Then
Beep
End If
End Sub


Private Sub Form_Load()
IniFileName = InputBox("Which file do you want to read/edit/create?")
If IniFileName = "" Then End
End Sub

casparas
Jan 3rd, 2000, 05:41 AM
Well i can say only one thing it's an alien language to me

(could anybody explain me this code, please :))

mwdelta
Jan 3rd, 2000, 07:57 AM
Here's a sample project that deals with ini files: http://www.vb-world.net/demos/ini/

There are lots of resources available at VB-World. Just do a search for "ini files" in "All VB-World" and you will find many pages.

------------------
Mike Wellems
PowerQuery

KENNNY
Jan 3rd, 2000, 08:05 AM
nooooo! dont use ini files, use the registry - much easier and more secure.
u dont even need to call api
look up :
GetSetting
SaveSetting
in msdn.


------------------
cintel rules :p
www.cintelsoftware.co.uk

LG
Jan 3rd, 2000, 08:06 AM
Hi,casparas.
Here is a link: http://visualbasic.miningco.com/library/weekly/aa121998.htm?id

Larisa

mhayenga
Jan 3rd, 2000, 10:56 AM
I saw this link a while back on a previous post(can't remember where)... It includes some good information.. It lists all of the API calls and gives examples of how to use them. http://skyscraper.fortunecity.com/transmission/45/api/index.html

Hope that helps...

Mitchell Hayenga
mitch@hayenga.com

Clunietp
Jan 3rd, 2000, 11:55 AM
Storing and loading info from API FILE??? What about the API viewer? That will show you all of the info you need (at least to start)

Jan 3rd, 2000, 12:17 PM
another helpful resource was originally introduced by Bruce McKinney(author of Hardcore VB); it's the win32 type library. He has since given up the development of this tlb to peet morris of TMS(The Mandelbrot Set) who, with his colleagues have taken the type library to a new level. The TLB and IDL source code(if you're in to writing type libraries) is freely downloadable here: http://www.themandelbrotset.com/html/typelib.html
...just drop it in your windows or system32 directory and then select it from projects>references in vb. it's very cool, very easy to use and encapsulates most of the win32api. I do wish however, that some of the other api's are added to the type library sometime soon.
pvb

Crazy D
Jan 3rd, 2000, 03:27 PM
Kenny: What's wrong with using ini files? Security is not an issue; windooz is not secure anyway, and secure info you want to save, you better not save with SaveSetting either. I like ini files.. their gone when the program is uninstalled, and the bigger the registry gets, the slower windooz gets (and after installing Visual Studio my registry is 10mb already...)

KENNNY
Jan 3rd, 2000, 06:30 PM
yeah, but reg is still a bit safer than using ini, and say some fool was playing around with files on a pc, and happened to delete the ini file your app needed? the person using your app wouldnt be too happy. whereas with reg, its unlikely someone qho doesnt know a lot will be bothered to go start>run>regedit
anyway u can delete your reg settings
also, it can be quite secure if u encrypt them too

------------------
cintel rules :p
www.cintelsoftware.co.uk

casparas
Jan 3rd, 2000, 07:34 PM
Thanx everyone

-Casparas

Jan 3rd, 2000, 10:27 PM
If you want really good code,go to the
Planet Source Code. It has source code for Visual Basic, Java and C++. Their site is...

www.planet-source-code.com (http://www.planet-source-code.com)

KENNNY
Jan 4th, 2000, 01:56 AM
except a lot of the code there doesnt work :(
and u have to spend 1/2hr fixing it

------------------
cintel rules :p
www.cintelsoftware.co.uk

erw
Jan 5th, 2000, 07:14 PM
So why are you a coder then ?
Just to copy somebody else his/her code without trying to find out how the code works ?

I see a lot of people who just copy some sourcecode and complain when it doesn't work even before they checked out themselve what things a really happening.

------------------