home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1999 November / SOTMC_Nov1999-Ultimate.iso / mac / REALbasic ƒ / Plugins / Plugins SDK / x86dll_to_resource / dll_to_resource.c next >
Encoding:
C/C++ Source or Header  |  1999-02-16  |  1.1 KB  |  58 lines  |  [TEXT/CWIE]

  1. static void Initialize(void)
  2. {
  3.     InitGraf(&qd.thePort);
  4.     InitFonts();
  5.     InitWindows();
  6.     InitMenus();
  7.     TEInit();
  8.     InitDialogs(nil);
  9.     InitCursor();
  10. }
  11.  
  12. void main(void)
  13. {
  14.     StandardFileReply sfr;
  15.  
  16.     Initialize();
  17.  
  18.     StandardGetFile(nil, 1, (OSType *) "iDLL", &sfr);
  19.     if (sfr.sfGood)
  20.     {
  21.         short ph, rph;
  22.         Handle h;
  23.         long len;
  24.         FSSpec resourceSpec;
  25.         int pos;
  26.         int nameLen;
  27.  
  28.         if (noErr != FSpOpenDF(&sfr.sfFile, fsRdPerm, &ph))
  29.             return;
  30.         GetEOF(ph, &len);
  31.         nameLen = sfr.sfFile.name[0];
  32.         h = NewHandleClear(4 + 1 + nameLen + len);
  33.         if (!h)
  34.         {
  35.             FSClose(ph);
  36.             return;
  37.         }
  38.         HLock(h);
  39.         pos = 4;
  40.         BlockMoveData(sfr.sfFile.name, (*h) + pos, 1 + nameLen);
  41.         pos += 1 + nameLen;
  42.         FSRead(ph, &len, (*h) + pos);
  43.         FSClose(ph);
  44.  
  45.         FSMakeFSSpec(sfr.sfFile.vRefNum, sfr.sfFile.parID, "\pDLL resource", &resourceSpec);
  46.         FSpDelete(&resourceSpec);
  47.         FSpCreateResFile(&resourceSpec, 'RSED', 'rsrc', smSystemScript);
  48.         if (ResError() != noErr)
  49.             return;
  50.  
  51.         rph = FSpOpenResFile(&resourceSpec, fsRdWrPerm);
  52.         if (rph == -1)
  53.             return;
  54.         AddResource(h, 'PL86', 128, "\p");
  55.         CloseResFile(rph);
  56.     }
  57. }
  58.