home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 May / CHIPCD200305.iso / super / altn / md_en.exe / CREATEUSER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-26  |  1.3 KB  |  46 lines

  1. #include "CreateUser.h"
  2. #include "MDUserImports.h"
  3.  
  4.  
  5. int main(int argc, char** argv)
  6. {
  7.     int iLoadResult = 0;
  8.     if (!LoadMDUserDll(iLoadResult, // buffer to store error result code
  9.                       NULL,        // Optional path to the dll
  10.                       false))      // TRUE if you want the accounts loaded into memory after the dll has been initialized
  11.     {
  12.         cout << "Could not load the MDUserDll, error:" << iLoadResult << "\n";
  13.         return -1;
  14.     }
  15.  
  16.     
  17.     if (CreateMDUser("Frank", "secret", "mydomain.com", "Frank Thomas")) 
  18.         cout << "User was created successfully\n";
  19.     else
  20.         cout << "Error creating user\n";
  21.  
  22.     // Release the MDUserDLL
  23.     FreeMDUserDll();
  24.  
  25.     return 0;
  26. }
  27.  
  28.  
  29. bool CreateMDUser(string strMailbox, string strPassword, string strDomain, string strRealName)
  30. {
  31.     MD_UserInfo UserInfo;
  32.     
  33.     // Copy new account defaults into structure
  34.     MD_InitUserInfo(&UserInfo);  // You must call MD_InitUserInfo on new UserInfo structures when creating users
  35.     
  36.     // copy data into UserInfo members
  37.     strncpy(UserInfo.FullName, strRealName.c_str(), FULLNAME_LEN);
  38.     strncpy(UserInfo.Domain, strDomain.c_str(), DOMAIN_LEN);
  39.     strncpy(UserInfo.Mailbox, strMailbox.c_str(), MAILBOX_LEN);
  40.     strncpy(UserInfo.Password, strPassword.c_str(), PASSWORD_LEN);
  41.     
  42.     MD_FilterUserInfo(&UserInfo);
  43.     
  44.     return (MD_AddUser(&UserInfo, 0) == MDDLLERR_NOERROR);
  45. }
  46.