Call API in InstallShield 2009

Data Type in InstallShield   And Win32API Data Type

BOOL TRUE or FALSE
CHAR 8-bit 有符号字符
DWORD 同NUMBER
HWND 窗口句柄(内部类型是NUMBER)
INT 同NUMBER
LIST 指向InstallShield list的指针(内部类型是NUMBER)
LONG 同NUMBER
LPSTR 同POINTER
NUMBER 有符号4字节整数
POINTER 指向数据的指针(如int i;p=&i)
SHORT 同NUMBER
STRING 字符串

Call API  For Example

prototype KERNEL32.GetVolumeInformation(BYREF STRING, BYREF STRING, NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, NUMBER); 

附加一篇不错的文章

installshield安装程序,包括Mysql初始化、安装jre、配置环境变量、简单注册码生成

C代码
  1. 曾经使用installshield制作的安装程序,包括Mysql初始化、安装jre、配置环境变量、简单注册码生成。  
曾经使用installshield制作的安装程序,包括Mysql初始化、安装jre、配置环境变量、简单注册码生成。
C代码
  1. ////////////////////////////////////////////////////////////////////////////////   
  2. //                                                                              
  3. //  File Name: Setup.rul                                                     
  4. //                                                                              
  5. //  Description: InstallShield script                                          
  6. //                                                                              
  7. //  Comments: This script was generated based on the selections you made in   
  8. //            the Project Wizard.  Refer to the help topic entitled "Modify        
  9. //            the script that the Project Wizard generates" for information   
  10. //    on possible next steps.   
  11. //   
  12. /////////////////////////////////////////////an///////////////////////////////////   
  13.   
  14. // Include header files   
  15.       
  16. #include "ifx.h"   
  17.       
  18. ////////////////////// string defines ////////////////////////////   
  19. //////////////////// installation declarations ///////////////////   
  20. // ----- DLL function prototypes -----   
  21.   
  22.     // your DLL function prototypes   
  23.   
  24. // ---- script function prototypes -----   
  25.   
  26.     // your script function prototypes   
  27.     // your global variables   
  28.     
  29. NUMBER volumeNum;   
  30. //Before using the GetVolumeInformation API you will need to prototype it   
  31. prototype KERNEL32.GetVolumeInformation(BYREF STRING, BYREF STRING, NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, NUMBER);   
  32. //prototype for the custom InstallScript function   
  33. prototype GetVolumeSerial();   
  34. //function definition   
  35. function GetVolumeSerial()   
  36. STRING lpRootPathName;   
  37. STRING lpVolumeNameBuffer;   
  38. NUMBER nVolumeNameSize;   
  39. NUMBER lpVolumeSerialNumber;   
  40. NUMBER lpMaximumComponentLength;   
  41. NUMBER lpFileSystemFlags;   
  42. STRING lpFileSystemNameBuffer;   
  43. NUMBER nFileSystemNameSize;   
  44. BOOL APIReturn;   
  45. begin   
  46.   lpRootPathName="d:\\";   
  47.   nVolumeNameSize=60;   
  48.   nFileSystemNameSize=60;   
  49.   //APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);   
  50.   APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);   
  51.     
  52.     
  53.   if (APIReturn) then           
  54.     
  55.    volumeNum = lpVolumeSerialNumber ;    
  56.    if (volumeNum < 0) then   
  57.     volumeNum = 0 - volumeNum;   
  58.    endif;        
  59.    //NumToStr(volumeNum,lpVolumeSerialNumber);   
  60.     //SprintfBox(INFORMATION, "", "Volume= %s\nVolume Serial= %d", lpRootPathName, lpVolumeSerialNumber);   
  61.    if (volumeNum > 2139999999 - 135792468) then          
  62.     
  63.     //volumeNum = 123456789;   
  64.     volumeNum = volumeNum - volumeNum/100000000*100000000;   
  65.    endif;        
  66.       
  67.   else                       
  68.     
  69.      volumeNum = 123456789;   
  70.     //MessageBox("Failure.",0);   
  71.   endif;   
  72. end ;   
  73. prototype getNumString();   
  74. function getNumString()   
  75.   number numSpace;   
  76.   number numMen;   
  77.   string tmpString;   
  78. begin                                           
  79.      //tmpNum = GetWindowHandle(HWND_INSTALL);  //安装主窗口的句柄    
  80.      //numSpace = GetDiskSpace("c:\\"); //指定驱动器上的空闲磁盘空间    
  81.      numSpace = GetDiskSpaceEx("c:\\",KBYTES); //指定驱动器上的空闲磁盘空间        BYTES    
  82.      //numMen = GetMemFree();  //运行在Microsoft Windows下的一个应用程序可用的内存大小       
  83.      numMen = GetDiskSpaceEx("d:\\",KBYTES);   
  84.      if numSpace < 10000 then   
  85.         numSpace = 11360000;   
  86.      else  
  87.       numSpace = (numSpace - numSpace/10000*10000)*10000;   
  88.      endif;   
  89.      if numMen < 10000 then   
  90.         numMen = 7521;     
  91.      else  
  92.       numMen = numMen - numMen/10000*10000;   
  93.      endif;                                                     
  94.      volumeNum = 100000000 + numSpace + numMen;    
  95.        
  96.      //NumToStr(tmpString,volumeNum);        
  97.     // MessageBox(tmpString,0);                               
  98. end;     
  99.     
  100.     
  101.     
  102. //////////////////////////////////////////////////////////////////////////////   
  103. //                                                                             
  104. //  FUNCTION:   OnFirstUIBefore                                              
  105. //                                                                             
  106. //  EVENT:      FirstUIBefore event is sent when installation is run for the first   
  107. //              time on given machine. In the handler installation usually displays   
  108. //              UI allowing end user to specify installation parameters. After this   
  109. //              function returns, ComponentTransferData is called to perform file   
  110. //              transfer.   
  111. //                                                                             
  112. ///////////////////////////////////////////////////////////////////////////////   
  113. function OnFirstUIBefore()   
  114.     number  nResult,nSetupType;   
  115.     string  szTitle, szMsg;   
  116.     string  szLicenseFile, szQuestion;   
  117.     string  szName, szCompany, szSerial;   
  118.     string  szFile;   
  119.     string  szTargetPath;   
  120.     string  szDir;   
  121.     string  szfolder;   
  122.     string  szComponents, szTargetdir;   
  123.     number  nLevel;   
  124.     LIST    listStartCopy;   
  125.     LIST    list;   
  126.     number  nvSize;       
  127.       
  128.     string szField1, svEdit1,szField2, svEdit2;   
  129.                         
  130.     string localNum;     
  131.     number tmpNum;        
  132.     string tmpCheckString;   
  133.     string checkString;   
  134. begin    
  135.     // TO DO: if you want to enable background, window title, and caption bar title                                                                       
  136.     // SetTitle( @TITLE_MAIN, 24, WHITE );                                          
  137.     // SetTitle( @TITLE_CAPTIONBAR, 0, BACKGROUNDCAPTION );                       
  138.     // Enable( FULLWINDOWMODE );           
  139.     // Enable( BACKGROUND );           
  140.     // SetColor(BACKGROUND,RGB (0, 128, 128));          
  141.              
  142.     GetVolumeSerial();                       
  143.     //getNumString();   
  144.       
  145.     tmpNum =  volumeNum;                
  146.     tmpNum = tmpNum - tmpNum / 100 * 100;     
  147.     NumToStr(tmpCheckString,tmpNum);       
  148.     if (tmpCheckString == "0") then   
  149.       tmpCheckString = "0X";   
  150.     endif;   
  151.     checkString = "B" + tmpCheckString + "_";        
  152.       
  153.     tmpNum =  volumeNum / 100;                
  154.     tmpNum = tmpNum - tmpNum / 100 * 100;     
  155.     NumToStr(tmpCheckString,tmpNum);      
  156.     if (tmpCheckString == "0") then   
  157.       tmpCheckString = "0X";   
  158.     endif;   
  159.     checkString = checkString + "K" + tmpCheckString + "_";   
  160.       
  161.     tmpNum =  volumeNum / 10000;                
  162.     tmpNum = tmpNum - tmpNum / 100 * 100;     
  163.     NumToStr(tmpCheckString,tmpNum);     
  164.     if (tmpCheckString == "0") then   
  165.       tmpCheckString = "0X";   
  166.     endif;   
  167.     checkString = checkString + "X" + tmpCheckString + "_";   
  168.       
  169.     tmpNum =  volumeNum / 1000000;                
  170.     tmpNum = tmpNum - tmpNum / 100 * 100;     
  171.     NumToStr(tmpCheckString,tmpNum);   
  172.     if (tmpCheckString == "0") then   
  173.       tmpCheckString = "0X";   
  174.     endif;    
  175.     checkString = checkString + "T" + tmpCheckString;   
  176.                                                       
  177.     //MessageBox(checkString,INFORMATION);    
  178.          
  179.     //变换volumeNum的值   
  180.     //B3242_K423_X342_T3423      
  181.     volumeNum = volumeNum + 135792468;              
  182.     NumToStr(localNum,volumeNum);                                                      
  183.     //MessageBox(localNum,INFORMATION);   
  184.       
  185.                            
  186.     //copy images                                                                                                                                    
  187.    nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif""c:\\xxx\\icons\\media\\",EXCLUDE_SUBDIR);                                                                                                    
  188.    nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg""c:\\xxx\\icons\\teacher\\",EXCLUDE_SUBDIR);      
  189.    CreateDir("c:\\xxx\\resc\\");                         
  190.            
  191.    if (nResult != 0) then          
  192.          MessageBox ("图片拷贝出错!", SEVERE);   
  193.    endif;   
  194.       
  195.           
  196.           
  197.           
  198.           
  199.          
  200.          
  201.          
  202.     nSetupType = TYPICAL;    
  203.     TARGETDIR = PROGRAMFILES ^@COMPANY_NAME ^@PRODUCT_NAME;    
  204.     szDir = TARGETDIR;   
  205.     SHELL_OBJECT_FOLDER = @FOLDER_NAME;   
  206.     szName    = "";   
  207.     szCompany = "";   
  208.     szSerial = "";   
  209. Dlg_Start:   
  210.     // beginning of dialogs label   
  211. Dlg_SdWelcome:   
  212.     szTitle = "xxxx系统";   
  213.     szMsg   = "  确定是否继续安装?继续请按【下一步(next)】";   
  214.     nResult = SdWelcome( szTitle, szMsg );   
  215.     if (nResult = BACK) goto Dlg_Start;   
  216. //Dlg_SdLicense:   
  217. //    szLicenseFile = SUPPORTDIR ^ "license.txt";   
  218. //    szTitle    = "xxxx系统";   
  219. //    szMsg      = "许可协议";   
  220. //    szQuestion = "您是否接受该协议?接受请按【是(Yes)】。继续安装必须接受该协议。";   
  221. //    nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );   
  222. //    if (nResult = BACK) goto Dlg_SdWelcome;   
  223. Dlg_SdShowInfoList:        
  224.     //szFile = SUPPORTDIR ^ "infolist.txt";   
  225.     //list = ListCreate( STRINGLIST );   
  226.     //ListReadFromFile( list, szFile );   
  227.     szTitle = "系统本地编号";   
  228.     szMsg    = "将下面的本地编号发送给权限授予机构,在接收到相应的注册码后,您将进行继续注册!";        
  229.     szField1 = "编号";   
  230.     svEdit1 = localNum;   
  231.     //nResult  = SdShowInfoList( szTitle, szMsg, list );    
  232.     //ListDestroy( list );       
  233.     nResult = SdShowDlgEdit1(szTitle, szMsg,szField1, svEdit1);          
  234.     //if (nResult = BACK) goto Dlg_SdLicense;   
  235.     if (nResult = BACK) goto Dlg_SdWelcome;   
  236. Dlg_SdRegisterUserEx:   
  237.     szMsg   = "请输入:用户名、公司名和注册号";   
  238.     szTitle = "xxxx系统";         
  239.     nResult = SdRegisterUserEx( szTitle, szMsg, szName, szCompany, szSerial );   
  240.     if (nResult = BACK) goto Dlg_SdShowInfoList;   
  241.     if (szSerial != checkString)  then        
  242.         MessageBox( "注册码输入错误!", SEVERE);   
  243.        goto Dlg_SdRegisterUserEx;       
  244.     endif;   
  245.                          
  246. Dlg_SdShowDlgEdit2:   
  247.     szTitle = "数据库信息";   
  248.     szMsg    = "请输入数据库用户名和数据库密码:";         
  249.     szField1 = "用户名";   
  250.     szField2 = "密码";   
  251.     svEdit1 = "root";   
  252.     svEdit2 = "password";        
  253.     nResult = SdShowDlgEdit2(szTitle, szMsg,szField1,szField2, svEdit1,svEdit2);    
  254.     if (nResult = BACK) goto Dlg_SdRegisterUserEx;   
  255.  //SdShowMsg ("下面进行数据库初始化操作,请勿手动关闭弹出窗口!", TRUE);   
  256.  //Delay(2);   
  257.     
  258.       
  259.    //启动mysql                                    
  260.    LaunchAppAndWait("net","start mysql",WAIT);   
  261.    //LaunchAppAndWait("net","stop mysql",WAIT);    
  262.    //LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);   
  263.   // LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -h localhost  -u root   -p password<" + SRCDIR ^ "test.sql",WAIT) ;   
  264.    //LaunchApp(WINDIR ^ "Notepad.exe",SRCDIR ^ "init.sql");    
  265.    //LaunchAppAndWait(SRCDIR ^ "sql.bat"," root password ",WAIT);    
  266.    ///LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe ","mysql  -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);   
  267.                                                                               
  268.     nResult = XCopyFile(SRCDIR + "\\sql.bat","c:\\xxx\\",EXCLUDE_SUBDIR);      
  269.     nResult = XCopyFile(SRCDIR + "\\init.sql","c:\\xxx\\",EXCLUDE_SUBDIR);       
  270.  //if (LaunchAppAndWait(SRCDIR + "\\sql.bat", " root password",WAIT) < 0) then   
  271.   //MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);   
  272.  //endif;             
  273.                                              
  274.  //NumToStr(tmpCheckString,LaunchAppAndWait("c:\\xxx\\sql.bat", " root password",WAIT));                                                               
  275.  //MessageBox(tmpCheckString,SEVERE);       
  276.     
  277.  if (LaunchAppAndWait("c:\\xxx\\sql.bat"" " + svEdit1 + " " + svEdit2 + " ",WAIT) < 0) then   
  278.   MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);   
  279.  endif;     
  280.     //DeleteDir("c:\\xxx\\",ALLCONTENTS); //删除这个临时目录            
  281.     DeleteFile("c:\\xxx\\sql.bat");   
  282.     DeleteFile("c:\\xxx\\init.sql");   
  283.       
  284.       
  285.       
  286. Dlg_SdAskDestPath:   
  287.     szTitle = "xxxx系统";   
  288.     szMsg   = "请选择安装目录";   
  289.     nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 );   
  290.     TARGETDIR = szDir;                                   
  291.     //if (nResult = BACK) goto Dlg_SdRegisterUserEx;   
  292.     if (nResult = BACK) goto Dlg_SdShowDlgEdit2;   
  293.     
  294. Dlg_SetupType:     
  295.     szTitle    = "xxxx系统";   
  296.     szMsg      =  "请选择安装类型";   
  297.     nResult = SetupType ( szTitle , szMsg , "" , nSetupType , 0 );   
  298.     if (nResult = BACK) then   
  299.         goto Dlg_SdAskDestPath;   
  300.     else  
  301.         nSetupType = nResult;   
  302.         if (nSetupType != CUSTOM) then   
  303.         szTargetPath = TARGETDIR;   
  304.         nvSize = 0;   
  305.         ComponentCompareSizeRequired(MEDIA,szTargetPath,nvSize);   
  306.         if (nvSize != 0) then        
  307.                 MessageBox( szSdStr_NotEnoughSpace, WARNING );   
  308.             goto Dlg_SetupType;   
  309.             endif;   
  310.         endif;     
  311.     endif;   
  312. Dlg_SdComponentTree:   
  313.     if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType;   
  314.     szTitle    = "xxxx系统";   
  315.     szMsg      = "";   
  316.     szTargetdir = TARGETDIR;   
  317.     szComponents = "";   
  318.     nLevel = 2;   
  319.     if (nSetupType = CUSTOM) then   
  320.       nResult = SdComponentTree(szTitle, szMsg, szTargetdir, szComponents, nLevel);   
  321.       if (nResult = BACK) goto Dlg_SetupType;    
  322.     endif;   
  323. Dlg_ObjDialogs:   
  324.     nResult = ShowObjWizardPages(nResult);   
  325.     if (nResult = BACK) goto Dlg_SdComponentTree;   
  326.       
  327. Dlg_SdSelectFolder:   
  328.     szfolder = SHELL_OBJECT_FOLDER;   
  329.     szTitle    = "xxxx系统";   
  330.     szMsg      = "";   
  331.     nResult    = SdSelectFolder( szTitle, szMsg, szfolder );   
  332.     SHELL_OBJECT_FOLDER = szfolder;   
  333.     if (nResult = BACK) goto Dlg_ObjDialogs;   
  334.     
  335. Dlg_SdStartCopy:   
  336.     szTitle = "xxxx系统";   
  337.     szMsg   = "安装信息收集完毕,并且获得安装权限,下一步将进行文件拷贝。";   
  338.     listStartCopy = ListCreate( STRINGLIST );   
  339.     //The following is an example of how to add a string(szName) to a list(listStartCopy).   
  340.     //eg. ListAddString(listStartCopy,szName,AFTER);   
  341.     nResult = SdStartCopy( szTitle, szMsg, listStartCopy );    
  342.     ListDestroy(listStartCopy);   
  343.     if (nResult = BACK) goto Dlg_SdSelectFolder;   
  344.     // setup default status   
  345.     SetStatusWindow(0, "");   
  346.     Enable(STATUSEX);   
  347.     StatusUpdate(ON, 100);   
  348.     return 0;   
  349. end;   
  350. ///////////////////////////////////////////////////////////////////////////////   
  351. //   
  352. //  FUNCTION:   OnMoving   
  353. //   
  354. //  EVENT:      Moving event is sent when file transfer is started as a result of   
  355. //              ComponentTransferData call, before any file transfer operations   
  356. //              are performed.   
  357. //   
  358. ///////////////////////////////////////////////////////////////////////////////   
  359. function OnMoving()   
  360.     string szAppPath;   
  361. begin   
  362.     // Set LOGO Compliance Application Path   
  363.     // TO DO : if your application .exe is in a subfolder of TARGETDIR then add subfolder   
  364.     szAppPath = TARGETDIR;   
  365.     RegDBSetItem(REGDB_APPPATH, szAppPath);   
  366.     RegDBSetItem(REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY);   
  367. end;   
  368. // --- include script file section ---   
  369. function OnEnd()                                       
  370. // //string  java_home, catalina_home, szKey, szEnv;   
  371. // string  szKey, szEnv, svClassPath;         
  372. // string icon_dir, xml_dir,output_dir;   
  373. // number nRegSize;   
  374. // pointer pEnv;   
  375. begin                 
  376. //          
  377. //   //catalina_home=TARGETDIR + "\\tomcat5.0.30";   
  378. //   //java_home=TARGETDIR + "\\j2sdk1.4.2_10";      
  379. //   szKey="Environment";   
  380. //   RegDBSetDefaultRoot(HKEY_CURRENT_USER);      
  381. //   //RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);   
  382. //   //RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);   
  383. //     
  384. //   //RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,nRegSize);      
  385. //   GetEnvVar ("CLASSPATH", svClassPath);   
  386. //   //MessageBox(svClassPath,0);   
  387. //   svClassPath = svClassPath + "; " + "c:\\xxx\\resc";       
  388. //   //MessageBox(svClassPath,0);   
  389. //   RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,-1)   ;   
  390. //   szEnv = "Environment";   
  391. //   pEnv = &szEnv;    
  392. //   //pEnv = AddressString(szEnv);     
  393. //   SendMessage(0xffff, 0x001A , 0, pEnv );   
  394. //     
  395. //   //MessageBox("sssss",0);     
  396.   
  397.                                                   
  398.    XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif",TARGETDIR,EXCLUDE_SUBDIR);    
  399.    XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg",TARGETDIR,EXCLUDE_SUBDIR);     
  400.    CreateDir(TARGETDIR ^ "resc\\");      
  401. end;   
  402.     
  403.     
  404.     
  405.     
  406.     
  407.     
  408.     
  409. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   
  410. ////////////////////////////////////////////////////////////////下面是一些设定tomcat或者jdk的环境变量的代码/////////////非本系统/////////////////   
  411. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   
  412. function OnEnd()       
  413. string  java_home, catalina_home, szKey, szEnv;         
  414. string icon_dir, xml_dir,output_dir;   
  415. POINTER pEnv;   
  416. begin                 
  417.   catalina_home=TARGETDIR + "\\tomcat5.0.30";   
  418.   java_home=TARGETDIR + "\\j2sdk1.4.2_10";      
  419.   szKey="Environment";   
  420.   RegDBSetDefaultRoot(HKEY_CURRENT_USER);      
  421.   RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);   
  422.   RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);   
  423.   szEnv = "Environment";   
  424.   pEnv = &szEnv;   
  425.   SendMessage (0xffff, 0x001A , 0, pEnv );   
  426.     
  427.     
  428.     
  429.    
