Results 1 to 18 of 18

Thread: WritePrivateProfileString

  1. #1

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335

    WritePrivateProfileString

    Im trying to make a ini file by using the below code but i get this error:
    VB Code:
    1. [B]E:\Program Files\Microsoft Visual Studio\MyProjects\ini\main.cpp(11) : error C2065: 'WritePrivateProfileString' : undeclared identifier[/B]
    VB Code:
    1. #include <iostream>
    2. #include <stdio.h>
    3.  
    4.  
    5. using namespace std;
    6.  
    7. int main(int nArgs, char** vArgs)
    8. {
    9. cout << "Making C:\\test.ini \n";
    10.  
    11. WritePrivateProfileString ("Section","Keyname","Value","C:\\test.ini");
    12.  
    13. return 0;
    14. }
    - 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/

  2. #2
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    WritePrivateProfileString is an API function. You forgot to include <windows.h>

    By the way, INI files are depreciated. Use registry instead.
    VS.NET 2003

    Need to email me?

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    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/

  5. #5

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    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/

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  7. #7

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    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/

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  9. #9

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    i was trying to do this
    VB Code:
    1. LPTSTR vPath ;
    2. GetModuleFileName(NULL,vPath,255);
    3.  
    4. 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/

  10. #10

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    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/

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  12. #12

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    ok cool i used
    VB Code:
    1. 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/

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  14. #14

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    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/

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  16. #16

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    ok i got it like:
    VB Code:
    1. char drive[_MAX_DRIVE];
    2.    char dir[_MAX_DIR];
    3.    char fname[_MAX_FNAME];
    4.    char ext[_MAX_EXT];
    5.  
    6. _splitpath( vArgs[0], drive, dir, fname, ext );
    7.  cout <<"\n\n";
    8.  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/

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  18. #18

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    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:
    1. #include <iostream>
    2. #include <stdio.h>
    3. #include <windows.h>
    4. #include <stdlib.h>
    5. #include <string>
    6. using namespace std;
    7.  
    8. int main(int nArgs, char **vArgs)
    9. {
    10.     //' cout << " Called As :\n" << vArgs[0] << "\n";
    11.     // 'gets the full path with filename of this program
    12.    char drive[_MAX_DRIVE];
    13.    char dir[_MAX_DIR];
    14.    char fname[_MAX_FNAME];
    15.    char ext[_MAX_EXT];
    16. // 'seperate char for each section of the filename & path
    17. _splitpath( vArgs[0], drive, dir, fname, ext );
    18. //'split the filename & path into 4
    19.  
    20. string s1(drive), s2(dir), s3;
    21. s3 = s1 + s2;
    22. //'combine the drive char and dir char into 1 string
    23.  
    24. string vIni1(s3), vIni2("test.ini"), vIni;
    25. vIni = vIni1 + vIni2;
    26. //'combine s3 which was the drive & dir chars, with "test.ini" to make
    27. //'the path for the ini
    28.  
    29. cout << "Making File:\n" << vIni;
    30. cout << "\n\n";
    31. //'show "Making File:"
    32. // 'and the filename ie: "c:\ini\test.ini"
    33.  
    34. const char *ptr1 = 0;
    35.    ptr1= vIni.data ( );
    36.    // 'convert the string into a char so i can use it with
    37.    // 'WritePrivateProfileString . WritePrivateProfileString doesnt except strings
    38.  
    39. WritePrivateProfileString ("Main","Path", vArgs[0], ptr1);
    40. //'write to a ini file which will be cerated by ptr1 (the filename)
    41. // '[Main]
    42. // 'Path=c:\ini\ini.exe
    43.  
    44. return 0;
    45. }
    - 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
  •  



Click Here to Expand Forum to Full Width