|
-
Jan 26th, 2003, 11:00 PM
#1
Thread Starter
Frenzied Member
WritePrivateProfileString
Im trying to make a ini file by using the below code but i get this error:
VB Code:
[B]E:\Program Files\Microsoft Visual Studio\MyProjects\ini\main.cpp(11) : error C2065: 'WritePrivateProfileString' : undeclared identifier[/B]
VB Code:
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int nArgs, char** vArgs)
{
cout << "Making C:\\test.ini \n";
WritePrivateProfileString ("Section","Keyname","Value","C:\\test.ini");
return 0;
}
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 07:44 AM
#2
Hyperactive Member
WritePrivateProfileString is an API function. You forgot to include <windows.h>
By the way, INI files are depreciated. Use registry instead.
-
Jan 27th, 2003, 12:02 PM
#3
deprecated, not depreciated , as parksie just explained to someone.
Anyway, I'd prefer some small app to write to a private ini file instead of cluttering up the registry.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 27th, 2003, 12:25 PM
#4
Thread Starter
Frenzied Member
i like the ini files because i input alot to the ini file and like CornedBee said i dont want to fill up the registry. Also a single ini file can be erased with a simple
kill "c:\\test.ini";
as with a registry you have to delete the entire folder or every string in it.
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 12:44 PM
#5
Thread Starter
Frenzied Member
also is there a way to get the exe filename ? Like the path?
in vb its App.Path
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 12:57 PM
#6
Monday Morning Lunatic
GetModuleFileName, and use the module handle for yourself that you were given in WinMain.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 27th, 2003, 01:17 PM
#7
Thread Starter
Frenzied Member
but how would i do this in a console then
do i just leave the module NULL?
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 01:20 PM
#8
Monday Morning Lunatic
Oh. In a console, it's argument 0, i.e. argv[0].
That gives the name it was *called* as, I believe.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 27th, 2003, 01:23 PM
#9
Thread Starter
Frenzied Member
i was trying to do this
VB Code:
LPTSTR vPath ;
GetModuleFileName(NULL,vPath,255);
cout << vPath;
but it dont work
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 01:23 PM
#10
Thread Starter
Frenzied Member
that didnt make much sense can you clear that up
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 01:26 PM
#11
Monday Morning Lunatic
An LPTSTR is just a pointer. You'd need to have TCHAR[255]; defined for it to work. I meant:
Code:
int main(int argc, char **argv) {
cout << "Called as: " << argv[0] << endl;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 27th, 2003, 01:34 PM
#12
Thread Starter
Frenzied Member
ok cool i used
VB Code:
cout << " Called As :\n" << vArgs[0] << "\n";
to get the full path and name like "C:\INI\Ini.exe".
Now how can i cut that up to get just "C:\INI" or "C:\INI\"
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 01:45 PM
#13
Monday Morning Lunatic
In Visual C++, there's the non-portable _tsplitpath function
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 27th, 2003, 01:49 PM
#14
Thread Starter
Frenzied Member
and i would include
<stdlib.h> right?
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 01:54 PM
#15
Monday Morning Lunatic
Include whatever header MSDN says to include.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 27th, 2003, 01:56 PM
#16
Thread Starter
Frenzied Member
ok i got it like:
VB Code:
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( vArgs[0], drive, dir, fname, ext );
cout <<"\n\n";
cout << drive << dir ;
Thanks Alot you and CornedBee helped alot. You guys should get like a new moderator status.
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 27th, 2003, 02:00 PM
#17
We're the mods at Galahtech. That's enough for me.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 27th, 2003, 02:51 PM
#18
Thread Starter
Frenzied Member
thank you parksie and CornedBee so much you're teaching me so much and i just wanted to post something i made with all the info you game me. mi going to of course incorparate this into a bigger program. I just posted this to show that you guys do help alot and i commented the code hopefully the right way so anyone can learn also . Thanks once again.
VB Code:
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main(int nArgs, char **vArgs)
{
//' cout << " Called As :\n" << vArgs[0] << "\n";
// 'gets the full path with filename of this program
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
// 'seperate char for each section of the filename & path
_splitpath( vArgs[0], drive, dir, fname, ext );
//'split the filename & path into 4
string s1(drive), s2(dir), s3;
s3 = s1 + s2;
//'combine the drive char and dir char into 1 string
string vIni1(s3), vIni2("test.ini"), vIni;
vIni = vIni1 + vIni2;
//'combine s3 which was the drive & dir chars, with "test.ini" to make
//'the path for the ini
cout << "Making File:\n" << vIni;
cout << "\n\n";
//'show "Making File:"
// 'and the filename ie: "c:\ini\test.ini"
const char *ptr1 = 0;
ptr1= vIni.data ( );
// 'convert the string into a char so i can use it with
// 'WritePrivateProfileString . WritePrivateProfileString doesnt except strings
WritePrivateProfileString ("Main","Path", vArgs[0], ptr1);
//'write to a ini file which will be cerated by ptr1 (the filename)
// '[Main]
// 'Path=c:\ini\ini.exe
return 0;
}
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|