////////////////////////////////////////////////////////////////////////////////
//                                                                           
//  File Name: Setup.rul                                                  
//                                                                           
//  Description: InstallShield script                                       
//                                                                           
//  Comments: This script was generated based on the selections you made in
//            the Project Wizard.  Refer to the help topic entitled "Modify     
//            the script that the Project Wizard generates" for information
//    on possible next steps.
//
/////////////////////////////////////////////an///////////////////////////////////

// Include header files
   
#include "ifx.h"
   
////////////////////// string defines ////////////////////////////
//////////////////// installation declarations ///////////////////
// ----- DLL function prototypes -----

    // your DLL function prototypes

// ---- script function prototypes -----

    // your script function prototypes
    // your global variables
 
NUMBER volumeNum;
//Before using the GetVolumeInformation API you will need to prototype it
prototype KERNEL32.GetVolumeInformation(BYREF STRING, BYREF STRING, NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, NUMBER);
//prototype for the custom InstallScript function
prototype GetVolumeSerial();
//function definition
function GetVolumeSerial()
STRING lpRootPathName;
STRING lpVolumeNameBuffer;
NUMBER nVolumeNameSize;
NUMBER lpVolumeSerialNumber;
NUMBER lpMaximumComponentLength;
NUMBER lpFileSystemFlags;
STRING lpFileSystemNameBuffer;
NUMBER nFileSystemNameSize;
BOOL APIReturn;
begin
  lpRootPathName="d:\\";
  nVolumeNameSize=60;
  nFileSystemNameSize=60;
  //APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);
  APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);
 
 
  if (APIReturn) then        
 
   volumeNum = lpVolumeSerialNumber ; 
   if (volumeNum < 0) then
    volumeNum = 0 - volumeNum;
   endif;     
   //NumToStr(volumeNum,lpVolumeSerialNumber);
    //SprintfBox(INFORMATION, "", "Volume= %s\nVolume Serial= %d", lpRootPathName, lpVolumeSerialNumber);
   if (volumeNum > 2139999999 - 135792468) then       
 
    //volumeNum = 123456789;
    volumeNum = volumeNum - volumeNum/100000000*100000000;
   endif;     
   
  else                    
 
     volumeNum = 123456789;
    //MessageBox("Failure.",0);
  endif;
