【问题标题】:character ASCII code in InstallScript InstallShieldInstallScript InstallShield 中的字符 ASCII 代码
【发布时间】:2011-09-14 10:37:56
【问题描述】:

我想阻止用户在安装程序的密码字段之一中输入字符 > ASCII 127。

我用谷歌搜索但没有找到任何直接的方法,目前我正在使用:

CHAR ch;
STRING ASCII;
NUMBER nASCII;

for nCount = 0 to StrLength(sPassword)
  ch = sPassword[nCount];
  sprintf(ASCII,"%d",ch);

  StrToNum(nASCII,ASCII);

  if ( nASCII > 127 )
    MessageBox("Invalid Character in Password",INFORMATION);
  endif; 

endfor;

有没有更好的方法从字符串中获取 ASCII 码?

【问题讨论】:

    标签: windows-installer installshield installscript installscript-msi


    【解决方案1】:

    首先,我会避免与字符串之间的转换;只需将sPassword[nCount]127 直接比较即可; InstallScript 存储宽字符(16 位数字)。

    作为替代方法,您可以尝试使用 US-ASCII code page (20127) 调用 WideCharToMultiByte。我对 InstallScript 不是很擅长,并且在没有编译器的情况下进行编码,因此您可能需要修复一两个错误,但这是一个粗略的想法:

    #define CP_US_ASCII 20127
    extern prototype NUMBER Kernel32.WideCharToMultiByte(NUMBER, NUMBER, WSTRING, NUMBER, STRING, NUMBER, STRING, BYREF BOOL);
    
    function BOOL IsSafeAscii(STRING szCheck)
        STRING szOut;
        BOOL bReplaced;
    begin
        WideCharToMultiBute(CP_US_ASCII,          // only supports characters 0-127
                            WC_NO_BEST_FIT_CHARS, // or maybe 0; disallow turning accented to plain
                            szCheck,              // test string
                            StrLength(szCheck),   // length of test string
                            szOut,                // return buffer
                            StrLength(szOut),     // length of return buffer
                            "?",                  // replacement for unsupported characters
                            bReplaced);           // whether replacement was used
        return !bReplaced;
    end;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多