TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Doug Glenn
from: Peter Fitzsimmons
date: 1995-04-25 14:33:22
subject: Newbie code

DG>     I patched this togeather from the example code in the PMREF.

90% of the samples in the reference are pure junk.

For example:


  char  pszFileName[13];  /* user-profile file name               */
  strcpy(pszFileName,"PROFILE.INI");
  hini = PrfOpenProfile(hab,pszFileName);

I don't know about you,  but I see two lines of NOISE here.  Samples should
have as few lines as possible.  This is what it should be:

  hini = PrfOpenProfile(hab, "PROFILE.INI");

The problem with your code is that the HAB is not valid.  It is not valid
in the toolkit example (for PrfOpenProfile()),  so who can blame you.

I don't know which compiler you're using,  but you obviously don't have
many warnings turned on (or you are ignoring them -- don't ever ignore a
warning).  You are calling functions like strcpy() and printf() without
#including the appropriate header file.


 DG>     One last question. Do all the !{at}#$ variables _have_ to be in
 DG>     caps?

No;  I suspect this is a problem you are having with your compiler,  and/or
not #define'ing the corrent INCL_* constants.

Here's a working version;  something like this (with a main() and
everything) should be with each function in the API reference:

 #define INCL_WIN
 #include 
 #include 
 int main(void)
 {
     HINI hini;
     HAB hab;
     ULONG ulSize;
     BOOL b;

     hab = 0;    /* this is not documented,  but works with the Prf...()
                  * functions.  Usually,  you have to call WinInitialize(),
                  * which means you are a PM program. */

     hini = PrfOpenProfile(hab, "foo.ini");
     if(!hini){
         printf("Error - couldn't open foo.ini\n");
         return 1;
     }

     b = PrfQueryProfileSize(hini, "AppName", "Key",
&ulSize);
     if(!b)
         printf("error calling PrfQueryProfileSize (app/key not
defined?)\n");
     else
         printf("data len = %ld\n", ulSize);

     PrfCloseProfile(hini);
     return 0;
 }



--- Maximus/2 2.02p1
* Origin: Sol 3/Toronto (905)858-8488 (1:259/414)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 259/414 400 99 250/702 3615/50 396/1 270/101 105/103 42 712/515
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.