end ;
prototype getNumString();
function getNumString()
  number numSpace;
  number numMen;
  string tmpString;
begin                                        
     //tmpNum = GetWindowHandle(HWND_INSTALL);  //安装主窗口的句柄 
     //numSpace = GetDiskSpace("c:\\"); //指定驱动器上的空闲磁盘空间 
     numSpace = GetDiskSpaceEx("c:\\",KBYTES); //指定驱动器上的空闲磁盘空间        BYTES 
     //numMen = GetMemFree();  //运行在Microsoft Windows下的一个应用程序可用的内存大小    
     numMen = GetDiskSpaceEx("d:\\",KBYTES);
     if numSpace < 10000 then
        numSpace = 11360000;
     else
      numSpace = (numSpace - numSpace/10000*10000)*10000;
     endif;
     if numMen < 10000 then
        numMen = 7521;  
     else
      numMen = numMen - numMen/10000*10000;
     endif;                                                  
     volumeNum = 100000000 + numSpace + numMen; 
    
     //NumToStr(tmpString,volumeNum);     
    // MessageBox(tmpString,0);                            
end;  
 
 
 
//////////////////////////////////////////////////////////////////////////////
//                                                                          
//  FUNCTION:   OnFirstUIBefore                                           
//                                                                          
//  EVENT:      FirstUIBefore event is sent when installation is run for the first
//              time on given machine. In the handler installation usually displays
//              UI allowing end user to specify installation parameters. After this
//              function returns, ComponentTransferData is called to perform file
//              transfer.
//                                                                          
///////////////////////////////////////////////////////////////////////////////
function OnFirstUIBefore()
    number  nResult,nSetupType;
    string  szTitle, szMsg;
    string  szLicenseFile, szQuestion;
    string  szName, szCompany, szSerial;
    string  szFile;
    string  szTargetPath;
    string  szDir;
    string  szfolder;
    string  szComponents, szTargetdir;
    number  nLevel;
    LIST    listStartCopy;
    LIST    list;
    number  nvSize;    
   
    string szField1, svEdit1,szField2, svEdit2;
                     
    string localNum;  
    number tmpNum;     
    string tmpCheckString;
    string checkString;
