home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / modsma.exe / MODSCMA.C next >
C/C++ Source or Header  |  1995-03-13  |  36KB  |  1,376 lines

  1. /****************************************************************************
  2. **    File:    MODSCMA.C
  3. **
  4. **    Desc:    This program designed to display the NDS Schema. It lists all of
  5. **            classes and the attributes associated with each class. Also 
  6. **            demonstrated is how to add this program to the NWAdmin "Tools"         
  7. **            menu.        
  8. **        
  9. **
  10. **        DISCLAIMER  
  11. **  
  12. **    Novell, Inc. makes no representations or warranties with respect to
  13. **    any NetWare software, and specifically disclaims any express or
  14. **    implied warranties of merchantability, title, or fitness for a
  15. **    particular purpose.  
  16. **
  17. **    Distribution of any NetWare software is forbidden without the
  18. **    express written consent of Novell, Inc.  Further, Novell reserves
  19. **    the right to discontinue distribution of any NetWare software.
  20. **    
  21. **    Novell is not responsible for lost profits or revenue, loss of use
  22. **    of the software, loss of data, costs of re-creating lost data, the
  23. **    cost of any substitute equipment or program, or claims by any party
  24. **    other than you.  Novell strongly recommends a backup be made before
  25. **    any software is installed.   Technical support for this software
  26. **    may be provided at the discretion of Novell.
  27. **
  28. **    Programmers:
  29. **
  30. **        Ini    Who                        Firm
  31. **        -----------------------------------------------------------------------
  32. **        KLB    Karl Bunnell                Novell Developer Support.
  33. **
  34. **    History:
  35. **
  36. **        When        Who    What
  37. **        -----------------------------------------------------------------------
  38. **        12-01-94    klb    First code.
  39. */
  40.  
  41. /****************************************************************************
  42. **    Include headers, macros, function prototypes, etc.
  43. */
  44.  
  45.     /*------------------------------------------------------------------------
  46.     **    ANSI
  47.     */
  48.     #include <windows.h>
  49.     #include <bwcc.h>
  50.     #include <toolhelp.h>
  51.     #include <string.h>
  52.     #include <stdio.h>
  53.    #include <stdlib.h>
  54.  
  55.     /*------------------------------------------------------------------------
  56.     **    NetWare
  57.     */
  58.     #include <nwnet.h>
  59.     #include <nwsnapin.h>
  60.     #include "modscma.h"
  61.  
  62.  
  63.     /*------------------------------------------------------------------------
  64.     **    Prototypes
  65.     */
  66.  
  67.     #ifdef __cplusplus
  68.     extern "C"
  69.     {
  70.     #endif
  71.  
  72.     BOOL FAR PASCAL _export ModSchemaDlgProc(HWND hDlg, UINT message, UINT wParam,
  73.                                     LONG lParam);
  74.     ReadAttributeInfo(HWND hDlg);
  75.     WORD ReadClassInfo(HWND hDlg);
  76.     N_EXTERN_LIBRARY( void ) ModSchemaMenuAction(void);
  77.     N_EXTERN_LIBRARY( void ) ModSchemaMenuValid(pnuint16 pFlags);
  78.     WORD CreateClass(HWND hDlg);
  79.     WORD ReadClassFlagInfo(HWND hDlg);
  80.     WORD ReadAttrFlagInfo(HWND hDlg);
  81.     WORD ReadSyntaxInfo(HWND hDlg);
  82.     WORD RemoveClassDefinition(HWND hDlg);
  83.     WORD RemoveAttributeDefinition(HWND hDlg);
  84.     WORD ModifyClass(HWND hDlg);
  85.     WORD CreateAttribute(HWND hDlg);
  86.     AttrClear(HWND hDlg);
  87.     ClassClear(HWND hDlg);
  88.     ClassResetComboBoxes(HWND hDlg);
  89.     AttrResetComboBoxes(HWND hDlg);
  90.     
  91.     #ifdef __cplusplus
  92.     }
  93.     #endif
  94.  
  95.     /*------------------------------------------------------------------------
  96.     **    Globals
  97.     */
  98.     HINSTANCE hDLL;
  99.     char      attrNameBuf[MAX_SCHEMA_NAME_BYTES];
  100.     char      classNameBuf[MAX_SCHEMA_NAME_BYTES];
  101.     
  102. //    int      superClassFlag = 0;
  103. //    int      superClassCount = 0;
  104.     
  105. /***************************************************************************
  106. **    DLL Entry Point
  107. */
  108. int FAR PASCAL LibMain (HINSTANCE hInstance, WORD wDataSeg, 
  109.                                 WORD cbHeapSize, LPSTR lpCmdLine)
  110. {
  111.     hDLL = hInstance;
  112.     if(cbHeapSize != 0)
  113.         UnlockData (0);
  114.     return 1;
  115. };
  116.  
  117. /***************************************************************************
  118. ** Function : InitSnapin(void)
  119. ** Description :                                                           
  120. **    Every Snapin DLL must provide this function. In this function,       
  121. **    snapin menu items (under Tools) are registered. Also, object procs   
  122. **    are registered.                                                      
  123. */                                                                         
  124. int _export FAR PASCAL InitSnapin()
  125. {
  126.     nuint16 ShowSchemaForm=0;
  127.  
  128.     BWCCRegister(hDLL);
  129.     /*-----------------------------------------------------------------------
  130.     ** Registering Menu Item                                    
  131.     */
  132.     NWARegisterMenu(
  133.     /* View Name      */  NWA_VIEW_BROWSER,      
  134.           /* Menu Parent ID */  0,
  135.           /* Menu Parent    */  NULL,
  136.           /* Menu Option    */  MF_STRING, 
  137.           /* Menu ID        */  &ShowSchemaForm,        
  138.           /* Menu String    */  "&Modify Schema",       
  139.           /* Menu Hint      */  "Add Schema Definitions",  
  140.           /* Menu Act. Proc */  ModSchemaMenuAction,  
  141.           /* Menu Valic Prc */  ModSchemaMenuValid,   
  142.           /* Snapin Version */  NWA_SNAPIN_VERSION
  143.     );   
  144.  
  145.  
  146.     return NWA_RET_SUCCESS;
  147. }
  148.  
  149. /******************************************************************************
  150. ** Function : ViewSchemaMenuAction(void)                                   
  151. ** Description :                                                           
  152. **    Menu Action Callback Proc for ViewSchemaAction
  153. */                        
  154. N_GLOBAL_LIBRARY( void ) _export
  155. ModSchemaMenuAction( void )
  156. {
  157.  HWND    hwnd;
  158.  MSG    msg;
  159.  static FARPROC lpfnModSchemaDlgProc;
  160.  
  161.  lpfnModSchemaDlgProc = MakeProcInstance((FARPROC)ModSchemaDlgProc, hDLL);
  162.  
  163. DialogBox(hDLL, "MODSCMA", GetActiveWindow(), lpfnModSchemaDlgProc);
  164.  
  165. FreeProcInstance(lpfnModSchemaDlgProc);
  166. }
  167.  
  168. /*******************************************************************************
  169. ** Function : ViewSchemaMenuValid(void)                                    
  170. ** Description :                                                           
  171. **   Menu Valid Callback Proc for  Menu                          
  172. */
  173. N_GLOBAL_LIBRARY( void ) _export
  174. ModSchemaMenuValid( pnuint16 pFlags )
  175. {
  176.     *pFlags=MF_ENABLED;
  177. }
  178.  
  179. BOOL FAR PASCAL _export ModSchemaDlgProc(HWND hDlg, UINT message, UINT wParam,
  180.                                     LONG lParam)
  181. {
  182.  WORD            n;
  183.  char            attrDefName[50];
  184.  char            flagName[40];
  185.  long            rval;
  186.  
  187.  switch(message)
  188.     {
  189.      case WM_INITDIALOG:
  190.  
  191.             ReadClassInfo(hDlg);
  192.             ReadAttributeInfo(hDlg);
  193.             ReadClassFlagInfo(hDlg);
  194.             ReadAttrFlagInfo(hDlg);
  195.             ReadSyntaxInfo(hDlg);
  196.             
  197.      SetFocus(GetDlgItem(hDlg, NEW_CLASS));
  198.      return FALSE;
  199.  
  200.      case WM_SYSCOMMAND:
  201.         if (wParam == SC_CLOSE)
  202.             {
  203.             EndDialog(hDlg, TRUE);
  204.             return TRUE;
  205.             }
  206.             
  207.      case WM_COMMAND:
  208.         switch(wParam)
  209.             {
  210.              case SUPER_CLASS:
  211.                                         break;
  212.  
  213.              case NAME_ATTR:
  214.                 if (HIWORD (lParam) == CBN_SELCHANGE)
  215.                     SetFocus(GetDlgItem(hDlg, SYNTAX));
  216.                                         break;
  217.                                         
  218.              case SYNTAX:
  219.                 if (HIWORD (lParam) == CBN_SELCHANGE)
  220.                     SetFocus(GetDlgItem(hDlg, FLAGS));
  221.                                         break;
  222.                                         
  223.              case CONTAINMENT:
  224.                 if (HIWORD (lParam) == CBN_SELCHANGE)
  225.                     {
  226.                     n = (WORD) SendDlgItemMessage(hDlg, CONTAINMENT,
  227.                       CB_GETCURSEL, 0, 0L);
  228.                       
  229.                     SendDlgItemMessage(hDlg, CONTAINMENT, CB_GETLBTEXT, n,
  230.                                 (LONG) (LPSTR) attrDefName);
  231.  
  232.                     if(strcmp(attrDefName, "\0") != 0)
  233.                         {
  234.                                 
  235.                         rval = SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_FINDSTRING, -1,
  236.                                     (LONG) (LPSTR) attrDefName);
  237.                         if (rval == LB_ERR)
  238.                             {
  239.                             SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_ADDSTRING, 0,
  240.                                     (LONG) (LPSTR) attrDefName);
  241.                                     
  242.                             SendDlgItemMessage(hDlg, CONTAINMENT, CB_SETCURSEL, 0, 0);
  243.                                                   
  244.                             }
  245.                         }
  246.                     }
  247.                                         break;
  248.                                 
  249.              case MANDATORY_ATTR:
  250.                 if (HIWORD (lParam) == CBN_SELCHANGE)
  251.                     {
  252.                     n = (WORD) SendDlgItemMessage(hDlg, MANDATORY_ATTR,
  253.                       CB_GETCURSEL, 0, 0L);
  254.                       
  255.                     SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_GETLBTEXT, n,
  256.                                 (LONG) (LPSTR) attrDefName);
  257.  
  258.                     if(strcmp(attrDefName, "\0") != 0)
  259.                         {
  260.                                 
  261.                         rval = SendDlgItemMessage(hDlg, MANDATORY_LB, LB_FINDSTRING, -1,
  262.                                     (LONG) (LPSTR) attrDefName);
  263.                         if (rval == LB_ERR)
  264.                             {
  265.                             SendDlgItemMessage(hDlg, MANDATORY_LB, LB_ADDSTRING, 0,
  266.                                     (LONG) (LPSTR) attrDefName);
  267.                                     
  268.                             SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_SETCURSEL, 0, 0);
  269.                                                   
  270.                             }
  271.                         }
  272.                     }
  273.                                         break;
  274.  
  275.  
  276.              case MANDATORY_LB:
  277.                 if (HIWORD (lParam) == LBN_DBLCLK)
  278.                     {
  279.                     n = (WORD) SendDlgItemMessage(hDlg, MANDATORY_LB,
  280.                       CB_GETCURSEL, 0, 0L);
  281.                       
  282.                     SendDlgItemMessage(hDlg, MANDATORY_LB, LB_DELETESTRING, n, 0);
  283.                     }
  284.                                         break;
  285.  
  286.              case OPTIONAL_LB:
  287.                 if (HIWORD (lParam) == LBN_DBLCLK)
  288.                     {
  289.                     n = (WORD) SendDlgItemMessage(hDlg, OPTIONAL_LB,
  290.                       CB_GETCURSEL, 0, 0L);
  291.                       
  292.                     SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_DELETESTRING, n, 0);
  293.                     }
  294.                     
  295.                                         break;
  296.  
  297.              case CONTAINMENT_LB:
  298.                 if (HIWORD (lParam) == LBN_DBLCLK)
  299.                     {
  300.                     n = (WORD) SendDlgItemMessage(hDlg, CONTAINMENT_LB,
  301.                       CB_GETCURSEL, 0, 0L);
  302.                       
  303.                     SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_DELETESTRING, n, 0);
  304.                     }
  305.                     
  306.                                         break;
  307.                                         
  308.              case CLASS_LB:
  309.                 if (HIWORD (lParam) == LBN_DBLCLK)
  310.                     {
  311.                     n = (WORD) SendDlgItemMessage(hDlg, CLASS_LB,
  312.                       CB_GETCURSEL, 0, 0L);
  313.                       
  314.                     SendDlgItemMessage(hDlg, CLASS_LB, LB_DELETESTRING, n, 0);
  315.                     }
  316.                                         break;
  317.  
  318.              case FLAGS_LB:
  319.                 if (HIWORD (lParam) == LBN_DBLCLK)
  320.                     {
  321.                     n = (WORD) SendDlgItemMessage(hDlg, FLAGS_LB,
  322.                       CB_GETCURSEL, 0, 0L);
  323.                       
  324.                     SendDlgItemMessage(hDlg, FLAGS_LB, LB_DELETESTRING, n, 0);
  325.                     }
  326.                                         break;
  327.                                         
  328.              case OPTIONAL_ATTR:
  329.                 if (HIWORD (lParam) == CBN_SELCHANGE)
  330.                     {
  331.                     n = (WORD) SendDlgItemMessage(hDlg, OPTIONAL_ATTR,
  332.                       CB_GETCURSEL, 0, 0L);
  333.                       
  334.                     SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_GETLBTEXT, n,
  335.                                 (LONG) (LPSTR) attrDefName);
  336.  
  337.                     if(strcmp(attrDefName, "\0") != 0)
  338.                         {
  339.                         rval = SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_FINDSTRING, -1,
  340.                                     (LONG) (LPSTR) attrDefName);
  341.                         if (rval == LB_ERR)
  342.                             {
  343.                             SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_ADDSTRING, 0,
  344.                                     (LONG) (LPSTR) attrDefName);
  345.  
  346.                             SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_SETCURSEL, 0, 0);
  347.                                     
  348.                             }
  349.                         }
  350.                     }
  351.                                         break;
  352.  
  353.              case CREATE_CLASS:
  354.                 CreateClass(hDlg);        
  355.                                         break;
  356.                                         
  357.              case CREATE_ATTR:
  358.                 CreateAttribute(hDlg);        
  359.                                         break;
  360.                                         
  361.              case MODIFY_CLASS:
  362.                 ModifyClass(hDlg);
  363.                                         break;
  364.  
  365.              case REMOVE_ATTR:
  366.                 RemoveAttributeDefinition(hDlg);
  367.                                         break;
  368.                                         
  369.              case REMOVE_CLASS:
  370.                 RemoveClassDefinition(hDlg);
  371.                                         break;
  372.                                         
  373.              case CLASS_FLAGS:
  374.                 if (HIWORD (lParam) == CBN_SELCHANGE)
  375.                     {
  376.                     n = (WORD) SendDlgItemMessage(hDlg, CLASS_FLAGS,
  377.                       CB_GETCURSEL, 0, 0L);
  378.                       
  379.                     SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_GETLBTEXT, n,
  380.                                 (LONG) (LPSTR) flagName);
  381.  
  382.                     if(strcmp(flagName, "\0") != 0)
  383.                         {
  384.                                 
  385.                         rval = SendDlgItemMessage(hDlg, CLASS_LB, LB_FINDSTRING, -1,
  386.                                     (LONG) (LPSTR) flagName);
  387.                         if (rval == LB_ERR)
  388.                             {
  389.                             SendDlgItemMessage(hDlg, CLASS_LB, LB_ADDSTRING, 0,
  390.                                     (LONG) (LPSTR) flagName);
  391.                             SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_SETCURSEL, 0, 0);
  392.                                     
  393.                             }
  394.                         }
  395.                     }
  396.                                         break;
  397.  
  398.              case FLAGS:
  399.                 if (HIWORD (lParam) == CBN_SELCHANGE)
  400.                     {
  401.                     n = (WORD) SendDlgItemMessage(hDlg, FLAGS,
  402.                       CB_GETCURSEL, 0, 0L);
  403.                       
  404.                     SendDlgItemMessage(hDlg, FLAGS, CB_GETLBTEXT, n,
  405.                                 (LONG) (LPSTR) flagName);
  406.  
  407.                     if(strcmp(flagName, "\0") != 0)
  408.                         {
  409.                                 
  410.                         rval = SendDlgItemMessage(hDlg, FLAGS_LB, LB_FINDSTRING, -1,
  411.                                     (LONG) (LPSTR) flagName);
  412.                         if (rval == LB_ERR)
  413.                             {
  414.                             SendDlgItemMessage(hDlg, FLAGS_LB, LB_ADDSTRING, 0,
  415.                                     (LONG) (LPSTR) flagName);
  416.                                     
  417.                             SendDlgItemMessage(hDlg, FLAGS, CB_SETCURSEL, 0, 0);
  418.                                     
  419.                             }
  420.                         }
  421.                     }
  422.                                         break;
  423.                                         
  424.             }
  425.                      break;
  426.     }
  427.  
  428.           return FALSE;
  429. }
  430.  
  431.  
  432. WORD ReadClassInfo(HWND hDlg)
  433. {
  434.  
  435.     NWDSContextHandle    dContext;
  436.     NWDS_ITERATION        iterHandle = -1L;
  437.     NWDS_BUFFER            *outBuf;
  438.     Class_Info_T       classInfo;
  439.     NWDSCCODE            cCode;
  440.     NWCOUNT                classDefCount /* classItemCount */;
  441.     char                   classDefName[MAX_SCHEMA_NAME_BYTES];
  442.     int                   i;
  443.  
  444.      dContext = NWDSCreateContext();
  445.  
  446.     if (dContext == ERR_CONTEXT_CREATION)
  447.         {
  448.         NWDSFreeContext(dContext);
  449.         return(dContext);
  450.         }
  451.  
  452.  
  453.     cCode = NWDSAllocBuf(
  454.              /* Buffer Size */ DEFAULT_MESSAGE_LEN,
  455.              /* Buff. Point.*/ &outBuf
  456.              );
  457.  
  458.     if (cCode < 0)
  459.             {
  460.             NWDSFreeContext(dContext);
  461.             return(cCode);
  462.             }
  463.  
  464.  
  465.     do
  466.         {
  467.         cCode = NWDSReadClassDef(
  468.               /* Contxt Handle */ dContext,
  469.               /* Info Type     */ DS_CLASS_DEF_NAMES,
  470.               /* All classes ? */ TRUE,
  471.               /* Class Names   */ NULL,
  472.               /* Iter handle   */ &iterHandle,
  473.               /* Result Buf    */ outBuf
  474.               );
  475.  
  476.         if (cCode < 0)
  477.               {
  478.                       NWDSFreeContext(dContext);
  479.                       NWDSFreeBuf(outBuf);
  480.                       return(cCode);
  481.               }
  482.  
  483.         cCode = NWDSGetClassDefCount(
  484.               /* Contxt Handle  */ dContext,
  485.               /* Result buffer  */ outBuf,
  486.               /* Class Def count*/ &classDefCount
  487.               );
  488.  
  489.         if (cCode < 0)
  490.               {
  491.                     NWDSFreeContext(dContext);
  492.                     NWDSFreeBuf(outBuf);
  493.                     return(cCode);
  494.               }
  495.  
  496.  
  497.         for (i = 0; i < (int)classDefCount; ++i)
  498.             {
  499.             cCode = NWDSGetClassDef(
  500.                   /* Contxt Handle */ dContext,
  501.                   /* Result Buffer */ outBuf,
  502.                   /* Item Name     */ classDefName,
  503.                   /* Class info    */ &classInfo
  504.                   );
  505.  
  506.             if (cCode < 0)
  507.                   {
  508.                         NWDSFreeContext(dContext);
  509.                                  NWDSFreeBuf(outBuf);
  510.                     return(cCode);
  511.                   }
  512.  
  513.             SendDlgItemMessage(hDlg, SUPER_CLASS, CB_ADDSTRING, 0,
  514.                         (LONG) (LPSTR) classDefName);
  515.                         
  516.             SendDlgItemMessage(hDlg, CONTAINMENT, CB_ADDSTRING, 0,
  517.                         (LONG) (LPSTR) classDefName);
  518.  
  519.             SendDlgItemMessage(hDlg, NEW_CLASS, CB_ADDSTRING, 0,
  520.                         (LONG) (LPSTR) classDefName);
  521.             }
  522.         } while(iterHandle != -1L);
  523.  
  524.         SendDlgItemMessage(hDlg, CONTAINMENT, CB_ADDSTRING, 0,
  525.                     (LONG) "\0 ");
  526.                     
  527.         SendDlgItemMessage(hDlg, SUPER_CLASS, CB_ADDSTRING, 0,
  528.                     (LONG) "\0 ");
  529.         
  530. NWDSFreeContext(dContext);
  531. NWDSFreeBuf(outBuf);
  532. return FALSE;
  533. }
  534.  
  535. ReadAttributeInfo(HWND hDlg)
  536. {
  537.     NWDSContextHandle    dContext;
  538.     NWDS_ITERATION    iterHandle = -1L;
  539.     NWDS_BUFFER        *outBuf;
  540.     NWDSCCODE        cCode;
  541.     NWCOUNT            attrCount;
  542.     Attr_Info_T     attributeInfo;
  543.     char                attrName[MAX_SCHEMA_NAME_CHARS];
  544.     int                i;
  545.  
  546.  
  547.     dContext = NWDSCreateContext();
  548.  
  549.     if (dContext == ERR_CONTEXT_CREATION)
  550.         {
  551.         NWDSFreeContext(dContext);
  552.         return(dContext);
  553.         }
  554.  
  555.  
  556.     cCode = NWDSAllocBuf(
  557.              /* Buffer Size */ DEFAULT_MESSAGE_LEN,
  558.              /* Buff. Point.*/ &outBuf
  559.              );
  560.  
  561.     if (cCode < 0)
  562.             {
  563.             NWDSFreeContext(dContext);
  564.                          return(cCode);
  565.             }
  566.  
  567.  
  568.  
  569.     do
  570.         {
  571.         cCode = NWDSReadAttrDef(
  572.               /* Contxt Handle */ dContext,
  573.               /* Info Type     */ DS_ATTR_DEFS,
  574.               /* All classes ? */ TRUE,
  575.               /* Class Names   */ NULL,
  576.               /* Iter handle   */ &iterHandle,
  577.               /* Result Buf    */ outBuf
  578.               );
  579.  
  580.         if (cCode < 0)
  581.               {
  582.                 NWDSFreeContext(dContext);
  583.                 NWDSFreeBuf(outBuf);
  584.                                     return(cCode);
  585.               }
  586.  
  587.         cCode = NWDSGetAttrCount(
  588.               /* Contxt Handle  */ dContext,
  589.               /* Result buffer  */ outBuf,
  590.               /* Class Def count*/ &attrCount
  591.               );
  592.  
  593.         if (cCode < 0)
  594.               {
  595.                 NWDSFreeContext(dContext);
  596.                 NWDSFreeBuf(outBuf);
  597.                 return(cCode);
  598.               }
  599.  
  600.  
  601.         for (i = 0; i < (int)attrCount; ++i)
  602.             {
  603.             cCode = NWDSGetAttrDef(
  604.                   /* Contxt Handle */ dContext,
  605.                   /* Result Buffer */ outBuf,
  606.                   /* Item Name     */ attrName,
  607.                   /* Class info    */ &attributeInfo
  608.                   );
  609.  
  610.             if (cCode < 0)
  611.                   {
  612.                   NWDSFreeContext(dContext);
  613.                   NWDSFreeBuf(outBuf);
  614.                   return(cCode);
  615.                   }
  616.  
  617.             SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_ADDSTRING, 0,
  618.                         (LONG) (LPSTR) attrName);
  619.             
  620.             SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_ADDSTRING, 0,
  621.                         (LONG) (LPSTR) attrName);
  622.         
  623.             SendDlgItemMessage(hDlg, NAME_ATTR, CB_ADDSTRING, 0,
  624.                         (LONG) (LPSTR) attrName);
  625.                         
  626.             SendDlgItemMessage(hDlg, ATTR_NAME, CB_ADDSTRING, 0,
  627.                         (LONG) (LPSTR) attrName);
  628.             }
  629.         } while(iterHandle != -1L);
  630.  
  631.         SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_ADDSTRING, 0,
  632.                     (LONG) "\0 ");
  633.             
  634.         SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_ADDSTRING, 0,
  635.                     (LONG) "\0");
  636.         
  637.         SendDlgItemMessage(hDlg, NAME_ATTR, CB_ADDSTRING, 0,
  638.                     (LONG) "\0 ");
  639.                     
  640. NWDSFreeContext(dContext);                               
  641. NWDSFreeBuf(outBuf);
  642. return FALSE;
  643. }
  644.  
  645.  
  646. WORD ReadClassFlagInfo(HWND hDlg)
  647. {
  648.  int    i;
  649.  
  650.  for (i=0; i < 5; ++i)
  651.         {
  652.         
  653.         SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_ADDSTRING, 0,
  654.                     (LONG) (LPSTR) classFlagsInfo[i].szLabel);
  655.         
  656.         }
  657.         
  658.     SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_ADDSTRING, 0,
  659.                 (LONG) "\0 ");
  660.         
  661. return TRUE;
  662. }
  663.  
  664. WORD ReadAttrFlagInfo(HWND hDlg)
  665. {
  666.  int    i;
  667.  
  668.  for (i=0; i < 11; ++i)
  669.         {
  670.         
  671.         SendDlgItemMessage(hDlg, FLAGS, CB_ADDSTRING, 0,
  672.                     (LONG) (LPSTR) attrFlagsInfo[i].szLabel);
  673.         
  674.         }
  675.  
  676.   SendDlgItemMessage(hDlg, FLAGS, CB_ADDSTRING, 0,
  677.         (LONG) " \0");
  678.  
  679. return TRUE;
  680. }
  681.  
  682.  
  683. WORD ReadSyntaxInfo(HWND hDlg)
  684. {
  685.  int    i;
  686.  
  687.  for (i=0; i < 29; ++i)
  688.         {
  689.         
  690.         SendDlgItemMessage(hDlg, SYNTAX, CB_ADDSTRING, 0,
  691.                     (LONG) (LPSTR) syntaxInfo[i].szLabel);
  692.         
  693.         }
  694.   SendDlgItemMessage(hDlg, SYNTAX, CB_ADDSTRING, 0,
  695.         (LONG) "\0 ");
  696.  
  697. return TRUE;
  698. }
  699.  
  700. WORD CreateClass(HWND hDlg)
  701. {
  702.     NWDSContextHandle    dContext;
  703.     char        className[MAX_DN_CHARS];
  704.     char        superClassName[MAX_DN_CHARS];
  705.     char        namingAttr[MAX_DN_CHARS];
  706.     char        containment[MAX_DN_CHARS];
  707.     char        optionalAttr[MAX_DN_CHARS];
  708.     char        mandatoryAttr[MAX_DN_CHARS];
  709.     char        flagLabel[50];
  710.     char         tempBuf[1024];
  711.     NWDS_BUFFER       *classBuf;
  712.     NWDSCCODE            cCode;
  713.     WORD      n = MAX_DN_CHARS;
  714.     long        rval;
  715.     DWORD        mandatoryCnt = 0 ;
  716.     DWORD        optionalCnt = 0;
  717.     int        i, j;
  718.     int        containCnt = 0, name = 0; 
  719.     Class_Info_T    classInfo;
  720.  
  721.  
  722.     memset(&classInfo, (int) '\0', sizeof(Class_Info_T));
  723.  
  724.     rval = SendDlgItemMessage(hDlg, NEW_CLASS, WM_GETTEXT, n,
  725.                 (LONG) (LPSTR) className);
  726.     
  727.     if ((rval == CB_ERR) || (rval == 0))
  728.         {
  729.         sprintf(tempBuf, "You must enter a Class Name \n in the Class Name field!");
  730.         MessageBox(NULL, tempBuf, "No Class Specified ", MB_ICONSTOP);
  731.         return FALSE;
  732.         }
  733.         
  734.     rval = SendDlgItemMessage(hDlg, SUPER_CLASS, WM_GETTEXT, n,
  735.                 (LONG) (LPSTR) superClassName); 
  736.                 
  737.     if ((rval == CB_ERR) || (rval == 0))
  738.         {
  739.         sprintf(tempBuf, "You must select a Super Class \n in the Super Class field!");
  740.         MessageBox(NULL, tempBuf, "No Super Class Selected", MB_ICONSTOP);
  741.         return FALSE;
  742.         }
  743.             
  744.     rval = SendDlgItemMessage(hDlg, NAME_ATTR, WM_GETTEXT, n,
  745.                 (LONG) (LPSTR) namingAttr);
  746.                 
  747.     if ((rval == CB_ERR) || (rval == 0))
  748.         name = 1;
  749.         
  750.     rval = SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_GETCOUNT, 0, 0);
  751.             
  752.     if ((rval > 0) && (rval != LB_ERR))
  753.         containCnt = rval;        
  754.  
  755.     rval = SendDlgItemMessage(hDlg, CLASS_LB, LB_GETCOUNT, 0, 0);
  756.             
  757.     if ((rval == 0) || (rval == LB_ERR))
  758.         {
  759.         sprintf(tempBuf, "You must select Class Flag(s)!");
  760.         MessageBox(NULL, tempBuf, "No Class Flag(s) Selected", MB_ICONSTOP);
  761.         return FALSE;
  762.         }
  763.  
  764.     classInfo.classFlags = 0x00;
  765.     for(i=0; i < rval; ++i)
  766.         {
  767.         SendDlgItemMessage(hDlg, CLASS_LB, LB_GETTEXT, i,
  768.                 (LONG) (LPSTR) flagLabel);
  769.  
  770.         for(j=0; j < 5; ++j)
  771.             {
  772.             if(strcmp(flagLabel, classFlagsInfo[j].szLabel) == 0)
  773.                 classInfo.classFlags |= classFlagsInfo[j].classFlag;
  774.             }
  775.         }
  776.             
  777.     rval = SendDlgItemMessage(hDlg, MANDATORY_LB, LB_GETCOUNT, 0, 0);
  778.             
  779.     if ((rval > 0) && (rval != LB_ERR))
  780.         mandatoryCnt = rval;        
  781.         
  782.     rval = SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETCOUNT, 0, 0);
  783.             
  784.     if ((rval > 0) && (rval != LB_ERR))
  785.         optionalCnt = rval;        
  786.         
  787.  
  788.     dContext = NWDSCreateContext();
  789.  
  790.     if (dContext == ERR_CONTEXT_CREATION)
  791.         {
  792.         NWDSFreeContext(dContext);
  793.         return(dContext);
  794.         }
  795.  
  796.     cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf);
  797.     if( cCode < 0 )
  798.         {
  799.         sprintf(tempBuf, "\nNWDSAllocBuf returned %04X", cCode);
  800.         MessageBox(NULL, tempBuf, "NWDSAllocBuf() Failed", MB_ICONSTOP);
  801.         NWDSFreeContext(dContext);
  802.         return FALSE;
  803.         }
  804.  
  805.     cCode = NWDSInitBuf(dContext, DSV_DEFINE_CLASS, classBuf);
  806.     if( cCode < 0 )
  807.         {
  808.         sprintf(tempBuf, "\nNWDSInitBuf returned %04X", cCode);
  809.         MessageBox(NULL, tempBuf, "NWDSInitBuf Failed!", MB_ICONSTOP);
  810.         NWDSFreeContext(dContext);
  811.         NWDSFreeBuf(classBuf);
  812.         return FALSE;
  813.         }
  814.  
  815.     /*----------------------------------------------------------------
  816.     ** entries for super class names
  817.     */
  818.     cCode = NWDSBeginClassItem(dContext, classBuf);
  819.     if( cCode < 0 )
  820.         {
  821.         sprintf(tempBuf, "\nNWDSBeginClasss returned %04X", cCode);
  822.         MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
  823.         NWDSFreeContext(dContext);
  824.         NWDSFreeBuf(classBuf);
  825.         return FALSE;
  826.         }
  827.  
  828.     cCode = NWDSPutClassItem(dContext, classBuf, superClassName);
  829.     if( cCode < 0 )
  830.         {
  831.         sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
  832.         MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
  833.         NWDSFreeContext(dContext);
  834.         NWDSFreeBuf(classBuf);
  835.         return FALSE;
  836.         }
  837.  
  838.     /*----------------------------------------------------------------
  839.     ** entries for containment class names; which are none
  840.     */
  841.     cCode = NWDSBeginClassItem(dContext, classBuf);
  842.     if( cCode < 0 )
  843.         {
  844.         sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
  845.         MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
  846.         NWDSFreeContext(dContext);
  847.         NWDSFreeBuf(classBuf);
  848.         return FALSE;
  849.         }
  850.         
  851.      if (containCnt > 0)
  852.         {
  853.          for(i=0; i < containCnt; ++ i)
  854.                 {
  855.                 SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_GETTEXT, i,
  856.                         (LONG) (LPSTR) containment);
  857.  
  858.                 cCode = NWDSPutClassItem(dContext, classBuf, containment);
  859.                 if( cCode < 0 )
  860.                     {
  861.                     sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
  862.                     MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
  863.                     NWDSFreeContext(dContext);
  864.                     NWDSFreeBuf(classBuf);
  865.                     return FALSE;
  866.                     }
  867.                 
  868.                 }
  869.  
  870.         }    
  871.         
  872.     /*----------------------------------------------------------------
  873.     ** entries for naming attribute names; same as Server
  874.     */
  875.     cCode = NWDSBeginClassItem(dContext, classBuf);
  876.     if( cCode < 0 )
  877.         {
  878.         sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
  879.         MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
  880.         NWDSFreeContext(dContext);
  881.         NWDSFreeBuf(classBuf);
  882.         return FALSE;
  883.         }
  884.  
  885.     if (!name)
  886.         {
  887.         cCode = NWDSPutClassItem(dContext, classBuf, namingAttr);
  888.         if( cCode < 0 )
  889.             {
  890.             sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
  891.             MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
  892.             NWDSFreeContext(dContext);
  893.             NWDSFreeBuf(classBuf);
  894.             return FALSE;
  895.             }
  896.         }
  897.         
  898.     /*----------------------------------------------------------------
  899.     ** entries for mandatory attribute names; same as Server
  900.     */
  901.     cCode = NWDSBeginClassItem(dContext, classBuf);
  902.     if( cCode < 0 )
  903.         {
  904.         sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
  905.         MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
  906.         NWDSFreeContext(dContext);
  907.         NWDSFreeBuf(classBuf);
  908.         return FALSE;
  909.         }
  910.  
  911.      if (mandatoryCnt > 0)
  912.         {
  913.          for(i=0; i < mandatoryCnt; ++ i)
  914.                 {
  915.                 SendDlgItemMessage(hDlg, MANDATORY_LB, LB_GETTEXT, i,
  916.                         (LONG) (LPSTR) mandatoryAttr);
  917.  
  918.                 cCode = NWDSPutClassItem(dContext, classBuf, mandatoryAttr);
  919.                 if( cCode < 0 )
  920.                     {
  921.                     sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
  922.                     MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
  923.                     NWDSFreeContext(dContext);
  924.                     NWDSFreeBuf(classBuf);
  925.                     return FALSE;
  926.                     }
  927.                 
  928.                 }
  929.  
  930.         }    
  931.     /*----------------------------------------------------------------
  932.     ** entries for optional attribute names; same as server for now.
  933.     */
  934.     cCode = NWDSBeginClassItem(dContext, classBuf);
  935.     if( cCode < 0 )
  936.         {
  937.         sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
  938.         MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
  939.         NWDSFreeContext(dContext);
  940.         NWDSFreeBuf(classBuf);
  941.         return FALSE;
  942.         }
  943.  
  944.      if (optionalCnt > 0)
  945.         {
  946.          for(i=0; i < optionalCnt; ++ i)
  947.                 {
  948.                 SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETTEXT, i,
  949.                         (LONG) (LPSTR) optionalAttr);
  950.  
  951.                 cCode = NWDSPutClassItem(dContext, classBuf, optionalAttr);
  952.                 if( cCode < 0 )
  953.                     {
  954.                     sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
  955.                     MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
  956.                     NWDSFreeContext(dContext);
  957.                     NWDSFreeBuf(classBuf);
  958.                     return FALSE;
  959.                     }
  960.                 
  961.                 }
  962.  
  963.         }    
  964.  
  965.     cCode = NWDSDefineClass(dContext, className, &classInfo, classBuf);
  966.     if( cCode < 0 )
  967.         {
  968.         sprintf(tempBuf, "\nNWDSDefineClass returned %04X", cCode);
  969.         MessageBox(NULL, tempBuf, "NWDSDefineClass Failed!", MB_ICONSTOP);
  970.         NWDSFreeContext(dContext);
  971.         NWDSFreeBuf(classBuf);
  972.         }
  973.     else
  974.         {
  975.         sprintf(tempBuf, "Class %s successfully added!", className);
  976.         MessageBox(NULL, tempBuf, "Successfully added!", MB_OK);
  977.         }
  978.         
  979.     ClassClear(hDlg);    
  980.     ClassResetComboBoxes(hDlg);     
  981.     ReadClassInfo(hDlg);
  982. NWDSFreeBuf(classBuf);
  983. NWDSFreeContext(dContext);
  984. return TRUE;
  985. }
  986.  
  987.  
  988. WORD RemoveClassDefinition(HWND hDlg)
  989. {
  990.     WORD                  n = MAX_DN_CHARS;
  991.     long                    rval;
  992.     char                    className[MAX_DN_CHARS];
  993.     char         tempBuf[1024];
  994.     NWDSContextHandle    dContext;
  995.     NWDSCCODE            cCode;
  996.     
  997.     dContext = NWDSCreateContext();
  998.  
  999.     if (dContext == ERR_CONTEXT_CREATION)
  1000.         {
  1001.         NWDSFreeContext(dContext);
  1002.         return(dContext);
  1003.         }
  1004.  
  1005.     rval = SendDlgItemMessage(hDlg, NEW_CLASS, WM_GETTEXT, n,
  1006.                 (LONG) (LPSTR) className);
  1007.     
  1008.     if ((rval == CB_ERR) || (rval == 0))
  1009.         {
  1010.         sprintf(tempBuf, "You must enter a Class Name \n in the Class Name field!");
  1011.         MessageBox(NULL, tempBuf, "No Class Specified ", MB_ICONSTOP);
  1012.         NWDSFreeContext(dContext);
  1013.         return FALSE;
  1014.         }
  1015.  
  1016.     cCode = NWDSRemoveClassDef(
  1017.                 /* Context Handle */ dContext,
  1018.                 /* Class Name     */ className
  1019.                 );
  1020.                         
  1021.     if (cCode < 0)
  1022.         {
  1023.         sprintf(tempBuf, "NWDSRemoveClassDef() returned %04X\n\
  1024.         Remember that clients cannot subtract\n\
  1025.         from the standard set of class\n\
  1026.         definitions defined by the directory.\n\
  1027.         If an instance of this class\n\
  1028.         exists the class definition cannot\n\
  1029.         be removed util all objects of this\n\
  1030.         class are deleted.", cCode);
  1031.         MessageBox(NULL, tempBuf, "Remove Class Failed!", MB_ICONSTOP);
  1032.         NWDSFreeContext(dContext);
  1033.         return FALSE;
  1034.         }
  1035.     else
  1036.         {
  1037.         sprintf(tempBuf, "Class %s successfully removed!", className);
  1038.         MessageBox(NULL, tempBuf, "Successfully removed!", MB_OK);
  1039.         }
  1040.  
  1041.     ClassClear(hDlg);
  1042.     ClassResetComboBoxes(hDlg);
  1043.     ReadClassInfo(hDlg);    
  1044. NWDSFreeContext(dContext);
  1045. return TRUE;        
  1046. }
  1047.  
  1048. WORD RemoveAttributeDefinition(HWND hDlg)
  1049. {
  1050.     WORD                  n = MAX_DN_CHARS;
  1051.     long                    rval;
  1052.     char                    attrName[MAX_DN_CHARS];
  1053.     char                     tempBuf[1024];
  1054.     NWDSContextHandle    dContext;
  1055.     NWDSCCODE            cCode;
  1056.     
  1057.  
  1058.     rval = SendDlgItemMessage(hDlg, ATTR_NAME, WM_GETTEXT, n,
  1059.                 (LONG) (LPSTR) attrName);
  1060.     
  1061.     if ((rval == CB_ERR) || (rval == 0))
  1062.         {
  1063.         sprintf(tempBuf, "You must enter an Attribute  \n name in the Attribute Name field!");
  1064.         MessageBox(NULL, tempBuf, "No Attribute Specified ", MB_ICONSTOP);
  1065.         return FALSE;
  1066.         }
  1067.         
  1068.     dContext = NWDSCreateContext();
  1069.  
  1070.     if (dContext == ERR_CONTEXT_CREATION)
  1071.         {
  1072.         NWDSFreeContext(dContext);
  1073.         return(dContext);
  1074.         }
  1075.  
  1076.     cCode = NWDSRemoveAttrDef(
  1077.                 /* Context Handle */ dContext,
  1078.                 /* Class Name     */ attrName
  1079.                 );
  1080.                         
  1081.     if (cCode < 0)
  1082.         {
  1083.         sprintf(tempBuf, "NWDSRemoveAttrDef() returned %04X\n\
  1084.         Remember that clients cannot subtract\n\
  1085.         from the standard set of attribute\n\
  1086.         definitions defined by the directory.\n\
  1087.         If this attribute is in use by an existing\n\
  1088.         class this attribute cannot be removed!", cCode);
  1089.         MessageBox(NULL, tempBuf, "Remove Attribute Failed!", MB_ICONSTOP);
  1090.         NWDSFreeContext(dContext);
  1091.         return FALSE;
  1092.         }
  1093.     else
  1094.         {
  1095.         sprintf(tempBuf, "Attribute %s successfully removed!", attrName);
  1096.         MessageBox(NULL, tempBuf, "Successfully removed!", MB_OK);
  1097.         }
  1098.         
  1099.     AttrClear(hDlg);
  1100.     AttrResetComboBoxes(hDlg);
  1101.     ReadAttributeInfo(hDlg);    
  1102. NWDSFreeContext(dContext);
  1103. return TRUE;        
  1104. }
  1105.  
  1106.  
  1107. WORD ModifyClass(HWND hDlg)
  1108. {
  1109.     NWDSContextHandle    dContext;
  1110.     char        className[MAX_DN_CHARS];
  1111.     char        optionalAttr[MAX_DN_CHARS];
  1112.     char         tempBuf[1024];                    
  1113.     NWDSCCODE            cCode;
  1114.     WORD      n = MAX_DN_CHARS;
  1115.     long        optionalCnt = 0;
  1116.     Buf_T             *classBuf;
  1117.     long        rval;
  1118.     int        i;
  1119.  
  1120.     rval = SendDlgItemMessage(hDlg, NEW_CLASS, WM_GETTEXT, n,
  1121.                 (LONG) (LPSTR) className);
  1122.     
  1123.     if ((rval == CB_ERR) || (rval == 0))
  1124.         {
  1125.         sprintf(tempBuf, "You must enter a Class Name \n in the Class Name field!");
  1126.         MessageBox(NULL, tempBuf, "No Class Specified ", MB_ICONSTOP);
  1127.         return FALSE;
  1128.         }
  1129.  
  1130.     rval = SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETCOUNT, 0, 0);
  1131.             
  1132.     if ((rval > 0) && (rval != LB_ERR))
  1133.         optionalCnt = rval;
  1134.     else
  1135.         {
  1136.         sprintf(tempBuf, "You must select at least \n one optional attribute!");
  1137.         MessageBox(NULL, tempBuf, "No Optional Attribute Selected ", MB_ICONSTOP);
  1138.         return FALSE;
  1139.         
  1140.         }            
  1141.  
  1142.     dContext = NWDSCreateContext();
  1143.  
  1144.     if (dContext == ERR_CONTEXT_CREATION)
  1145.         {
  1146.         NWDSFreeContext(dContext);
  1147.         return(dContext);
  1148.         }
  1149.   
  1150.     cCode = NWDSAllocBuf(
  1151.                 /* Number of Bytes */ DEFAULT_MESSAGE_LEN, 
  1152.                 /* PTR NWDS_BUFFER */&classBuf
  1153.                         );
  1154.     if( cCode < 0 )
  1155.         {
  1156.         sprintf(tempBuf, "\nNWDSAllocBuf returned %04X", cCode);
  1157.         MessageBox(NULL, tempBuf, "NWDSAllocBuf Failed!", MB_ICONSTOP);
  1158.         NWDSFreeContext(dContext);
  1159.         return FALSE;
  1160.         }
  1161.  
  1162.     cCode = NWDSInitBuf(
  1163.                 /* Context Handle */ dContext, 
  1164.                 /* Operation      */ DSV_MODIFY_CLASS_DEF, 
  1165.                 /* PTR to Buffer  */ classBuf
  1166.                 );
  1167.     if( cCode < 0 )
  1168.         {
  1169.         sprintf(tempBuf, "\nNWDSInitBuf returned %04X", cCode);
  1170.         MessageBox(NULL, tempBuf, "NWDSInitBuf Failed!", MB_ICONSTOP);
  1171.         NWDSFreeContext(dContext);
  1172.         NWDSFreeBuf(classBuf);
  1173.         return FALSE;
  1174.         }
  1175.  
  1176.     /*---------------------------------------------------------------
  1177.     ** Add optional attribute(s)
  1178.     */
  1179.      if (optionalCnt > 0)
  1180.         {
  1181.          for(i=0; i < optionalCnt; ++ i)
  1182.                 {
  1183.                 SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETTEXT, i,
  1184.                         (LONG) (LPSTR) optionalAttr);
  1185.  
  1186.                 cCode = NWDSPutClassItem(dContext, classBuf, optionalAttr);
  1187.                 if( cCode < 0 )
  1188.                     {
  1189.                     sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
  1190.                     MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
  1191.                     NWDSFreeContext(dContext);
  1192.                     NWDSFreeBuf(classBuf);
  1193.                     return FALSE;
  1194.                     }
  1195.                 
  1196.                 }
  1197.  
  1198.         }    
  1199.  
  1200.  
  1201.     cCode = NWDSModifyClassDef(
  1202.                 /* Context Handle */ dContext, 
  1203.                 /* Class Name     */ className, 
  1204.                 /* Class Buffer   */ classBuf
  1205.                 );
  1206.     if( cCode < 0 )
  1207.         {
  1208.         sprintf(tempBuf, "\nNWDSModifyClassDef returned %04X", cCode);
  1209.         MessageBox(NULL, tempBuf, "NWDSModifyClassDef Failed!", MB_ICONSTOP);
  1210.         NWDSFreeContext(dContext);
  1211.         NWDSFreeBuf(classBuf);
  1212.         return FALSE;
  1213.         }
  1214.     else
  1215.         {
  1216.         sprintf(tempBuf, "Class %s successfully modified", className);
  1217.         MessageBox(NULL, tempBuf, "Successfully modified!", MB_OK);
  1218.         }
  1219.         
  1220.     ClassClear(hDlg);
  1221.     ClassResetComboBoxes(hDlg);
  1222.     ReadClassInfo(hDlg);
  1223. NWDSFreeBuf(classBuf);
  1224. NWDSFreeContext(dContext);
  1225. return TRUE;    
  1226. }
  1227.  
  1228. WORD CreateAttribute(HWND hDlg)
  1229. {
  1230.  
  1231.     char                     tempBuf[1024];
  1232.     char                    flagLabel[50];
  1233.     char                    attrName[MAX_DN_CHARS];
  1234.     char                    attrBounds[12];
  1235.     char                    syntaxField[40];
  1236.     NWDSCCODE            cCode;  
  1237.     NWDSContextHandle    dContext;
  1238.     WORD                  n = MAX_DN_CHARS;
  1239.     Attr_Info_T       attrInfo;
  1240.     long                    rval;
  1241.     int                    i, j;
  1242.  
  1243.  
  1244.     memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
  1245.      
  1246.     rval = SendDlgItemMessage(hDlg, ATTR_NAME, WM_GETTEXT, n,
  1247.                 (LONG) (LPSTR) attrName);
  1248.     
  1249.     if ((rval == CB_ERR) || (rval == 0))
  1250.         {
  1251.         sprintf(tempBuf, "You must enter an Attribute  \n name in the Attribute Name field!");
  1252.         MessageBox(NULL, tempBuf, "No Attribute Specified ", MB_ICONSTOP);
  1253.         return FALSE;
  1254.         }
  1255.  
  1256.     rval = SendDlgItemMessage(hDlg, SYNTAX, WM_GETTEXT, n,
  1257.                 (LONG) (LPSTR) syntaxField);
  1258.     
  1259.     if ((rval == CB_ERR) || (rval == 0))
  1260.         {
  1261.         sprintf(tempBuf, "You must select a Syntax  \n in the Syntax field!");
  1262.         MessageBox(NULL, tempBuf, "No Syntax Selected!", MB_ICONSTOP);
  1263.         return FALSE;
  1264.         }
  1265.  
  1266.     rval = SendDlgItemMessage(hDlg, FLAGS_LB, LB_GETCOUNT, 0, 0);
  1267.  
  1268.     if ((rval != 0) && (rval != LB_ERR))
  1269.         {
  1270.         for(i=0; i < rval; ++i)
  1271.             {
  1272.             SendDlgItemMessage(hDlg, FLAGS_LB, LB_GETTEXT, i,
  1273.                     (LONG) (LPSTR) flagLabel);
  1274.  
  1275.             for(j=0; j < 11; ++j)
  1276.                 {
  1277.                 if(strcmp(flagLabel, attrFlagsInfo[j].szLabel) == 0)
  1278.                     attrInfo.attrFlags |= attrFlagsInfo[j].attrFlag;
  1279.                 }
  1280.             }
  1281.         }
  1282.     else
  1283.         attrInfo.attrFlags = 0;
  1284.  
  1285.     rval = SendDlgItemMessage(hDlg, ATTR_UPPER, WM_GETTEXT, 10,
  1286.                 (LONG) (LPSTR) attrBounds);
  1287.                 
  1288.     if((rval > 0) && (rval != LB_ERR))
  1289.         attrInfo.attrUpper = atol(attrBounds);
  1290.     
  1291.     rval = SendDlgItemMessage(hDlg, ATTR_LOWER, WM_GETTEXT, 10,
  1292.                 (LONG) (LPSTR) attrBounds);
  1293.                 
  1294.     if((rval > 0) && (rval != LB_ERR))
  1295.         attrInfo.attrLower = atol(attrBounds);
  1296.         
  1297.             
  1298.     for(j=0; j < 29; ++j)
  1299.         {
  1300.         if(strcmp(syntaxField, syntaxInfo[j].szLabel) == 0)
  1301.         attrInfo.attrSyntaxID = syntaxInfo[j].syntaxID;
  1302.         }
  1303.  
  1304.  
  1305.     dContext = NWDSCreateContext();
  1306.  
  1307.     if (dContext == ERR_CONTEXT_CREATION)
  1308.         {
  1309.         NWDSFreeContext(dContext);
  1310.         return(dContext);
  1311.         }
  1312.         
  1313.     cCode = NWDSDefineAttr(dContext, attrName, &attrInfo);
  1314.         if( cCode < 0 )
  1315.             {
  1316.             sprintf(tempBuf, "\nNWDSDefineAttr() returned %04X", cCode);
  1317.             MessageBox(NULL, tempBuf, "NWDSDefineAttr() Failed!", MB_ICONSTOP);
  1318.             NWDSFreeContext(dContext);
  1319.             return FALSE;
  1320.             }
  1321.         else
  1322.             {
  1323.             sprintf(tempBuf, "Attribute %s successfully added!", attrName);
  1324.             MessageBox(NULL, tempBuf, "Successfully Added!", MB_OK);
  1325.             }
  1326.             
  1327.     AttrClear(hDlg);
  1328.     AttrResetComboBoxes(hDlg);
  1329.     ReadAttributeInfo(hDlg);
  1330.     SendDlgItemMessage(hDlg, ATTR_LOWER, WM_SETTEXT, 0, (LONG) "\0");
  1331.     SendDlgItemMessage(hDlg, ATTR_UPPER, WM_SETTEXT, 0, (LONG) "\0");
  1332.                                                                                         
  1333. NWDSFreeContext(dContext);
  1334. return TRUE;        
  1335. }
  1336.  
  1337. AttrClear(HWND hDlg)
  1338. {
  1339.     SendDlgItemMessage(hDlg, ATTR_NAME, WM_SETTEXT, 0, (LONG) "\0");
  1340.     SendDlgItemMessage(hDlg, SYNTAX, CB_SETCURSEL, 0, 0);
  1341.     SendDlgItemMessage(hDlg, FLAGS, WM_SETTEXT, 0, (LONG) "\0");
  1342.     SendDlgItemMessage(hDlg, FLAGS_LB, LB_RESETCONTENT, 0, 0);
  1343. }
  1344.  
  1345. ClassClear(HWND hDlg)
  1346. {
  1347.     SendDlgItemMessage(hDlg, NEW_CLASS, WM_SETTEXT, 0, (LONG) "\0");
  1348.     SendDlgItemMessage(hDlg, SUPER_CLASS, CB_SETCURSEL, 0, 0);
  1349.     SendDlgItemMessage(hDlg, NAME_ATTR, CB_SETCURSEL, 0, 0);
  1350.     SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_SETCURSEL, 0, 0);
  1351.     SendDlgItemMessage(hDlg, CLASS_LB, LB_RESETCONTENT, 0, 0);
  1352.     SendDlgItemMessage(hDlg, CONTAINMENT, CB_SETCURSEL, 0, 0);
  1353.     SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_RESETCONTENT, 0, 0);
  1354.     SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_SETCURSEL, 0, 0);
  1355.     SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_RESETCONTENT, 0, 0);
  1356.     SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_SETCURSEL, 0, 0);
  1357.     SendDlgItemMessage(hDlg, MANDATORY_LB, LB_RESETCONTENT, 0, 0);
  1358. }
  1359.  
  1360. AttrResetComboBoxes(HWND hDlg)
  1361. {
  1362.     SendDlgItemMessage(hDlg, ATTR_NAME, CB_RESETCONTENT, 0, 0);
  1363.     SendDlgItemMessage(hDlg, NAME_ATTR, CB_RESETCONTENT, 0, 0);
  1364.     SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_RESETCONTENT, 0, 0);
  1365.     SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_RESETCONTENT, 0, 0);
  1366.  
  1367. }
  1368.  
  1369. ClassResetComboBoxes(HWND hDlg)
  1370. {
  1371.     SendDlgItemMessage(hDlg, NEW_CLASS, CB_RESETCONTENT, 0, 0);
  1372.     SendDlgItemMessage(hDlg, SUPER_CLASS, CB_RESETCONTENT, 0, 0);
  1373.     SendDlgItemMessage(hDlg, CONTAINMENT, CB_RESETCONTENT, 0, 0);
  1374.  
  1375. }
  1376.