根据CPU序列号和磁盘序列号设计软件注册程序(十九)

 

根据 CPU 序列号和磁盘序列号设计软件注册程序 ( 十九 )
本文讲述如何通过 CPU 序列号和磁盘序列号来生成软件注册程序。
1.      创建对话框工程: CPUAndDiskReg
2.      创建一个按钮“生成序列号”,代码如下:
       CString code [16] = { "ad" , "eh" , "im" , "np" , "ru" , "vy" , "zc" , "gk" ,
       "pt" , "xb" , "fj" , "ox" , "wa" , "ei" , "nr" , "qu" };
       CString reg , stred ;
       int num ;
       m_machine . GetWindowText ( stred );
       stred . MakeLower ();
       for ( int i = 0; i <10; i ++)
       {
              char p = stred . GetAt ( i );
              if ( p >= 'a' && p <= 'f' )
                     num = p - 'a' +10;
              else
                     num = p - '0' ;
              CString tmp = code [ num ];
              reg += tmp ;
       }
 
       reg . MakeUpper ();
       GetDlgItem ( IDC_NUM1 )-> SetWindowText ( reg . Mid (0,5));
       GetDlgItem ( IDC_NUM2 )-> SetWindowText ( reg . Mid (5,5));
       GetDlgItem ( IDC_NUM3 )-> SetWindowText ( reg . Mid (10,5));
       GetDlgItem ( IDC_NUM4 )-> SetWindowText ( reg . Mid (15,5));
3.      OnInitDialog () 中添加代码如下,来获取 CPU 序列号和 C 盘序列号,并产生机器码。
       unsigned long s1 , s2 ;
       char sel ;
       sel = '1' ;
       CString MyCpuID , CPUID1 , CPUID2 ;
       __asm {
              mov eax,01h
                     xor edx,edx
                     cpuid
                     mov s1 ,edx
                     mov s2 ,eax
       }
       CPUID1 . Format ( "%08X%08X" , s1 , s2 );
       __asm {
              mov eax,03h
                     xor ecx,ecx
                     xor edx,edx
                     cpuid
                     mov s1 ,edx
                     mov s2 ,ecx
       }
       CPUID2 . Format ( "%08X%08X" , s1 , s2 );
 
       MyCpuID = CPUID1 + CPUID2 ;
       m_cpu . SetWindowText ( MyCpuID );
       DWORD ser ;
       char namebuf [128];
       char filebuf [128];
       :: GetVolumeInformation ( "c://" , namebuf ,128,& ser ,0,0, filebuf ,128);
       CString strdisk ;
       strdisk . Format ( "%d" , ser );
       CString strmachine ;
       strmachine = MyCpuID . Mid (13,5);
       strmachine += strdisk . Mid (3,5);
       m_disk . SetWindowText ( strdisk );
       m_machine . SetWindowText ( strmachine );
       完成。

 

你可能感兴趣的:(c,IM,disk,磁盘)