begin 
    // TO DO: if you want to enable background, window title, and caption bar title                                                                    
    // SetTitle( @TITLE_MAIN, 24, WHITE );                                       
    // SetTitle( @TITLE_CAPTIONBAR, 0, BACKGROUNDCAPTION );                    
    // Enable( FULLWINDOWMODE );        
    // Enable( BACKGROUND );        
    // SetColor(BACKGROUND,RGB (0, 128, 128));       
          
    GetVolumeSerial();                    
    //getNumString();
   
    tmpNum =  volumeNum;             
    tmpNum = tmpNum - tmpNum / 100 * 100;  
    NumToStr(tmpCheckString,tmpNum);    
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif;
    checkString = "B" + tmpCheckString + "_";     
   
    tmpNum =  volumeNum / 100;             
    tmpNum = tmpNum - tmpNum / 100 * 100;  
    NumToStr(tmpCheckString,tmpNum);   
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif;
    checkString = checkString + "K" + tmpCheckString + "_";
   
    tmpNum =  volumeNum / 10000;             
    tmpNum = tmpNum - tmpNum / 100 * 100;  
    NumToStr(tmpCheckString,tmpNum);  
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif;
    checkString = checkString + "X" + tmpCheckString + "_";
   
    tmpNum =  volumeNum / 1000000;             
    tmpNum = tmpNum - tmpNum / 100 * 100;  
    NumToStr(tmpCheckString,tmpNum);
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif; 
    checkString = checkString + "T" + tmpCheckString;
                                                   
    //MessageBox(checkString,INFORMATION); 
      
    //变换volumeNum的值
    //B3242_K423_X342_T3423   
    volumeNum = volumeNum + 135792468;           
    NumToStr(localNum,volumeNum);                                                   
    //MessageBox(localNum,INFORMATION);
   
                        
    //copy images                                                                                                                                 
   nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif", "c:\\xxx\\icons\\media\\",EXCLUDE_SUBDIR);                                                                                                 
   nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg", "c:\\xxx\\icons\\teacher\\",EXCLUDE_SUBDIR);   
   CreateDir("c:\\xxx\\resc\\");                      
        
   if (nResult != 0) then       
         MessageBox ("图片拷贝出错!", SEVERE);
   endif;
   
       
       
       
       
      
      
      
    nSetupType = TYPICAL; 
    TARGETDIR = PROGRAMFILES ^@COMPANY_NAME ^@PRODUCT_NAME; 
    szDir = TARGETDIR;
    SHELL_OBJECT_FOLDER = @FOLDER_NAME;
    szName    = "";
    szCompany = "";
    szSerial = "";
