home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / C Internet Config / Examples ƒ / Example / CExample.c next >
Encoding:
C/C++ Source or Header  |  1995-12-06  |  2.2 KB  |  102 lines  |  [TEXT/SPM ]

  1. #include <stdio.h>
  2.  
  3. #include <Types.h>
  4. #include <Files.h>
  5. #include <Folders.h>
  6. #include <Components.h>
  7.  
  8. #ifndef THINK_C
  9. #include <Strings.h>
  10. #endif
  11.  
  12. #include "IC Types.h"
  13. #include "IC API.h"
  14. #include "IC Keys.h"
  15. #include "IC Component API.h"
  16. #include "IC Component Selectors.h"
  17. #include "IC Component Utils.h"
  18.  
  19. void DumpPrefs(void);
  20.  
  21. ICInstance inst;
  22.  
  23. int main(void);
  24. int main(void){
  25.     ICError err;
  26.     ICDirSpecArray folder_spec;
  27.     Str255 email_address;
  28.     long attr;
  29.     long size;
  30.     long seed;
  31.     short vref;
  32.     long dirid;
  33.     ComponentInstance ci;
  34.     
  35.     printf("Internet Config: C Example\n\n");
  36.     
  37.     // ICDisableComponent();
  38.     ICDisableLinkedCode();
  39.     
  40.     err = ICStart(&inst, 'CREA');            /* tell it your application creator */
  41.     printf("ICStart: %ld\n", err);
  42.     
  43.     printf("ICUsingComponent: %s\n",ICUsingComponent(inst)?"true":"false");
  44.     
  45.     if (ICUsingComponent(inst)){
  46.         long ver;
  47.         err=ICGetComponentInstance(inst,(Ptr*)&ci);
  48.         
  49.         if (err==noErr){
  50.             ver=GetComponentVersion(ci);
  51.             printf("Vers is %ld (%lx)\n",ver,ver);
  52.         } else
  53.             printf("Get inst error %ld\n",err);
  54.     }
  55.     
  56.     FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&vref,&dirid);
  57.     
  58.     folder_spec[0].vRefNum = vref;                                /* search for prefs in root of the system */
  59.     folder_spec[0].dirID = dirid;                                    /* volume, obviously you'd use other things */
  60.     err = ICFindConfigFile(inst, 1, (ICDirSpecArrayPtr) &folder_spec);
  61.     printf("ICFindConfigFile: %ld\n", err);
  62.  
  63.     err = ICBegin(inst, icReadWritePerm);
  64.     printf("ICBegin: %ld %#lx\n", err,err);
  65.     size = sizeof(email_address);
  66.     err = ICGetPref(inst, "\pEmail", &attr, (Ptr) email_address, &size);
  67.     printf("ICGetPref: %ld\n", err);
  68.     
  69.     p2cstr(email_address);
  70.     printf("Your Email address is %s\n", email_address);
  71.     DumpPrefs();
  72.     err = ICEnd(inst);
  73.     printf("ICEnd: %ld\n", err);
  74.  
  75.     err = ICGetSeed(inst, &seed);
  76.     printf("ICGetSeed: %ld = %ld\n", err, seed);
  77.     /* now monitor this seed to see if any preferences have changed */
  78.  
  79.     err = ICStop(inst);
  80.     printf("ICStop: %ld\n", err);
  81.     
  82.     fflush(stdout);
  83.     
  84.     return 0;
  85. }
  86.  
  87. void DumpPrefs()
  88. {
  89.     ICError err;
  90.     long count;
  91.     long i;
  92.     Str255 key;
  93.     
  94.     err = ICCountPref(inst, &count);
  95.     printf("ICCountPref: %ld\n", err);
  96.     for (i = 1; i <= count; i++) {
  97.         err = ICGetIndPref(inst, i, key);
  98.         p2cstr(key);
  99.         printf("  ICGetIndPref: %ld - %s\n", err, &key);
  100.     };
  101. }
  102.