Dlg_Start:
    // beginning of dialogs label
Dlg_SdWelcome:
    szTitle = "xxxx系统";
    szMsg   = "  确定是否继续安装?继续请按【下一步(next)】";
    nResult = SdWelcome( szTitle, szMsg );
    if (nResult = BACK) goto Dlg_Start;
//Dlg_SdLicense:
//    szLicenseFile = SUPPORTDIR ^ "license.txt";
//    szTitle    = "xxxx系统";
//    szMsg      = "许可协议";
//    szQuestion = "您是否接受该协议?接受请按【是(Yes)】。继续安装必须接受该协议。";
//    nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );
//    if (nResult = BACK) goto Dlg_SdWelcome;
Dlg_SdShowInfoList:     
    //szFile = SUPPORTDIR ^ "infolist.txt";
    //list = ListCreate( STRINGLIST );
    //ListReadFromFile( list, szFile );
    szTitle = "系统本地编号";
    szMsg    = "将下面的本地编号发送给权限授予机构,在接收到相应的注册码后,您将进行继续注册!";     
    szField1 = "编号";
    svEdit1 = localNum;
    //nResult  = SdShowInfoList( szTitle, szMsg, list ); 
    //ListDestroy( list );    
    nResult = SdShowDlgEdit1(szTitle, szMsg,szField1, svEdit1);       
    //if (nResult = BACK) goto Dlg_SdLicense;
    if (nResult = BACK) goto Dlg_SdWelcome;
Dlg_SdRegisterUserEx:
    szMsg   = "请输入:用户名、公司名和注册号";
    szTitle = "xxxx系统";      
    nResult = SdRegisterUserEx( szTitle, szMsg, szName, szCompany, szSerial );
    if (nResult = BACK) goto Dlg_SdShowInfoList;
    if (szSerial != checkString)  then     
        MessageBox( "注册码输入错误!", SEVERE);
       goto Dlg_SdRegisterUserEx;    
    endif;
                      
Dlg_SdShowDlgEdit2:
    szTitle = "数据库信息";
    szMsg    = "请输入数据库用户名和数据库密码:";      
    szField1 = "用户名";
    szField2 = "密码";
    svEdit1 = "root";
    svEdit2 = "password";     
    nResult = SdShowDlgEdit2(szTitle, szMsg,szField1,szField2, svEdit1,svEdit2); 
    if (nResult = BACK) goto Dlg_SdRegisterUserEx;
 //SdShowMsg ("下面进行数据库初始化操作,请勿手动关闭弹出窗口!", TRUE);
 //Delay(2);
 
   
   //启动mysql                                 
   LaunchAppAndWait("net","start mysql",WAIT);
   //LaunchAppAndWait("net","stop mysql",WAIT); 
   //LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);
  // LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -h localhost  -u root   -p password<" + SRCDIR ^ "test.sql",WAIT) ;
   //LaunchApp(WINDIR ^ "Notepad.exe",SRCDIR ^ "init.sql"); 
   //LaunchAppAndWait(SRCDIR ^ "sql.bat"," root password ",WAIT); 
   ///LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe ","mysql  -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);
                                                                           
    nResult = XCopyFile(SRCDIR + "\\sql.bat","c:\\xxx\\",EXCLUDE_SUBDIR);   
    nResult = XCopyFile(SRCDIR + "\\init.sql","c:\\xxx\\",EXCLUDE_SUBDIR);    
 //if (LaunchAppAndWait(SRCDIR + "\\sql.bat", " root password",WAIT) < 0) then
  //MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);
 //endif;          
                                          
 //NumToStr(tmpCheckString,LaunchAppAndWait("c:\\xxx\\sql.bat", " root password",WAIT));                                                            
 //MessageBox(tmpCheckString,SEVERE);    
 
 if (LaunchAppAndWait("c:\\xxx\\sql.bat", " " + svEdit1 + " " + svEdit2 + " ",WAIT) < 0) then
  MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);
 endif;  
    //DeleteDir("c:\\xxx\\",ALLCONTENTS); //删除这个临时目录         
    DeleteFile("c:\\xxx\\sql.bat");
    DeleteFile("c:\\xxx\\init.sql");
   
   
   
Dlg_SdAskDestPath:
    szTitle = "xxxx系统";
    szMsg   = "请选择安装目录";
    nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 );
    TARGETDIR = szDir;                                
    //if (nResult = BACK) goto Dlg_SdRegisterUserEx;
    if (nResult = BACK) goto Dlg_SdShowDlgEdit2;
 
Dlg_SetupType:  
    szTitle    = "xxxx系统";
    szMsg      =  "请选择安装类型";
    nResult = SetupType ( szTitle , szMsg , "" , nSetupType , 0 );
    if (nResult = BACK) then
        goto Dlg_SdAskDestPath;
    else
        nSetupType = nResult;
        if (nSetupType != CUSTOM) then
        szTargetPath = TARGETDIR;
        nvSize = 0;
        ComponentCompareSizeRequired(MEDIA,szTargetPath,nvSize);
        if (nvSize != 0) then     
                MessageBox( szSdStr_NotEnoughSpace, WARNING );
            goto Dlg_SetupType;
            endif;
        endif;  
    endif;
Dlg_SdComponentTree:
    if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType;
    szTitle    = "xxxx系统";
    szMsg      = "";
    szTargetdir = TARGETDIR;
    szComponents = "";
    nLevel = 2;
    if (nSetupType = CUSTOM) then
      nResult = SdComponentTree(szTitle, szMsg, szTargetdir, szComponents, nLevel);
      if (nResult = BACK) goto Dlg_SetupType; 
    endif;
Dlg_ObjDialogs:
    nResult = ShowObjWizardPages(nResult);
    if (nResult = BACK) goto Dlg_SdComponentTree;
   
Dlg_SdSelectFolder:
    szfolder = SHELL_OBJECT_FOLDER;
    szTitle    = "xxxx系统";
    szMsg      = "";
    nResult    = SdSelectFolder( szTitle, szMsg, szfolder );
    SHELL_OBJECT_FOLDER = szfolder;
    if (nResult = BACK) goto Dlg_ObjDialogs;
 
Dlg_SdStartCopy:
    szTitle = "xxxx系统";
    szMsg   = "安装信息收集完毕,并且获得安装权限,下一步将进行文件拷贝。";
    listStartCopy = ListCreate( STRINGLIST );
    //The following is an example of how to add a string(szName) to a list(listStartCopy).
    //eg. ListAddString(listStartCopy,szName,AFTER);
    nResult = SdStartCopy( szTitle, szMsg, listStartCopy ); 
    ListDestroy(listStartCopy);
    if (nResult = BACK) goto Dlg_SdSelectFolder;
    // setup default status
    SetStatusWindow(0, "");
    Enable(STATUSEX);
    StatusUpdate(ON, 100);
    return 0;
end;
///////////////////////////////////////////////////////////////////////////////
//
//  FUNCTION:   OnMoving
//
//  EVENT:      Moving event is sent when file transfer is started as a result of
//              ComponentTransferData call, before any file transfer operations
//              are performed.
//
///////////////////////////////////////////////////////////////////////////////
function OnMoving()
    string szAppPath;
begin
    // Set LOGO Compliance Application Path
    // TO DO : if your application .exe is in a subfolder of TARGETDIR then add subfolder
    szAppPath = TARGETDIR;
    RegDBSetItem(REGDB_APPPATH, szAppPath);
    RegDBSetItem(REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY);
end;
// --- include script file section ---
function OnEnd()                                    
// //string  java_home, catalina_home, szKey, szEnv;
// string  szKey, szEnv, svClassPath;      
// string icon_dir, xml_dir,output_dir;
// number nRegSize;
// pointer pEnv;
begin              
//       
//   //catalina_home=TARGETDIR + "\\tomcat5.0.30";
//   //java_home=TARGETDIR + "\\j2sdk1.4.2_10";   
//   szKey="Environment";
//   RegDBSetDefaultRoot(HKEY_CURRENT_USER);   
//   //RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);
//   //RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);
//  
//   //RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,nRegSize);   
//   GetEnvVar ("CLASSPATH", svClassPath);
//   //MessageBox(svClassPath,0);
//   svClassPath = svClassPath + "; " + "c:\\xxx\\resc";    
//   //MessageBox(svClassPath,0);
//   RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,-1)   ;
//   szEnv = "Environment";
//   pEnv = &szEnv; 
//   //pEnv = AddressString(szEnv);  
//   SendMessage(0xffff, 0x001A , 0, pEnv );
//  
//   //MessageBox("sssss",0);  

                                               
   XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif",TARGETDIR,EXCLUDE_SUBDIR); 
   XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg",TARGETDIR,EXCLUDE_SUBDIR);  
   CreateDir(TARGETDIR ^ "resc\\");   
end;
 
 
 
 
 
 
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////下面是一些设定tomcat或者jdk的环境变量的代码/////////////非本系统/////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function OnEnd()    
string  java_home, catalina_home, szKey, szEnv;      
string icon_dir, xml_dir,output_dir;
POINTER pEnv;
begin              
  catalina_home=TARGETDIR + "\\tomcat5.0.30";
  java_home=TARGETDIR + "\\j2sdk1.4.2_10";   
  szKey="Environment";
  RegDBSetDefaultRoot(HKEY_CURRENT_USER);   
  RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);
  RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);
  szEnv = "Environment";
  pEnv = &szEnv;
  SendMessage (0xffff, 0x001A , 0, pEnv );
 
 
 
 

 

 

 对应的 vb 注册码解码的核心程序(KeyGen.frm)如下:

 

 

C代码
  1. VERSION 5.00   
  2. Begin VB.Form keyGen    
  3.    Appearance      =   0  'Flat   
  4.    BackColor       =   &H80000001&   
  5.    BorderStyle     =   5  'Sizable ToolWindow   
  6.    Caption         =   "**系统注册码生成器"  
  7.    ClientHeight    =   1290   
  8.    ClientLeft      =   60   
  9.    ClientTop       =   330   
  10.    ClientWidth     =   4545   
  11.    DrawMode        =   1  'Blackness   
  12.    FillStyle       =   0  'Solid   
  13.    LinkTopic       =   "Form1"  
  14.    MaxButton       =   0   'False   
  15.    MinButton       =   0   'False   
  16.    OLEDropMode     =   1  'Manual   
  17.    ScaleHeight     =   1290   
  18.    ScaleMode       =   0  'User   
  19.    ScaleWidth      =   4545   
  20.    ShowInTaskbar   =   0   'False   
  21.    StartUpPosition =   1  '所有者中心   
  22.    Begin VB.CommandButton genButton    
  23.       Appearance      =   0  'Flat   
  24.       BackColor       =   &H80000001&   
  25.       Caption         =   "生成"  
  26.       Height          =   300   
  27.       Left            =   3480   
  28.       MaskColor       =   &H80000001&   
  29.       Style           =   1  'Graphical   
  30.       TabIndex        =   4   
  31.       Top             =   240   
  32.       UseMaskColor    =   -1  'True   
  33.       Width           =   615   
  34.    End   
  35.    Begin VB.TextBox snText    
  36.       Appearance      =   0  'Flat   
  37.       BackColor       =   &H80000001&   
  38.       Height          =   300   
  39.       Left            =   960   
  40.       Locked          =   -1  'True   
  41.       TabIndex        =   3   
  42.       Top             =   720   
  43.       Width           =   3135   
  44.    End   
  45.    Begin VB.TextBox machineText    
  46.       Appearance      =   0  'Flat   
  47.       BackColor       =   &H80000001&   
  48.       Height          =   300   
  49.       Left            =   960   
  50.       TabIndex        =   2   
  51.       Top             =   240   
  52.       Width           =   2295   
  53.    End   
  54.    Begin VB.Label snLabel    
  55.       Alignment       =   2  'Center   
  56.       Appearance      =   0  'Flat   
  57.       BackColor       =   &H80000001&   
  58.       BackStyle       =   0  'Transparent   
  59.       Caption         =   "注册码"  
  60.       ForeColor       =   &H80000008&   
  61.       Height          =   255   
  62.       Left            =   240   
  63.       TabIndex        =   1   
  64.       Top             =   840   
  65.       Width           =   735   
  66.    End   
  67.    Begin VB.Label machineLabel    
  68.       Alignment       =   2  'Center   
  69.       Appearance      =   0  'Flat   
  70.       BackColor       =   &H80000001&   
  71.       BackStyle       =   0  'Transparent   
  72.       Caption         =   "机器码"  
  73.       ForeColor       =   &H80000008&   
  74.       Height          =   255   
  75.       Left            =   240   
  76.       TabIndex        =   0   
  77.       Top             =   360   
  78.       Width           =   735   
  79.       WordWrap        =   -1  'True   
  80.    End   
  81. End   
  82. Attribute VB_Name = "keyGen"  
  83. Attribute VB_GlobalNameSpace = False   
  84. Attribute VB_Creatable = False   
  85. Attribute VB_PredeclaredId = True   
  86. Attribute VB_Exposed = False   
  87.   
  88.   
  89. Private Sub genButton_Click()   
  90.     Dim distNum As Double   
  91.     Dim intTmp As Double   
  92.     Dim mid As Long   
  93.     Dim strSN As String   
  94.        
  95.        
  96.     If (VBA.Trim(machineText) <> "") Then   
  97.         If (IsNumeric(VBA.Trim(machineText)) And VBA.Trim(machineText) > 135792468 And VBA.Trim(machineText) < 2139999999) Then   
  98.             distNum = machineText   
  99.         Else   
  100.             distNum = 123456789 + 135792468   
  101.         End If   
  102.         distNum = distNum - 135792468   
  103.            
  104.            
  105.         strSN = "B"  
  106.         intTmp = distNum   
  107.         mid = intTmp - Fix(intTmp / 100) * 100   
  108.         If mid = 0 Then   
  109.             strSN = strSN + "0X"  
  110.         Else   
  111.             strSN = strSN + VBA.Trim(Str(mid))   
  112.         End If   
  113.         strSN = strSN + "_"  
  114.            
  115.            
  116.         strSN = strSN + "K"  
  117.         intTmp = Fix(intTmp / 100)   
  118.         mid = intTmp - Fix(intTmp / 100) * 100   
  119.         If mid = 0 Then   
  120.             strSN = strSN + "0X"  
  121.         Else   
  122.             strSN = strSN + VBA.Trim(Str(mid))   
  123.         End If   
  124.         strSN = strSN + "_"  
  125.            
  126.            
  127.         strSN = strSN + "X"  
  128.         intTmp = Fix(intTmp / 100)   
  129.         mid = intTmp - Fix(intTmp / 100) * 100   
  130.         If mid = 0 Then   
  131.             strSN = strSN + "0X"  
  132.         Else   
  133.             strSN = strSN + VBA.Trim(Str(mid))   
  134.         End If   
  135.         strSN = strSN + "_"  
  136.            
  137.            
  138.         strSN = strSN + "T"  
  139.         intTmp = Fix(intTmp / 100)   
  140.         mid = intTmp - Fix(intTmp / 100) * 100   
  141.         If mid = 0 Then   
  142.             strSN = strSN + "0X"  
  143.         Else   
  144.             strSN = strSN + VBA.Trim(Str(mid))   
  145.         End If   
  146.            
  147.         snText = strSN   
  148.            
  149.     End If   
  150. End Sub  
VERSION 5.00
Begin VB.Form keyGen 
   Appearance      =   0  'Flat
   BackColor       =   &H80000001&
   BorderStyle     =   5  'Sizable ToolWindow
   Caption         =   "**系统注册码生成器"
   ClientHeight    =   1290
   ClientLeft      =   60
   ClientTop       =   330
   ClientWidth     =   4545
   DrawMode        =   1  'Blackness
   FillStyle       =   0  'Solid
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   OLEDropMode     =   1  'Manual
   ScaleHeight     =   1290
   ScaleMode       =   0  'User
   ScaleWidth      =   4545
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  '所有者中心
   Begin VB.CommandButton genButton 
      Appearance      =   0  'Flat
      BackColor       =   &H80000001&
      Caption         =   "生成"
      Height          =   300
      Left            =   3480
      MaskColor       =   &H80000001&
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   240
      UseMaskColor    =   -1  'True
      Width           =   615
   End
   Begin VB.TextBox snText 
      Appearance      =   0  'Flat
      BackColor       =   &H80000001&
      Height          =   300
      Left            =   960
      Locked          =   -1  'True
      TabIndex        =   3
      Top             =   720
      Width           =   3135
   End
   Begin VB.TextBox machineText 
      Appearance      =   0  'Flat
      BackColor       =   &H80000001&
      Height          =   300
      Left            =   960
      TabIndex        =   2
      Top             =   240
      Width           =   2295
   End
   Begin VB.Label snLabel 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H80000001&
      BackStyle       =   0  'Transparent
      Caption         =   "注册码"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   840
      Width           =   735
   End
   Begin VB.Label machineLabel 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H80000001&
      BackStyle       =   0  'Transparent
      Caption         =   "机器码"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   735
      WordWrap        =   -1  'True
   End
End
Attribute VB_Name = "keyGen"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Private Sub genButton_Click()
    Dim distNum As Double
    Dim intTmp As Double
    Dim mid As Long
    Dim strSN As String
    
    
    If (VBA.Trim(machineText) <> "") Then
        If (IsNumeric(VBA.Trim(machineText)) And VBA.Trim(machineText) > 135792468 And VBA.Trim(machineText) < 2139999999) Then
            distNum = machineText
        Else
            distNum = 123456789 + 135792468
        End If
        distNum = distNum - 135792468
        
        
        strSN = "B"
        intTmp = distNum
        mid = intTmp - Fix(intTmp / 100) * 100
        If mid = 0 Then
            strSN = strSN + "0X"
        Else
            strSN = strSN + VBA.Trim(Str(mid))
        End If
        strSN = strSN + "_"
        
        
        strSN = strSN + "K"
        intTmp = Fix(intTmp / 100)
        mid = intTmp - Fix(intTmp / 100) * 100
        If mid = 0 Then
            strSN = strSN + "0X"
        Else
            strSN = strSN + VBA.Trim(Str(mid))
        End If
        strSN = strSN + "_"
        
        
        strSN = strSN + "X"
        intTmp = Fix(intTmp / 100)
        mid = intTmp - Fix(intTmp / 100) * 100
        If mid = 0 Then
            strSN = strSN + "0X"
        Else
            strSN = strSN + VBA.Trim(Str(mid))
        End If
        strSN = strSN + "_"
        
        
        strSN = strSN + "T"
        intTmp = Fix(intTmp / 100)
        mid = intTmp - Fix(intTmp / 100) * 100
        If mid = 0 Then
            strSN = strSN + "0X"
        Else
            strSN = strSN + VBA.Trim(Str(mid))
        End If
        
        snText = strSN
        
    End If
End Sub


 

你可能感兴趣的:(Call API in InstallShield 2009)