BOOL CEnumerateSerial::UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames) #endif { //Make sure we clear out any elements which may already be in the array(s) #if defined CENUMERATESERIAL_USE_STL ports.clear(); friendlyNames.clear(); #else ports.RemoveAll(); friendlyNames.RemoveAll(); #endif //What will be the return value BOOL bSuccess = FALSE; //Create the WBEM locator IWbemLocator* pLocator = NULL; HRESULT hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&pLocator)); if (SUCCEEDED(hr)) { IWbemServices* pServices = NULL; hr = pLocator->ConnectServer(_bstr_t("\\\\.\\root\\cimv2"), NULL, NULL, NULL, 0, NULL, NULL, &pServices); if (SUCCEEDED(hr)) { //Execute the query IEnumWbemClassObject* pClassObject = NULL; hr = pServices->CreateInstanceEnum(_bstr_t("Win32_SerialPort"), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &pClassObject); if (SUCCEEDED(hr)) { bSuccess = TRUE; //Now enumerate all the ports hr = WBEM_S_NO_ERROR; //Final Next will return WBEM_S_FALSE while (hr == WBEM_S_NO_ERROR) { ULONG uReturned = 0; IWbemClassObject* apObj[10]; memset(apObj, 0, sizeof(apObj)); hr = pClassObject->Next(WBEM_INFINITE, 10, reinterpret_cast<IWbemClassObject**>(apObj), &uReturned); if (SUCCEEDED(hr)) { for (ULONG n=0; n<uReturned; n++) { VARIANT varProperty1; VariantInit(&varProperty1); HRESULT hrGet = apObj[n]->Get(L"DeviceID", 0, &varProperty1, NULL, NULL); if (SUCCEEDED(hrGet) && (varProperty1.vt == VT_BSTR) && (wcslen(varProperty1.bstrVal) > 3)) { //If it looks like "COMX" then add it to the array which will be returned if ((_wcsnicmp(varProperty1.bstrVal, L"COM", 3) == 0) && IsNumeric(&(varProperty1.bstrVal[3]), TRUE)) { //Work out the port number int nPort = _wtoi(&(varProperty1.bstrVal[3])); #if defined CENUMERATESERIAL_USE_STL ports.push_back(nPort); #else ports.Add(nPort); #endif //Also get the friendly name of the port VARIANT varProperty2; VariantInit(&varProperty2); if (SUCCEEDED(apObj[n]->Get(L"Name", 0, &varProperty2, NULL, NULL)) && (varProperty2.vt == VT_BSTR)) { #if defined CENUMERATESERIAL_USE_STL #if defined _UNICODE std::wstring szName(varProperty2.bstrVal); #else CAutoHeapAlloc szAsciiValue; int nLengthA = WideCharToMultiByte(CP_ACP, 0, varProperty2.bstrVal, -1, NULL, 0, NULL, NULL); if (nLengthA) { if (szAsciiValue.Allocate(nLengthA)) WideCharToMultiByte(CP_ACP, 0, varProperty2.bstrVal, -1, static_cast<LPSTR>(szAsciiValue.m_pData), nLengthA, NULL, NULL); } std::string szName(static_cast<LPSTR>(szAsciiValue.m_pData)); #endif friendlyNames.push_back(szName); #else friendlyNames.Add(CString(varProperty2.bstrVal)); #endif } else { #if defined CENUMERATESERIAL_USE_STL friendlyNames.push_back(_T("")); #else friendlyNames.Add(_T("")); #endif } //Free up the variant; VariantClear(&varProperty2); } } //Free up the variant; VariantClear(&varProperty1); //Free up each COM interface apObj[n]->Release(); } } } //Free up the COM interface pClassObject->Release(); } //Free up the COM interface pServices->Release(); } //Free up the COM interface pLocator->Release(); } return bSuccess; }
void CBacnetUserConfig::OnBnClickedButtonUserOk() { // TODO: Add your control notification handler code here char temp_buffer[255]; int compare_ret = 0; CString temp_enter_original; CString first_pw; CString second_pw; CString temp_user_name; CString access_string; switch(ok_button_stage) { case stage_enter_original_password://检查原始密码是否正确; { //m_user_login_data.at(m_slected_item).password GetDlgItemTextW(IDC_EDIT_USER_NAME,temp_user_name); GetDlgItemTextW(IDC_EDIT_USER_PASSWORD,temp_enter_original); if(temp_user_name.IsEmpty()) { MessageBox(_T("user name is empty"),_T("Warning"),MB_OK); return; } if(temp_user_name.GetLength()>=STR_USER_NAME_LENGTH) { MessageBox(_T("User name is too long!"),_T("Warning"),MB_OK); return; } if(temp_enter_original.IsEmpty()) { MessageBox(_T("Password is empty"),_T("Warning"),MB_OK); return; } memset(temp_buffer,0,255); WideCharToMultiByte(CP_ACP,NULL,temp_enter_original.GetBuffer(),-1,temp_buffer,255,NULL,NULL); compare_ret = strcmp(temp_buffer,m_user_login_data.at(m_slected_item).password); if(compare_ret == 0) { ok_button_stage = stage_enter_new_password; Enable_Window_Stage(ENTER_NEW_PASSWORD); } else { SetDlgItemTextW(IDC_EDIT_USER_PASSWORD,_T("")); MessageBox(_T("Password error"),_T("Warning"),MB_OK); GetDlgItem(IDC_EDIT_USER_PASSWORD)->SetFocus(); return; } } break; case stage_enter_new_password: { GetDlgItemTextW(IDC_EDIT_USER_NEW_PASSWORD,first_pw); if(first_pw.IsEmpty()) { MessageBox(_T("Password is empty"),_T("Warning"),MB_OK); return; } if(first_pw.GetLength()>=STR_USER_PASSWORD_LENGTH) { MessageBox(_T("Password too long!"),_T("Warning"),MB_OK); return; } ok_button_stage = stage_retype_password; Enable_Window_Stage(RETYPE_NEW_PASSWORD); } break; case stage_retype_password: { GetDlgItemTextW(IDC_EDIT_USER_NEW_PASSWORD,first_pw); GetDlgItemTextW(IDC_EDIT_USER_RETYPE_PASSWORD,second_pw); GetDlgItemTextW(IDC_EDIT_USER_NAME,temp_user_name); GetDlgItemTextW(IDC_COMBO_ACCESS_LEVEL,access_string); if(second_pw.IsEmpty()) { MessageBox(_T("Password is empty"),_T("Warning"),MB_OK); return; } if(second_pw.GetLength()>=STR_USER_PASSWORD_LENGTH) { MessageBox(_T("Password too long!"),_T("Warning"),MB_OK); return; } if(first_pw.CompareNoCase(second_pw) == 0) { if(temp_user_name.IsEmpty()) { MessageBox(_T("user name is empty"),_T("Warning"),MB_OK); return; } memset(temp_buffer,0,255); WideCharToMultiByte(CP_ACP,NULL,temp_user_name.GetBuffer(),-1,temp_buffer,255,NULL,NULL); memcpy(m_user_login_data.at(m_slected_item).name,temp_buffer,STR_USER_NAME_LENGTH); if(access_string.CompareNoCase(_T("View only")) == 0 ) { m_user_login_data.at(m_slected_item).access_level = 1; } else if(access_string.CompareNoCase(_T("Graphic Mode")) == 0) { m_user_login_data.at(m_slected_item).access_level = 3; } else if(access_string.CompareNoCase(_T("Routine Mode")) == 0) { m_user_login_data.at(m_slected_item).access_level = 4; } else m_user_login_data.at(m_slected_item).access_level = 2; //_T("View only")); //_T("Full access")); memset(temp_buffer,0,255); WideCharToMultiByte(CP_ACP,NULL,second_pw.GetBuffer(),-1,temp_buffer,255,NULL,NULL); memcpy(m_user_login_data.at(m_slected_item).password,temp_buffer,STR_USER_PASSWORD_LENGTH); //Post_Write_Message(g_bac_instance,WRITEUSER_T3000,m_slected_item,m_slected_item,sizeof(Str_userlogin_point),m_user_config_hwnd ,_T(""),m_slected_item,m_slected_item); int temp_invoke_id = -1; int send_status = true; int resend_count = 0; for (int z=0;z<3;z++) { do { resend_count ++; if(resend_count>5) { send_status = false; break; } temp_invoke_id = WritePrivateData(g_bac_instance,WRITEUSER_T3000,m_slected_item,m_slected_item); Sleep(SEND_COMMAND_DELAY_TIME); } while (g_invoke_id<0); if(send_status) { Sleep(1000); if(tsm_invoke_id_free(temp_invoke_id)) { ok_button_stage = 0; PostMessage(WM_REFRESH_BAC_USER_NAME_LIST,NULL,NULL); Enable_Window_Stage(HIDE_ALL); MessageBox(_T("Operation success!"),_T("Information"),MB_OK); return; } else continue; } } } else { MessageBox(_T("Password is not the same!"),_T("Warning"),MB_OK); return; } } break; default: break; } }
/* gets the list of mechanisms */ int _sasl_load_plugins(const add_plugin_list_t *entrypoints, const sasl_callback_t *getpath_cb, const sasl_callback_t *verifyfile_cb) { int result; TCHAR cur_dir[PATH_MAX], full_name[PATH_MAX+2], prefix[PATH_MAX+2]; /* 1 for '\\' 1 for trailing '\0' */ TCHAR * pattern; TCHAR c; int pos; int retCode = SASL_OK; char *utf8path = NULL; TCHAR *path=NULL; int position; const add_plugin_list_t *cur_ep; struct _stat statbuf; /* filesystem entry information */ intptr_t fhandle; /* file handle for _findnext function */ struct _tfinddata_t finddata; /* data returned by _findnext() */ size_t prefix_len; /* for static plugins */ add_plugin_t *add_plugin; _sasl_plug_type type; _sasl_plug_rec *p; if (! entrypoints || ! getpath_cb || getpath_cb->id != SASL_CB_GETPATH || ! getpath_cb->proc || ! verifyfile_cb || verifyfile_cb->id != SASL_CB_VERIFYFILE || ! verifyfile_cb->proc) return SASL_BADPARAM; /* do all the static plugins first */ for (cur_ep = entrypoints; cur_ep->entryname; cur_ep++) { /* What type of plugin are we looking for? */ if (!strcmp(cur_ep->entryname, "sasl_server_plug_init")) { type = SERVER; add_plugin = (add_plugin_t *)sasl_server_add_plugin; } else if (!strcmp(cur_ep->entryname, "sasl_client_plug_init")) { type = CLIENT; add_plugin = (add_plugin_t *)sasl_client_add_plugin; } else if (!strcmp(cur_ep->entryname, "sasl_auxprop_plug_init")) { type = AUXPROP; add_plugin = (add_plugin_t *)sasl_auxprop_add_plugin; } else if (!strcmp(cur_ep->entryname, "sasl_canonuser_init")) { type = CANONUSER; add_plugin = (add_plugin_t *)sasl_canonuser_add_plugin; } else { /* What are we looking for then? */ return SASL_FAIL; } for (p = _sasl_static_plugins; p->type; p++) { if (type == p->type) result = add_plugin(p->name, p->plug); } } /* get the path to the plugins */ result = ((sasl_getpath_t *)(getpath_cb->proc))(getpath_cb->context, &utf8path); if (result != SASL_OK) return result; if (!utf8path) return SASL_FAIL; if (sizeof(TCHAR) == sizeof(char)) { path = (TCHAR*)utf8path; } else { path = _sasl_utf8_to_wchar(utf8path); if (!path) return SASL_FAIL; } if (_tcslen(path) >= PATH_MAX) { /* no you can't buffer overrun */ retCode = SASL_FAIL; goto cleanup; } position=0; do { pos=0; do { c=path[position]; position++; cur_dir[pos]=c; pos++; } while ((c!=PATHS_DELIMITER) && (c!=0)); cur_dir[pos-1]='\0'; /* : check to make sure that a valid directory name was passed in */ if (_tstat (cur_dir, &statbuf) < 0) { continue; } if ((statbuf.st_mode & S_IFDIR) == 0) { continue; } _tcscpy(prefix, cur_dir); prefix_len = _tcslen (prefix); /* : Don't append trailing \ unless required */ if (prefix[prefix_len-1] != '\\') { _tcscat(prefix,_T("\\")); prefix_len++; } pattern = prefix; /* : Check that we have enough space for "*.dll" */ if ((prefix_len + DLL_MASK_LEN) > (sizeof(prefix) / sizeof(TCHAR) - 1)) { _sasl_log(NULL, SASL_LOG_WARN, "plugin search mask is too big"); continue; } _tcscat (prefix + prefix_len, _T("*") DLL_SUFFIX); fhandle = _tfindfirst (pattern, &finddata); if (fhandle == -1) { /* no matching files */ continue; } /* : Truncate "*.dll" */ prefix[prefix_len] = '\0'; do { size_t length; void *library; char *c; char plugname[PATH_MAX]; int entries; length = _tcslen(finddata.name); if (length < 5) { /* At least <Ch>.dll */ continue; /* can not possibly be what we're looking for */ } /* : Check for overflow */ if (length + prefix_len >= PATH_MAX) continue; /* too big */ if (_tcscmp(finddata.name + (length - _tcslen(DLL_SUFFIX)), DLL_SUFFIX) != 0) { continue; } /* : Check that it is not a directory */ if ((finddata.attrib & _A_SUBDIR) == _A_SUBDIR) { continue; } /* : Construct full name from prefix and name */ _tcscpy (full_name, prefix); _tcscat (full_name, finddata.name); /* cut off .dll suffix -- this only need be approximate */ if (sizeof(TCHAR) != sizeof(char)) { if (WideCharToMultiByte(CP_UTF8, 0, finddata.name, -1, plugname, sizeof(plugname), NULL, NULL) == 0) { // in case of unicode use utf8 continue; } } else { _tcscpy((TCHAR*)plugname, finddata.name); // w/o unicode local enconding is fine } c = strchr(plugname, '.'); if (c != NULL) *c = '\0'; result = _tsasl_get_plugin (full_name, verifyfile_cb, &library); if (result != SASL_OK) { continue; } entries = 0; for (cur_ep = entrypoints; cur_ep->entryname; cur_ep++) { result = _sasl_plugin_load(plugname, library, cur_ep->entryname, cur_ep->add_plugin); if (result == SASL_OK) { ++entries; } /* If this fails, it's not the end of the world */ } if (entries == 0) { _sasl_remove_last_plugin(); } } while (_tfindnext (fhandle, &finddata) == 0); _findclose (fhandle); } while ((c!='=') && (c!=0)); cleanup: if (sizeof(TCHAR) != sizeof(char)) { sasl_FREE(path); /* It's always allocated in coversion to wchar */ } return retCode; }
LRESULT CBacnetProgram::Fresh_Program_Item(WPARAM wParam,LPARAM lParam) { int cmp_ret ;//compare if match it will 0; int Changed_Item = (int)wParam; int Changed_SubItem = (int)lParam; memcpy_s(&m_temp_program_data[Changed_Item],sizeof(Str_program_point),&m_Program_data.at(Changed_Item),sizeof(Str_program_point)); CString temp_task_info; CString New_CString = m_program_list.GetItemText(Changed_Item,Changed_SubItem); if(Changed_SubItem == PROGRAM_LABEL) { CString cs_temp = m_program_list.GetItemText(Changed_Item,Changed_SubItem); if(cs_temp.GetLength()>= STR_PROGRAM_LABEL_LENGTH) //长度不能大于结构体定义的长度; { MessageBox(_T("Length can not higher than 8"),_T("Warning"),MB_OK | MB_ICONINFORMATION); PostMessage(WM_REFRESH_BAC_PROGRAM_LIST,NULL,NULL); return 0; } cs_temp.MakeUpper(); if(Check_Label_Exsit(cs_temp)) { PostMessage(WM_REFRESH_BAC_PROGRAM_LIST,Changed_Item,REFRESH_ON_ITEM); return 0; } char cTemp1[255]; memset(cTemp1,0,255); WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL ); memcpy_s(m_Program_data.at(Changed_Item).label,STR_PROGRAM_LABEL_LENGTH,cTemp1,STR_PROGRAM_LABEL_LENGTH); } if(Changed_SubItem == PROGRAM_FULL_LABLE) { CString cs_temp = m_program_list.GetItemText(Changed_Item,Changed_SubItem); if(cs_temp.GetLength()>= STR_PROGRAM_DESCRIPTION_LENGTH) //长度不能大于结构体定义的长度; { MessageBox(_T("Length can not higher than 20"),_T("Warning"),MB_OK | MB_ICONINFORMATION); PostMessage(WM_REFRESH_BAC_PROGRAM_LIST,NULL,NULL); return 0; } if(Check_FullLabel_Exsit(cs_temp)) { PostMessage(WM_REFRESH_BAC_PROGRAM_LIST,Changed_Item,REFRESH_ON_ITEM); return 0; } char cTemp1[255]; memset(cTemp1,0,255); WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL ); memcpy_s(m_Program_data.at(Changed_Item).description,STR_PROGRAM_DESCRIPTION_LENGTH,cTemp1,STR_PROGRAM_DESCRIPTION_LENGTH); } if(Changed_SubItem == PROGRAM_STATUS) { CString cs_temp=m_program_list.GetItemText(Changed_Item,PROGRAM_STATUS); if(cs_temp.CompareNoCase(_T("OFF"))==0) { m_Program_data.at(Changed_Item).on_off=0; } else { m_Program_data.at(Changed_Item).on_off=1; } } if(Changed_SubItem == PROGRAM_AUTO_MANUAL) { CString cs_temp=m_program_list.GetItemText(Changed_Item,PROGRAM_AUTO_MANUAL); if(cs_temp.CompareNoCase(_T("Auto"))==0) { m_Program_data.at(Changed_Item).auto_manual=0; } else { m_Program_data.at(Changed_Item).auto_manual=1; } } cmp_ret = memcmp(&m_temp_program_data[Changed_Item],&m_Program_data.at(Changed_Item),sizeof(Str_program_point)); if(cmp_ret!=0) { m_program_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR); temp_task_info.Format(_T("Write Program List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString); Post_Write_Message(g_bac_instance,WRITEPROGRAM_T3000,Changed_Item,Changed_Item,sizeof(Str_program_point),m_pragram_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem); } return 0; }
void FontAtlas::conversionU16TOGB2312(const std::u16string& newChars, std::unordered_map<unsigned short, unsigned short>& newCharsMap) { size_t strLen = newChars.length(); auto gb2312StrSize = strLen * 2; auto gb2312Text = new (std::nothrow) char[gb2312StrSize]; memset(gb2312Text, 0, gb2312StrSize); switch (_fontFreeType->getEncoding()) { case FT_ENCODING_GB2312: { #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT WideCharToMultiByte(936, NULL, (LPCWCH)newChars.c_str(), strLen, (LPSTR)gb2312Text, gb2312StrSize, NULL, NULL); #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID conversionEncodingJNI((char*)newChars.c_str(), gb2312StrSize, "UTF-16LE", gb2312Text, "GB2312"); #else if (_iconv == nullptr) { _iconv = iconv_open("gb2312", "utf-16le"); } if (_iconv == (iconv_t)-1) { CCLOG("conversion from utf16 to gb2312 not available"); } else { char* pin = (char*)newChars.c_str(); char* pout = gb2312Text; size_t inLen = strLen * 2; size_t outLen = gb2312StrSize; iconv(_iconv, (char**)&pin, &inLen, &pout, &outLen); } #endif } break; default: CCLOG("Unsupported encoding:%d", _fontFreeType->getEncoding()); break; } unsigned short gb2312Code = 0; unsigned char* dst = (unsigned char*)&gb2312Code; unsigned short u16Code; for (size_t index = 0, gbIndex = 0; index < strLen; ++index) { u16Code = newChars[index]; if (u16Code < 256) { newCharsMap[u16Code] = u16Code; gbIndex += 1; } else { dst[0] = gb2312Text[gbIndex + 1]; dst[1] = gb2312Text[gbIndex]; newCharsMap[u16Code] = gb2312Code; gbIndex += 2; } } delete [] gb2312Text; }
int wmain(int argc, wchar_t **wcargv) { char** argv; #else int main(int argc, char** argv) { #endif int eargv_size; int eargc_base; /* How many arguments in the base of eargv. */ char* emulator; char *env; int i; int need_shell = 0; #ifdef __WIN32__ int len; /* Convert argv to utf8 */ argv = malloc((argc+1) * sizeof(char*)); for (i=0; i<argc; i++) { len = WideCharToMultiByte(CP_UTF8, 0, wcargv[i], -1, NULL, 0, NULL, NULL); argv[i] = malloc(len*sizeof(char)); WideCharToMultiByte(CP_UTF8, 0, wcargv[i], -1, argv[i], len, NULL, NULL); } argv[argc] = NULL; #endif env = get_env("DIALYZER_EMULATOR"); emulator = env ? env : get_default_emulator(argv[0]); if (strlen(emulator) >= MAXPATHLEN) error("Value of environment variable DIALYZER_EMULATOR is too large"); /* * Allocate the argv vector to be used for arguments to Erlang. * Arrange for starting to pushing information in the middle of * the array, to allow easy addition of commands in the beginning. */ eargv_size = argc*4+100; eargv_base = (char **) emalloc(eargv_size*sizeof(char*)); eargv = eargv_base; eargc = 0; push_words(emulator); eargc_base = eargc; eargv = eargv + eargv_size/2; eargc = 0; free_env_val(env); /* * Push initial arguments. */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--wx") == 0) { PUSH("-smp"); /* wx currently requires SMP enabled */ break; } } if (argc > 1 && strcmp(argv[1], "-smp") == 0) { PUSH("-smpauto"); argc--, argv++; } if (argc > 2 && strcmp(argv[1], "+S") == 0) { PUSH3("-smp", "+S", argv[2]); argc--, argv++; argc--, argv++; } if (argc > 2 && strcmp(argv[1], "+P") == 0) { PUSH2("+P", argv[2]); argc--, argv++; argc--, argv++; } else PUSH2("+P", "1000000"); if (argc > 2 && strcmp(argv[1], "+sbt") == 0) { PUSH2("+sbt", argv[2]); argc--, argv++; argc--, argv++; } PUSH("+B"); PUSH2("-boot", "start_clean"); PUSH3("-run", "dialyzer", "plain_cl"); PUSH("-extra"); /* * Push everything except --shell. */ while (argc > 1) { if (strcmp(argv[1], "--shell") == 0) { need_shell = 1; } else { PUSH(argv[1]); } argc--, argv++; } if (!need_shell) { UNSHIFT("-noinput"); } /* * Move up the commands for invoking the emulator and adjust eargv * accordingly. */ while (--eargc_base >= 0) { UNSHIFT(eargv_base[eargc_base]); } /* * Invoke Erlang with the collected options. */ PUSH(NULL); return run_erlang(eargv[0], eargv); }
static void test_GetTimeZoneInformation(void) { char std_name[32], dlt_name[32]; TIME_ZONE_INFORMATION tzinfo, tzinfo1; BOOL res; DWORD tz_id; SYSTEMTIME st, current, utc, local; FILETIME l_ft, s_ft; LONGLONG l_time, s_time; LONG diff; GetSystemTime(&st); s_time = system_time_to_minutes(&st); SetLastError(0xdeadbeef); res = SystemTimeToFileTime(&st, &s_ft); ok(res, "SystemTimeToFileTime error %u\n", GetLastError()); SetLastError(0xdeadbeef); res = FileTimeToLocalFileTime(&s_ft, &l_ft); ok(res, "FileTimeToLocalFileTime error %u\n", GetLastError()); SetLastError(0xdeadbeef); res = FileTimeToSystemTime(&l_ft, &local); ok(res, "FileTimeToSystemTime error %u\n", GetLastError()); l_time = system_time_to_minutes(&local); tz_id = GetTimeZoneInformation(&tzinfo); ok(tz_id != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n"); trace("tz_id %u (%s)\n", tz_id, tz_id == TIME_ZONE_ID_DAYLIGHT ? "TIME_ZONE_ID_DAYLIGHT" : (tz_id == TIME_ZONE_ID_STANDARD ? "TIME_ZONE_ID_STANDARD" : (tz_id == TIME_ZONE_ID_UNKNOWN ? "TIME_ZONE_ID_UNKNOWN" : "TIME_ZONE_ID_INVALID"))); WideCharToMultiByte(CP_ACP, 0, tzinfo.StandardName, -1, std_name, sizeof(std_name), NULL, NULL); WideCharToMultiByte(CP_ACP, 0, tzinfo.DaylightName, -1, dlt_name, sizeof(dlt_name), NULL, NULL); trace("bias %d, %s - %s\n", tzinfo.Bias, std_name, dlt_name); trace("standard (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n", tzinfo.StandardDate.wDay, tzinfo.StandardDate.wMonth, tzinfo.StandardDate.wYear, tzinfo.StandardDate.wDayOfWeek, tzinfo.StandardDate.wHour, tzinfo.StandardDate.wMinute, tzinfo.StandardDate.wSecond, tzinfo.StandardDate.wMilliseconds, tzinfo.StandardBias); trace("daylight (d/m/y): %u/%02u/%04u day of week %u %u:%02u:%02u.%03u bias %d\n", tzinfo.DaylightDate.wDay, tzinfo.DaylightDate.wMonth, tzinfo.DaylightDate.wYear, tzinfo.DaylightDate.wDayOfWeek, tzinfo.DaylightDate.wHour, tzinfo.DaylightDate.wMinute, tzinfo.DaylightDate.wSecond, tzinfo.DaylightDate.wMilliseconds, tzinfo.DaylightBias); diff = (LONG)(s_time - l_time); ok(diff == tzinfo.Bias + get_tz_bias(&tzinfo, tz_id), "system/local diff %d != tz bias %d\n", diff, tzinfo.Bias + get_tz_bias(&tzinfo, tz_id)); ok(SetEnvironmentVariableA("TZ","GMT0") != 0, "SetEnvironmentVariableA failed\n"); res = GetTimeZoneInformation(&tzinfo1); ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n"); ok(((tzinfo.Bias == tzinfo1.Bias) && (tzinfo.StandardBias == tzinfo1.StandardBias) && (tzinfo.DaylightBias == tzinfo1.DaylightBias)), "Bias influenced by TZ variable\n"); ok(SetEnvironmentVariableA("TZ",NULL) != 0, "SetEnvironmentVariableA failed\n"); if (!pSystemTimeToTzSpecificLocalTime) { win_skip("SystemTimeToTzSpecificLocalTime not available\n"); return; } diff = get_tz_bias(&tzinfo, tz_id); utc = st; SetLastError(0xdeadbeef); res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, ¤t); if (!res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("SystemTimeToTzSpecificLocalTime is not implemented\n"); return; } ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError()); s_time = system_time_to_minutes(¤t); tzinfo.StandardBias -= 123; tzinfo.DaylightBias += 456; res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local); ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError()); l_time = system_time_to_minutes(&local); ok(l_time - s_time == diff - get_tz_bias(&tzinfo, tz_id), "got %d, expected %d\n", (LONG)(l_time - s_time), diff - get_tz_bias(&tzinfo, tz_id)); /* pretend that there is no transition dates */ tzinfo.DaylightDate.wDay = 0; tzinfo.DaylightDate.wMonth = 0; tzinfo.DaylightDate.wYear = 0; tzinfo.StandardDate.wDay = 0; tzinfo.StandardDate.wMonth = 0; tzinfo.StandardDate.wYear = 0; res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local); ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError()); l_time = system_time_to_minutes(&local); ok(l_time - s_time == diff, "got %d, expected %d\n", (LONG)(l_time - s_time), diff); /* test 23:01, 31st of December date */ memset(&tzinfo, 0, sizeof(tzinfo)); tzinfo.StandardDate.wMonth = 10; tzinfo.StandardDate.wDay = 5; tzinfo.StandardDate.wHour = 2; tzinfo.StandardDate.wMinute = 0; tzinfo.DaylightDate.wMonth = 4; tzinfo.DaylightDate.wDay = 1; tzinfo.DaylightDate.wHour = 2; tzinfo.Bias = 0; tzinfo.StandardBias = 0; tzinfo.DaylightBias = -60; utc.wYear = 2012; utc.wMonth = 12; utc.wDay = 31; utc.wHour = 23; utc.wMinute = 1; res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local); ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError()); ok(local.wYear==2012 && local.wMonth==12 && local.wDay==31 && local.wHour==23 && local.wMinute==1, "got (%d-%d-%d %02d:%02d), expected (2012-12-31 23:01)\n", local.wYear, local.wMonth, local.wDay, local.wHour, local.wMinute); }
LRESULT CTStatOutputView::Fresh_Output_Item(WPARAM wParam,LPARAM lParam) { int cmp_ret ;//compare if match it will 0; int Changed_Item = (int)wParam; int Changed_SubItem = (int)lParam; CString strText; CString temp_task_info; CString New_CString = m_output_list.GetItemText(Changed_Item,Changed_SubItem); strText=New_CString; CString cstemp_value; int lRow=Changed_Item; int lCol=Changed_SubItem; if (New_CString.CompareNoCase(NO_APPLICATION)==0) { return 0 ; } BOOL IS_SEND=FALSE; _MessageWriteOneInfo_List *pwrite_info = new _MessageWriteOneInfo_List; pwrite_info->list_type=LIST_TYPE_OUTPUT_TSTAT; #if 0 if(lCol == TStat_OutputName) { if (New_CString.CompareNoCase(m_tstat_output_data.at(Changed_Item).OutputName.StrValue)==0) { return 0; } CBADO bado; bado.SetDBPath(g_strCurBuildingDatabasefilePath); bado.OnInitADOConn(); CString strSerial; strSerial.Format(_T("%d"),g_serialNum); CString strsql; strsql.Format(_T("select * from IONAME where SERIAL_ID = '%s'"),strSerial); bado.m_pRecordset=bado.OpenRecordset(strsql); //m_RsTmp->Open((_variant_t)strsql,_variant_t((IDispatch *)m_ConTmp,true),adOpenStatic,adLockOptimistic,adCmdText); if(VARIANT_FALSE==bado.m_pRecordset->EndOfFile)//update { CString strField; switch (lRow+1) { case 1: strField=_T("OUTPUT1"); break; case 2: strField=_T("OUTPUT2"); break; case 3: strField=_T("OUTPUT3"); break; case 4: strField=_T("OUTPUT4"); break; case 5: strField=_T("OUTPUT5"); break; case 6: strField=_T("OUTPUT6"); break; case 7: strField=_T("OUTPUT7"); break; } try { CString str_temp; str_temp.Format(_T("update IONAME set "+strField+" = '"+strText+"' where SERIAL_ID = '"+strSerial+"'")); //AfxMessageBox(str_temp ); bado.m_pConnection->Execute(str_temp.GetString(),NULL,adCmdText); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } // m_FlexGrid.put_TextMatrix(lRow,lCol,strText); } else//inerst { switch (lRow+1) { case 1: g_strOutName1=strText; break; case 2: g_strOutName2=strText; break; case 3: g_strOutName3=strText; break; case 4: g_strOutName4=strText; break; case 5: g_strOutName5=strText; break; case 6: g_strOutName6=strText; break; case 7: g_strOutName7=strText; break; } CString str_temp; str_temp.Format(_T("insert into IONAME values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"), strSerial, g_strInName1, g_strInName2, g_strInName3, g_strInName4, g_strInName5, g_strInName6, g_strInName7, g_strOutName1, g_strOutName2, g_strOutName3, g_strOutName4, g_strOutName5, g_strOutName6, g_strOutName7, g_strInName8, g_strInHumName, g_strSensorName ); try { bado.m_pConnection->Execute(str_temp.GetString(),NULL,adCmdText); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } // m_FlexGrid.put_TextMatrix(lRow,lCol,strText); } switch (lRow+1) { case 1: g_strOutName1=strText; break; case 2: g_strOutName2=strText; break; case 3: g_strOutName3=strText; break; case 4: g_strOutName4=strText; break; case 5: g_strOutName5=strText; break; case 6: g_strOutName6=strText; break; case 7: g_strOutName7=strText; break; } bado.CloseRecordset(); bado.CloseConn(); m_tstat_output_data.at(Changed_Item).OutputName.StrValue=New_CString; Fresh_One_Item(Changed_Item); } #endif if(lCol == TStat_OutputName) { if (Changed_Item > 7) { IS_SEND=FALSE; m_output_list.Set_Edit(false); return 0; } CString cs_temp = m_output_list.GetItemText(Changed_Item,Changed_SubItem); if(cs_temp.GetLength()> STR_IN_LABEL) //长度不能大于结构体定义的长度; { cs_temp.Delete(8,cs_temp.GetLength()-8); } if (m_tstat_output_data.at(Changed_Item).OutputName.StrValue.CompareNoCase(cs_temp)==0) { PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,NULL,NULL); return 0; } char cTemp1[8]; memset(cTemp1,0,8); WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 8, NULL, NULL ); _MessageWriteMultiInfo_List *pwrite_info = new _MessageWriteMultiInfo_List; pwrite_info->device_id=g_tstat_id; pwrite_info->Changed_Name.Format(_T("Change outputname%d from %s to %s"),Changed_Item,m_tstat_output_data.at(Changed_Item).OutputName.StrValue,cs_temp); pwrite_info->hwnd=g_hwnd_now; pwrite_info->mRow=Changed_Item; pwrite_info->mCol=Changed_SubItem; pwrite_info->Start_Address=m_tstat_output_data.at(Changed_Item).OutputName.regAddress; memcpy_s(pwrite_info->RegValue,STR_IN_LABEL-1,cTemp1,STR_IN_LABEL-1); m_output_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR); if(!PostThreadMessage(nThreadID,MY_WRITE_MULTI_LIST,(WPARAM)pwrite_info,NULL))//post thread msg { return FALSE; } else { return TRUE; } } if(lCol == TStat_AM){ if (product_type==CS3000) { if (m_tstat_output_data.at(0).Signal_Type.StrValue.CompareNoCase(New_CString)!=0) { IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).Value.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).Signal_Type.regAddress; if (New_CString.CompareNoCase(_T("Current"))==0) { pwrite_info->new_value=0; } else { pwrite_info->new_value=1; } } } } if(lCol == TStat_Unit){ if (product_type==CS3000) { if (m_tstat_output_data.at(0).Range.StrValue.CompareNoCase(New_CString)!=0) { IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).Range.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).Range.regAddress; pwrite_info->new_value=_wtoi(New_CString); } } } if (lCol == TStat_Value){ //if (m_tstat_output_data.at(lRow).Value.StrValue.CompareNoCase(New_CString)==0)//选的字符和内存的值相同的话,就返回 //{ // m_output_list.Set_Edit(false); // IS_SEND=FALSE; // return 0; //} int Output_Value=(int)(_wtof(New_CString)*10); if(Output_Value >1000) { SetPaneString(BAC_SHOW_MISSION_RESULTS,_T("Please input value between 0 - 100 ")); PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,NULL,NULL); return 0; } if (m_tstat_output_data.at(lRow).Value.RegValue==Output_Value) { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("Value,From %u to %s"),m_tstat_output_data.at(lRow).Function.RegValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).Value.regAddress; pwrite_info->new_value=Output_Value; } if (lCol == TStat_Range) { if (m_tstat_output_data.at(lRow).Range.StrValue.CompareNoCase(New_CString)==0)//选的字符和内存的值相同的话,就返回 { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } if (New_CString.CompareNoCase(_T("PWM(0-100%)"))==0)//是PWM { //检测当前的PWM状态的个数 int PWMNUMBER =0; for (int i=0;i<7;i++) { if (m_tstat_output_data.at(i).Range.StrValue.CompareNoCase(_T("PWM(0-100%)"))==0) { PWMNUMBER++; } } if (PWMNUMBER>=2) { AfxMessageBox(_T("PWM Mode should be less than two!")); m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } } int RangeValue=-1; if (product_register_value[7]==1||product_register_value[7]==2||product_register_value[7]==3) { if (Changed_Item<3) { for (int i=0;i<3;i++) { if (New_CString.CompareNoCase(OUTPUT_RANGE5[i])==0) { RangeValue=i; break; } } } else if (Changed_Item<5) { for (int i=0;i<18;i++) { if (New_CString.CompareNoCase(OUTPUT_ANRANGE[i])==0) { RangeValue=i; break; } } } } else { if (Changed_Item<5) { for (int i=0;i<6;i++) { if (New_CString.CompareNoCase(OUTPUT_RANGE45[i])==0) { RangeValue=i; break; } } } else if (Changed_Item<7) { for (int i=0;i<18;i++) { if (New_CString.CompareNoCase(OUTPUT_ANRANGE[i])==0) { RangeValue=i; break; } } } } if (RangeValue==-1) { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).Range.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).Range.regAddress; pwrite_info->new_value=RangeValue; } if (lCol == TStat_Funcation) { if (m_tstat_output_data.at(lRow).Function.StrValue.CompareNoCase(New_CString)==0)//选的字符和内存的值相同的话,就返回 { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } int RangeValue=-1; for (int i=0;i<5;i++) { if (New_CString.CompareNoCase(ONTPUT_FUNS[i])==0) { RangeValue=i; break; } } if (RangeValue==-1) { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).Function.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).Function.regAddress; pwrite_info->new_value=RangeValue; } if (lCol == TStat_Interlock) { if (m_tstat_output_data.at(lRow).Interlock.StrValue.CompareNoCase(New_CString)==0)//选的字符和内存的值相同的话,就返回 { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } int InterlockValue=-1; for (int i=0;i<6;i++) { if (New_CString.CompareNoCase(Interlock[i])==0) { InterlockValue=i; break; } } if (InterlockValue==-1) { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).Interlock.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).Interlock.regAddress; pwrite_info->new_value=InterlockValue; } if (lCol == TStat_OFFON_Delay) { int OFFON_Delay_Value = _wtoi(New_CString); if (m_tstat_output_data.at(lRow).OFFON_Delay.RegValue==OFFON_Delay_Value) { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).OFFON_Delay.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).OFFON_Delay.regAddress; pwrite_info->new_value=OFFON_Delay_Value; } if (lCol == TStat_ONOFF_Delay) { int ONOFF_Delay_Value = _wtoi(New_CString); if (m_tstat_output_data.at(lRow).ONOFF_Delay.RegValue==ONOFF_Delay_Value) { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).ONOFF_Delay.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).ONOFF_Delay.regAddress; pwrite_info->new_value=ONOFF_Delay_Value; } if (lCol == TStat_Signal_Type) { if (m_tstat_output_data.at(lRow).Signal_Type.StrValue.CompareNoCase(New_CString)==0)//选的字符和内存的值相同的话,就返回 { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } int RangeValue=-1; for (int i=0;i<18;i++) { if (New_CString.CompareNoCase(OUTPUT_ANRANGE[i])==0) { RangeValue=i; break; } } if (RangeValue==-1) { m_output_list.Set_Edit(false); IS_SEND=FALSE; return 0; } IS_SEND=TRUE; pwrite_info->Changed_Name.Format(_T("%s,From %s to %s"),m_tstat_output_data.at(lRow).OutputName.StrValue,m_tstat_output_data.at(lRow).Signal_Type.StrValue,New_CString); pwrite_info->address=m_tstat_output_data.at(lRow).Signal_Type.regAddress; pwrite_info->new_value=RangeValue; } if (IS_SEND) { pwrite_info->device_id=g_tstat_id; pwrite_info->hwnd=g_hwnd_now; pwrite_info->mCol=lCol; pwrite_info->mRow=lRow; m_output_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR); if(!PostThreadMessage(nThreadID,MY_WRITE_ONE_LIST,(WPARAM)pwrite_info,NULL))//post thread msg { return FALSE ; } else { return TRUE ; } } else{ if (pwrite_info) { delete pwrite_info; } } return 0; }
/*++ Function : wcstod There is a slight difference between the Windows version of wcstod and the BSD versio of wcstod. Under Windows the string " -1b " returns -1.000000 stop char = 'b' Under BSD the same string returns 0.000000 stop ' ' see msdn doc. --*/ double __cdecl PAL_wcstod( const wchar_16 * nptr, wchar_16 **endptr ) { double RetVal = 0.0; LPSTR lpStringRep = NULL; LPWSTR lpStartOfExpression = (LPWSTR)nptr; LPWSTR lpEndOfExpression = NULL; UINT Length = 0; ENTRY( "wcstod( %p (%S), %p (%S) )\n", nptr, nptr, endptr , endptr ); if ( !nptr ) { ERROR( "nptr is invalid.\n" ); LOGEXIT( "wcstod returning 0.0\n" ); return 0.0; } /* Eat white space. */ while ( PAL_iswspace( *lpStartOfExpression ) ) { lpStartOfExpression++; } /* Get the end of the expression. */ lpEndOfExpression = lpStartOfExpression; while ( *lpEndOfExpression ) { if ( !MISC_CRT_WCSTOD_IsValidCharacter( *lpEndOfExpression ) ) { break; } lpEndOfExpression++; } if ( lpEndOfExpression != lpStartOfExpression ) { Length = lpEndOfExpression - lpStartOfExpression; lpStringRep = (LPSTR)malloc( Length + 1); if ( lpStringRep ) { if ( WideCharToMultiByte( CP_ACP, 0, lpStartOfExpression, Length, lpStringRep, Length + 1 , NULL, 0 ) != 0 ) { LPSTR ScanStop = NULL; lpStringRep[Length]= 0; RetVal = strtod( lpStringRep, &ScanStop ); /* See if strtod failed. */ if ( RetVal == 0.0 && ScanStop == lpStringRep ) { ASSERT( "An error occured in the conversion.\n" ); lpEndOfExpression = (LPWSTR)nptr; } } else { ASSERT( "Wide char to multibyte conversion failed.\n" ); lpEndOfExpression = (LPWSTR)nptr; } } else { ERROR( "Not enough memory.\n" ); lpEndOfExpression = (LPWSTR)nptr; } } else { ERROR( "Malformed expression.\n" ); lpEndOfExpression = (LPWSTR)nptr; } /* Set the stop scan character. */ if ( endptr != NULL ) { *endptr = lpEndOfExpression; } free( lpStringRep ); LOGEXIT( "wcstod returning %f.\n", RetVal ); return RetVal; }
HRESULT RunScenario(__in CONFIGURATION_PARAMETERS* configParams) { //common declarations UINT status = ERROR_SUCCESS; HRESULT hr = S_OK; UINT pinLen = Pin_Length_8; //pin needs to be a null terminated ascii char[] for the IWCNDevice::SetPassword function char pin[Pin_Length_8 + 1] = {0}; int result = 0; //WCN declarations CComPtr<IWCNDevice> pDevice; CComObject<WcnConnectNotification>* pWcnConNotif = NULL; CComObject<CWcnFdDiscoveryNotify> * wcnFdDiscoveryNotify = NULL; //Wlan variable declarations WCHAR profileBuffer[WCN_API_MAX_BUFFER_SIZE] = {0}; HANDLE wlanHandle = 0; DWORD negVersion = 0; GUID interfaceGuid = {0}; WLAN_INTERFACE_INFO_LIST* pInterfaceList = 0; DWORD wlanResult = 0; WLAN_CONNECTION_PARAMETERS connParams; ZeroMemory(&connParams,sizeof(connParams)); WCN_DEVICE_INFO_PARAMETERS WCNDeviceInformation; PWSTR pWlanProfileXml = NULL; DWORD dwFlags = WLAN_PROFILE_GET_PLAINTEXT_KEY; //The following wlan profile xml is used to configure an unconfigured WCN enabled Router or device. //See http://msdn.microsoft.com/en-us/library/bb525370(VS.85).aspx on how to generate a wlan profile. //Alternatively, you can read an existing network profile by calling WlanGetProfile. WCHAR WCNConnectionProfileTemplate[] = L"<?xml version=\"1.0\" ?>" L"" L"<WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\">" L" <name>%s</name>" L"" L" <SSIDConfig>" L" <SSID>" L" <name>%s</name>" L" </SSID>" L" </SSIDConfig>" L" " L" <connectionType>ESS</connectionType>" L" <connectionMode>auto</connectionMode>" L"" L" <MSM>" L" <security>" L" <authEncryption>" L" <authentication>WPA2PSK</authentication>" L" <encryption>AES</encryption>" L" </authEncryption>" L"" L"" L" <sharedKey>" L" <keyType>passPhrase</keyType>" L" <protected>false</protected>" L" <keyMaterial>%s</keyMaterial>" L" </sharedKey>" L"" L" </security>" L" </MSM>" L"</WLANProfile>"; std::wstring profileXML; //open a wlan handle - this will be used later for saving the profile to the system status = WlanOpenHandle( WLAN_API_VERSION_2_0, NULL, &negVersion, &wlanHandle); if (status != ERROR_SUCCESS) { wprintf(L"\nERROR: WlanOpenHandle failed with the following error code [%d]", status); hr = S_FALSE; goto cleanup; } // Get the first wlan device // ideally you would want to be able to choose the wireless device you want to use status = WlanEnumInterfaces( wlanHandle, NULL, &pInterfaceList); if(status != ERROR_SUCCESS) { wprintf(L"\nERROR: WlanEnumInterfaces failed with the following error code [0x%d]",status); hr = S_FALSE; goto cleanup; } //Make sure there is at least one wlan interface on the system if (pInterfaceList == 0 || pInterfaceList->dwNumberOfItems == 0) { wprintf(L"\nERROR: No wireless network adapters on the system"); hr = S_FALSE; goto cleanup; } //get the wlan interface GUID interfaceGuid = pInterfaceList->InterfaceInfo[0].InterfaceGuid; //Create an instance of the IWCNConnectNotify Interface hr = CComObject<WcnConnectNotification>::CreateInstance(&pWcnConNotif); if (hr != S_OK) { wprintf(L"\nERROR: Creating an instance of WcnConnectNotification failed with the following error hr=[0x%x]", hr); goto cleanup; } pWcnConNotif->AddRef(); hr = CComObject<CWcnFdDiscoveryNotify>::CreateInstance(&wcnFdDiscoveryNotify); if (hr != S_OK) { wprintf(L"\nERROR: Creating an instance of CWcnFdDiscoveryNotify failed with the following error hr=[0x%x]", hr); goto cleanup; } wcnFdDiscoveryNotify->AddRef(); //initialize WcnConnectNotification hr = pWcnConNotif->Init(); if(hr !=S_OK) { wprintf(L"\nERROR: Creating a connection notification event failed with the following error hr=[0x%x]", hr); goto cleanup; } //initialize CWcnFdDiscoveryNotify hr = wcnFdDiscoveryNotify->Init(configParams->bTurnOnSoftAP); if(hr != S_OK) { wprintf(L"\nERROR: Initializing Function Discovery notify failed with the following error hr=[0x%x].",hr); goto cleanup; } //Search for WCN device with function discovery hr = wcnFdDiscoveryNotify->WcnFDSearchStart(&configParams->pDeviceUUID, configParams->pSearchSSID); if(hr != S_OK) { wprintf(L"\nERROR: Function Discovery search failed to start with the following error hr=[0x%x].",hr); goto cleanup; } //Wait for Function Discovery to complete wcnFdDiscoveryNotify->WaitForAnyDiscoveryEvent(Discovery_Event_Wait_Time_MS); //Attempt to get the IWCNDevice instance if(wcnFdDiscoveryNotify->GetWCNDeviceInstance(&pDevice)) { //get information about the device from the IWCNDevice instance wprintf(L"\nINFO: The following Device was found by Function Discovery."); hr = GetWCNDeviceInformation(pDevice, &WCNDeviceInformation); if (hr != S_OK) { wprintf(L"\nERROR: Failed to get the Device information from the IWCNDevice Instance, hr=[0x%x]", hr); goto cleanup; } } else { wprintf(L"\nERROR: Device was NOT found by Function Discovery."); hr = S_FALSE; goto cleanup; } //The following segment generates a WLAN profile from the template above then saves it to the //WLAN store. It the retrieves the profile from the WLAN store for use in configuring a router //or device. if (configParams->enumConfigScenario != PCConfigPin && configParams->enumConfigScenario != PCConfigPushButton) { //add the profiles ssid and passphrase to the wlan profile template swprintf_s( profileBuffer, WCNConnectionProfileTemplate, configParams->pProfileSSID, configParams->pProfileSSID, configParams->pProfilePassphrase); //Add the created profile to the wlan store status = WlanSetProfile( wlanHandle, &interfaceGuid, 0, //all-user profile profileBuffer, NULL, // Default Security - All user profile TRUE, // Overwrite profile NULL, // reserved &wlanResult); if (status != ERROR_SUCCESS) { wprintf(L"\nERROR: Failed to save the profile return code was [0x%x]", wlanResult); hr = S_FALSE; goto cleanup; } else { wprintf(L"\nINFO: Successfully saved the profile to the wlan store"); } //Here is where the profile is retrieved from the wlan store to be used in the configuration //of the device. //If so desired a list of available profiles could be presented to the user so that //they could decied which profile will be used to configure the device //The wlan profile must be retrieved in plain text inorder for the IWCNDEVICE::SetNetWorkProfile // method to succeede. In order to do this you need to be elevated to get the wlan profile // in plain text. status = WlanGetProfile( wlanHandle, &interfaceGuid, configParams->pProfileSSID, NULL, //reserved &pWlanProfileXml, &dwFlags, // Flags - get profile in plain text NULL); // GrantedAccess - none if (status != ERROR_SUCCESS) { wprintf(L"\nERROR: WlanGetprofile Failed to get profile [%s] with error code [0x%x]", configParams->pProfileSSID, status); hr = S_FALSE; goto cleanup; } else { wprintf(L"\nINFO: Successfully retrieved profile [%s] from the wlan store.", configParams->pProfileSSID); } //check to make sure the profile from the wlan store is not a Group Policy profile if (WLAN_PROFILE_GROUP_POLICY & dwFlags) { wprintf(L"\nERROR: Profile [%s] is a group policy WLAN profile which is not supported by WCN", configParams->pProfileSSID); hr = S_FALSE; goto cleanup; } //The IWCNDevice::SetNetworkProfile method queues an XML WLAN profile to be //provisioned to the device. This method may only be called prior to IWCNDevice::Connect. hr = pDevice->SetNetworkProfile(pWlanProfileXml); if(hr != S_OK) { wprintf(L"\nERROR: IWCNDevice::SetNetworkProfile failed with error code [0x%x]", hr); goto cleanup; } else { wprintf(L"\nINFO: IWCNDevice::SetNetworkProfile() succeeded with result [0x%x]", hr); } } switch (configParams->enumConfigScenario) { case DeviceConfigPushButton: pinLen = 0; break; case DeviceConfigPin: case RouterConfig: if (configParams->pDevicePin == 0) { wprintf(L"\nERROR: Pin must not be 0 when doing a pin configuration"); hr = S_FALSE; goto cleanup; } result = WideCharToMultiByte( CP_UTF8, 0, configParams->pDevicePin, -1, (LPSTR)pin, sizeof(pin), NULL, NULL); if (result == 0 ) { wprintf(L"\nERROR: Failed to convert the pin to multibyte."); goto cleanup; } pinLen = sizeof(pin) - 1 ; break; case PCConfigPushButton: //check to make sure the device supports push button before doing the push button configuration if (WCNDeviceInformation.uConfigMethods & WCN_VALUE_CM_PUSHBUTTON) { //set the pin length to 0 this is necessary for a Push button configuration scenario pinLen = 0; } else { wprintf(L"ERROR: The [%s] device does not support the Push Button Method", WCNDeviceInformation.wszDeviceName); hr = S_FALSE; goto cleanup; } break; case PCConfigPin: //check to make sure the device supports pin before doing the pin configuration if ((WCNDeviceInformation.uConfigMethods & WCN_VALUE_CM_LABEL)|| (WCNDeviceInformation.uConfigMethods & WCN_VALUE_CM_DISPLAY)) { if (configParams->pDevicePin == 0) { wprintf(L"\nERROR: Pin must not be 0 when doing a pin configuration"); hr = S_FALSE; goto cleanup; } result = WideCharToMultiByte( CP_UTF8, //CodePage 0, //Unmapped character flags configParams->pDevicePin, -1, //null terminated string (LPSTR)pin, sizeof(pin), NULL, //lpDefaultChar - use system default value NULL); //lpUsedDefaultChar ignored if (result == 0 ) { wprintf(L"\nERROR: Failed to convert the pin to multibyte."); goto cleanup; } pinLen = sizeof(pin) - 1 ; } else { wprintf(L"\nERROR: The [%s] device does not supprot the pin method", WCNDeviceInformation.wszDeviceName); hr = S_FALSE; goto cleanup; } break; default: break; } //The IWCNDevice::SetPassword method configures the authentication method value, and if required, //a password used for the pending session. This method may only be called prior to IWCNDevice::Connect. hr = pDevice->SetPassword( configParams->enumConfigType, pinLen, (BYTE*)pin); if(hr != S_OK) { wprintf(L"\nERROR: IWCNDevice::SetPassword failed with error code [0x%x]", hr); goto cleanup; } else { wprintf(L"\nINFO: IWCNDevice::SetPassword succeeded with result [0x%x]", hr); } //The IWCNDevice::Connect method initiates the session. hr = pDevice->Connect(pWcnConNotif); if(hr != S_OK) { //Device Push button configuration is only supported on SoftAP capable wireless Nics if (hr == HRESULT_FROM_WIN32(ERROR_CONNECTION_UNAVAIL) && configParams->enumConfigScenario == DeviceConfigPushButton) { wprintf(L"\nERROR: PushButton Configuration of non AP devices is only supported on"); wprintf(L"\n SoftAP capable wireless network cards."); } else { wprintf(L"\nERROR: IWCNDevice::Connect failed with error code [0x%x]", hr); } goto cleanup; } else { wprintf(L"\nINFO: IWCNDevice::Connect succeeded with result [0x%x]", hr); } //wait for the configuration result hr = pWcnConNotif->WaitForConnectionResult(); if (hr != S_OK) { wprintf(L"ERROR: WaitforconnectionResult returned the following error [ox%x]", hr); goto cleanup; } //check to see which connection callbacks were called if(pWcnConNotif->connectSucceededCallBackInvoked) { wprintf(L"\nINFO: IWCNConnectNotify::ConnectSucceeded was invoked"); } else if(pWcnConNotif->connectFailedCallBackInvoked) { wprintf(L"\nERROR: IWCNConnectNotify::ConnectFailed was invoked"); hr = S_FALSE; goto cleanup; } //save the profile from the IWCNDevice instance to the WLAN store if doing a PCConfigPushButton //or a PCConfigPin scenario // this is the profile that was received from the router if (configParams->enumConfigScenario == PCConfigPushButton || configParams->enumConfigScenario == PCConfigPin) { //The IWCNDevice::GetNetworkProfile method gets a network profile from the device. hr = pDevice->GetNetworkProfile(ARRAYSIZE(profileBuffer), profileBuffer); if(hr != S_OK) { wprintf(L"\nERROR: IWCNDevice::GetNetworkProfile failed with [0x%x]", hr); goto cleanup; } //save the profile to the system if doing a RouterConfig or a pushbutton scenario //The SoftapConfig and DeviceConfig scenarios will generally use a profile that is already on the system //save the profile to the wlan interface status = WlanSetProfile( wlanHandle, &interfaceGuid, 0, //Flags - none profileBuffer, NULL, // Default Security - All user profile TRUE, // Overwrite profile NULL, // reserved &wlanResult); if (status != ERROR_SUCCESS) { wprintf(L"\nERROR: Failed to save the profile to the WLAN store, return code was [0x%x]", wlanResult); hr = S_FALSE; } else { wprintf(L"\nINFO: Successfully saved the profile to the WLAN store"); } } //Display the SSID and passphrase used to configure the Router or device if (configParams->enumConfigScenario != PCConfigPin && configParams->enumConfigScenario != PCConfigPushButton) { wprintf(L"\nINFO: Profile SSID Used: [%s]", configParams->pProfileSSID); wprintf(L"\nINFO: Profile Passphrase Used: [%s]", configParams->pProfilePassphrase); } cleanup: if(pWcnConNotif) { pWcnConNotif->Release(); pWcnConNotif = 0; } if(wcnFdDiscoveryNotify) { wcnFdDiscoveryNotify->Release(); wcnFdDiscoveryNotify = 0; } if (wlanHandle != NULL) { WlanCloseHandle(wlanHandle,NULL); } if (pInterfaceList != NULL) { WlanFreeMemory(pInterfaceList); } return hr; }
LRESULT BacnetController::Fresh_Controller_Item(WPARAM wParam,LPARAM lParam) { int cmp_ret ;//compare if match it will 0; int Changed_Item = (int)wParam; int Changed_SubItem = (int)lParam; if(Changed_Item>= PID_CONTROLLER_LIMITE_ITEM_COUNT) { m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); return 0; } CString temp_task_info; CString New_CString = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); CString cstemp_value; //先保存 原来的值,等结束的时候来比对,看是否有改变,有改变就进行写动作; memcpy_s(&m_temp_controller_data[Changed_Item],sizeof(Str_controller_point),&m_controller_data.at(Changed_Item),sizeof(Str_controller_point)); if(Changed_SubItem == CONTROLLER_INPUT) { if(bacnet_device_type == STM32_HUM_NET) //小叶的设备不支持修改 { return 0; } CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); if(cs_temp.IsEmpty() == false) { cs_temp.MakeUpper(); char cTemp1[255]; char temp_input[250]; char * tempcs=NULL; memset(cTemp1,0,255); WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL ); //Search the input label from the list. int temp_number=-1; byte temp_value_type = -1; byte temp_point_type=-1; int temp_panel = -1; int temp_net = -1; int k=0; //int temp1; tempcs = ispoint(cTemp1,&temp_number,&temp_value_type,&temp_point_type,&temp_panel,&temp_net,0,Station_NUM,&k); if(tempcs!=NULL) { strcpy(temp_input,tempcs); CString temp_des2; temp_des2.Empty(); MultiByteToWideChar( CP_ACP, 0, temp_input, (int)strlen(temp_input)+1, temp_des2.GetBuffer(MAX_PATH), MAX_PATH ); temp_des2.ReleaseBuffer(); m_controller_list.SetItemText(Changed_Item,CONTROLLER_INPUT,temp_des2); if(temp_panel != Station_NUM) { MessageBox(_T("Don't support other panel currently!"),_T("Warning"),MB_OK | MB_ICONINFORMATION); m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); return 0; } if(temp_number > 0); //因为Input2 的number 是1; temp_number = temp_number - 1; temp_point_type = temp_point_type + 1; if(2 == temp_point_type) { m_controller_data.at(Changed_Item).input.number = temp_number; m_controller_data.at(Changed_Item).input.panel = temp_panel;//bac_gloab_panel; m_controller_data.at(Changed_Item).input.point_type = temp_point_type;//1 means input point CString temp_des3; if(temp_number < BAC_INPUT_ITEM_COUNT) { //temp_des3.Format(_T("%d"),m_Input_data.at(temp_number - 1).value); CString cstemp_value; float temp_float_value; temp_float_value = ((float)m_Input_data.at(temp_number).value) / 1000; temp_des3.Format(_T("%.1f"),temp_float_value); m_controller_data.at(Changed_Item).input_value = m_Input_data.at(temp_number).value; m_controller_list.SetItemText(Changed_Item,CONTROLLER_INPUTVALUE,temp_des3); } } else if(3 == temp_point_type) { m_controller_data.at(Changed_Item).input.number = temp_number; m_controller_data.at(Changed_Item).input.panel = temp_panel;//bac_gloab_panel; m_controller_data.at(Changed_Item).input.point_type = temp_point_type;//1 means input point CString temp_des3; if(temp_number < BAC_VARIABLE_ITEM_COUNT) { //temp_des3.Format(_T("%d"),m_Input_data.at(temp_number - 1).value); CString cstemp_value; float temp_float_value; temp_float_value = ((float)m_Variable_data.at(temp_number).value) / 1000; temp_des3.Format(_T("%.1f"),temp_float_value); m_controller_data.at(Changed_Item).input_value = m_Variable_data.at(temp_number).value; m_controller_list.SetItemText(Changed_Item,CONTROLLER_INPUTVALUE,temp_des3); } } else { m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); return 0; } } else { CString temp_message; temp_message.Format(_T("%s character not allowed in labels!"),cs_temp.GetString()); MessageBox(temp_message,_T("Information"),MB_OK |MB_ICONINFORMATION); m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); return 0; } } } if(Changed_SubItem == CONTROLLER_INPUTVALUE) { if(bacnet_device_type == STM32_HUM_NET) //STM32_HUM_NET的设备不支持修改 { return 0; } //int temp_value = _wtoi(New_CString); int temp_value = (int)(_wtof(New_CString) * 1000); if(m_controller_data.at(Changed_Item).input.number == 0 ) return 0; if((m_controller_data.at(Changed_Item).input.number -1 )< BAC_INPUT_ITEM_COUNT) m_Input_data.at(m_controller_data.at(Changed_Item).input.number - 1).value = temp_value; temp_task_info.Format(_T("Write Controllers List Item%d .Changed the input value to \"%s\" "),Changed_Item + 1,New_CString); Post_Write_Message(g_bac_instance,WRITEINPUT_T3000,Changed_Item,Changed_Item,sizeof(Str_in_point),BacNet_hwd ,temp_task_info); return 0; } if(Changed_SubItem == CONTROLLER_SETVALUE) { if(bacnet_device_type == STM32_HUM_NET) //STM32_HUM_NET的设备不支持修改 { int temp_proportional=0; CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); m_controller_data.at(Changed_Item).setpoint_value = _wtoi(cs_temp)* 1000; } else { int temp_value = (int)(_wtof(New_CString) * 1000); if(m_controller_data.at(Changed_Item).setpoint.number == 0 ) return 0; if((m_controller_data.at(Changed_Item).setpoint.number -1 )< BAC_VARIABLE_ITEM_COUNT) m_Variable_data.at(m_controller_data.at(Changed_Item).setpoint.number - 1).value = temp_value; temp_task_info.Format(_T("Write Controllers List Item%d .Changed the variable value to \"%s\" "),Changed_Item + 1,New_CString); Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,Changed_Item,Changed_Item,sizeof(Str_in_point),BacNet_hwd ,temp_task_info); return 0; } } if(Changed_SubItem == CONTROLLER_AUTO_MANUAL) { CString temp_cs = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); if(temp_cs.CompareNoCase(_T("Auto"))==0) { m_controller_list.SetCellEnabled(Changed_Item,CONTROLLER_OUTPUT,0); m_controller_data.at(Changed_Item).auto_manual = BAC_AUTO ; } else { m_controller_list.SetCellEnabled(Changed_Item,CONTROLLER_OUTPUT,1); m_controller_data.at(Changed_Item).auto_manual = BAC_MANUAL ; } } if(Changed_SubItem == CONTROLLER_OUTPUT) { CString temp_cs = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); int temp_int = (int)(_wtof(temp_cs) * 1000); m_controller_data.at(Changed_Item).value = temp_int; } if(Changed_SubItem == CONTROLLER_SETPOINT) { CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); char cTemp1[255]; char temp_setpoint[250]; char * tempcs=NULL; memset(cTemp1,0,255); memset(temp_setpoint,0,250); WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL ); int temp_number=-1; byte temp_value_type = -1; byte temp_point_type=-1; int temp_panel = -1; int temp_net = -1; int k=0; //int temp1; //Change the lable.ex: Change the tempcs = ispoint(cTemp1,&temp_number,&temp_value_type,&temp_point_type,&temp_panel,&temp_net,0,bac_gloab_panel,&k); if(tempcs!=NULL) { memcpy_s(temp_setpoint,250,tempcs,9); //strcpy_s(temp_setpoint,tempcs); //strcpy(temp_setpoint,tempcs); CString temp_des2; temp_des2.Empty(); MultiByteToWideChar( CP_ACP, 0, temp_setpoint, STR_VARIABLE_LABEL+1, temp_des2.GetBuffer(MAX_PATH), MAX_PATH ); temp_des2.ReleaseBuffer(); m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETPOINT,temp_des2); if(temp_panel != bac_gloab_panel) { MessageBox(_T("Don't support other panel currently!"),_T("Warning"),MB_OK | MB_ICONINFORMATION); m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); return 0; } if(temp_number > 0) //Setpoint 也是这样;从0 开始的; temp_number = temp_number - 1; temp_point_type = temp_point_type + 1; //OUTPUT=1, INPUT, VARIABLE 要错位; m_controller_data.at(Changed_Item).setpoint.number = temp_number; m_controller_data.at(Changed_Item).setpoint.panel = temp_panel;//bac_gloab_panel; m_controller_data.at(Changed_Item).setpoint.point_type = temp_point_type;//1 means input point CString temp_des3; if(temp_number < BAC_VARIABLE_ITEM_COUNT) { if(m_Variable_data.at(temp_number).range < VARIABLE_ANALOG_UNITE_COUNT) temp_des3 = Variable_Analog_Units_Array[m_Variable_data.at(temp_number).range]; m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETPOINTUNITS,temp_des3); } char tempAAAA[250]; memset(tempAAAA,0,250); temp_des3.Empty(); if(m_Variable_data.at(temp_number).range == 20 ) { if((m_controller_data.at(Changed_Item).setpoint_value>=0)&&(m_controller_data.at(Changed_Item).setpoint_value<86400)) intervaltotext( tempAAAA, m_controller_data.at(Changed_Item).setpoint_value ,0 , 0); MultiByteToWideChar( CP_ACP, 0, tempAAAA, strlen(tempAAAA) + 1, temp_des3.GetBuffer(MAX_PATH), MAX_PATH ); temp_des3.ReleaseBuffer(); } else { CString cstemp_value; float temp_float_value; temp_float_value = ((float)m_Variable_data.at(m_controller_data.at(Changed_Item).setpoint.number).value) / 1000; temp_des3.Format(_T("%.1f"),temp_float_value); } m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETVALUE,temp_des3); } else { CString temp_show_ret; temp_show_ret = _T("\"") + cs_temp + _T("\"") + _T(" is a invalid label or keyword ."); SetPaneString(BAC_SHOW_MISSION_RESULTS,temp_show_ret); m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETPOINT,_T("")); } } if(Changed_SubItem == CONTROLLER_PROPORTIONAL) { int temp_proportional=0; CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); if((cs_temp.GetLength()>3) || (_wtoi(cs_temp)>255) ) { MessageBox(_T("Please input a effective value"),_T("Information"),MB_OK |MB_ICONINFORMATION); m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); } else { m_controller_data.at(Changed_Item).proportional = _wtoi(cs_temp); } } if(Changed_SubItem == CONTROLLER_RESET) { int temp_reset=0; CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); if((cs_temp.GetLength()>3) || (_wtoi(cs_temp)>255) ) { MessageBox(_T("Please input a effective value"),_T("Information"),MB_OK |MB_ICONINFORMATION); m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); } else { m_controller_data.at(Changed_Item).reset = _wtoi(cs_temp); } } if(Changed_SubItem == CONTROLLER_RATE) { int temp_rate=0; CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); int i_value = (int)(_wtof(cs_temp) * 100) ; if((i_value > 200) || (i_value < 0)) //if((cs_temp.GetLength()>1) || (_wtoi(cs_temp)>2) ) { MessageBox(_T("Please input a effective value 0.00 - 2.00"),_T("Information"),MB_OK |MB_ICONINFORMATION); m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); } else { m_controller_data.at(Changed_Item).rate = i_value; } } if(Changed_SubItem == CONTROLLER_BIAS) { int temp_bias=0; CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem); if((cs_temp.GetLength()>3) || (_wtoi(cs_temp)>100) ) { MessageBox(_T("Please input a effective value"),_T("Information"),MB_OK |MB_ICONINFORMATION); m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T("")); } else { m_controller_data.at(Changed_Item).bias = _wtoi(cs_temp); } } cmp_ret = memcmp(&m_temp_controller_data[Changed_Item],&m_controller_data.at(Changed_Item),sizeof(Str_controller_point)); if(cmp_ret!=0) { m_controller_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR); temp_task_info.Format(_T("Write Controllers List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString); Post_Write_Message(g_bac_instance,WRITEPID_T3000,Changed_Item,Changed_Item,sizeof(Str_controller_point),m_controller_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem); } return 0; }
/*********************************************************************** * UnicodeToAnsi (KERNEL.434) */ INT16 WINAPI UnicodeToAnsi16( LPCWSTR src, LPSTR dst, INT16 codepage ) { if ( codepage == -1 ) codepage = CP_ACP; return WideCharToMultiByte( codepage, 0, src, -1, dst, 0x7fffffff, NULL, NULL ); }
NTSTATUS RealUnicodeToFalseUnicode( IN OUT LPWSTR Source, IN int SourceLength, // in chars IN UINT Codepage ) /* this routine converts a unicode string into the correct characters for an OEM (cp 437) font. this code is needed because the gdi glyph mapper converts unicode to ansi using codepage 1252 to index font. this is how the data is stored internally. */ { NTSTATUS Status; LPSTR Temp; ULONG TempLength; ULONG Length; CHAR StackBuffer[STACK_BUFFER_SIZE]; BOOL NormalChars; int i; DBGCHARS(("RealUnicodeToFalseUnicode U->%d:ACP->U %.*ls\n", Codepage, SourceLength > 10 ? 10 : SourceLength, Source)); NormalChars = TRUE; for (i=0;i<SourceLength;i++) { if (Source[i] > 0x7f) { NormalChars = FALSE; break; } } if (NormalChars) { return STATUS_SUCCESS; } TempLength = SourceLength; if (TempLength > STACK_BUFFER_SIZE) { Temp = (LPSTR)HeapAlloc(pConHeap,MAKE_TAG( TMP_TAG ),TempLength); if (Temp == NULL) { return STATUS_NO_MEMORY; } } else { Temp = StackBuffer; } if (Codepage == OEMCP) { Status = RtlUnicodeToOemN(Temp, TempLength, &Length, Source, SourceLength * sizeof(WCHAR) ); } else { Status = WideCharToMultiByte(Codepage, 0, Source, SourceLength, Temp, TempLength, NULL, NULL); } if (!NT_SUCCESS(Status)) { if (TempLength > STACK_BUFFER_SIZE) { HeapFree(pConHeap,0,Temp); } return Status; } Status = RtlMultiByteToUnicodeN(Source, SourceLength * sizeof(WCHAR), &Length, Temp, TempLength ); if (TempLength > STACK_BUFFER_SIZE) { HeapFree(pConHeap,0,Temp); } if (!NT_SUCCESS(Status)) { return Status; } else { return STATUS_SUCCESS; } }
int ConvertOutputToOem( IN UINT Codepage, IN LPWSTR Source, IN int SourceLength, // in chars OUT LPSTR Target, IN int TargetLength // in chars ) /* Converts SourceLength Unicode characters from Source into not more than TargetLength Codepage characters at Target. Returns the number characters put in Target. (0 if failure) */ { if (Codepage == OEMCP) { NTSTATUS Status; ULONG Length; // Can do this in place Status = RtlUnicodeToOemN(Target, TargetLength, &Length, Source, SourceLength * sizeof(WCHAR) ); if (NT_SUCCESS(Status)) { return Length; } else { return 0; } } else { ASSERT (Source != (LPWSTR)Target); #ifdef SOURCE_EQ_TARGET LPSTR pszDestTmp; CHAR StackBuffer[STACK_BUFFER_SIZE]; DBGCHARS(("ConvertOutputToOem U->%d %.*ls\n", Codepage, SourceLength > 10 ? 10 : SourceLength, Source)); if (TargetLength > STACK_BUFFER_SIZE) { pszDestTmp = (LPSTR)HeapAlloc(pConHeap,MAKE_TAG( TMP_TAG ),TargetLength); if (pszDestTmp == NULL) { return 0; } } else { pszDestTmp = StackBuffer; } TargetLength = WideCharToMultiByte(Codepage, 0, Source, SourceLength, pszDestTmp, TargetLength, NULL, NULL); RtlCopyMemory(Target, pszDestTmp, TargetLength); if (pszDestTmp != StackBuffer) { HeapFree(pConHeap,0,pszDestTmp); } return TargetLength; #else DBGCHARS(("ConvertOutputToOem U->%d %.*ls\n", Codepage, SourceLength > 10 ? 10 : SourceLength, Source)); return WideCharToMultiByte(Codepage, 0, Source, SourceLength, Target, TargetLength, NULL, NULL); #endif } }
/*++ Function: SetCurrentDirectoryW See MSDN doc. --*/ BOOL PALAPI SetCurrentDirectoryW( IN LPCWSTR lpPathName) { BOOL bRet; DWORD dwLastError = 0; PathCharString dirPathString; int size; size_t length; char * dir; PERF_ENTRY(SetCurrentDirectoryW); ENTRY("SetCurrentDirectoryW(lpPathName=%p (%S))\n", lpPathName?lpPathName:W16_NULLSTRING, lpPathName?lpPathName:W16_NULLSTRING); /*check if the given path is null. If so return FALSE*/ if (lpPathName == NULL ) { ERROR("Invalid path/directory name\n"); dwLastError = ERROR_INVALID_NAME; bRet = FALSE; goto done; } length = (PAL_wcslen(lpPathName)+1) * 3; dir = dirPathString.OpenStringBuffer(length); if (NULL == dir) { dwLastError = ERROR_NOT_ENOUGH_MEMORY; bRet = FALSE; goto done; } size = WideCharToMultiByte( CP_ACP, 0, lpPathName, -1, dir, length, NULL, NULL ); dirPathString.CloseBuffer(size); if( size == 0 ) { dwLastError = GetLastError(); if( dwLastError == ERROR_INSUFFICIENT_BUFFER ) { WARN("lpPathName is larger than MAX_LONGPATH (%d)!\n", MAX_LONGPATH); dwLastError = ERROR_FILENAME_EXCED_RANGE; } else { ASSERT("WideCharToMultiByte failure! error is %d\n", dwLastError); dwLastError = ERROR_INTERNAL_ERROR; } bRet = FALSE; goto done; } bRet = SetCurrentDirectoryA(dir); done: if( dwLastError ) { SetLastError(dwLastError); } LOGEXIT("SetCurrentDirectoryW returns BOOL %d\n", bRet); PERF_EXIT(SetCurrentDirectoryW); return bRet; }
int ConsoleReadCh() { const int max_input = 8; static char console_input[8]; static int first_input_char = 0; static int last_input_char = 0; INPUT_RECORD rec; DWORD recRead; HANDLE h; if (first_input_char != last_input_char) { int c = console_input[first_input_char]; first_input_char++; first_input_char %= max_input; return c; } h = GetStdHandle(STD_INPUT_HANDLE); if (h == NULL) return NUL; ReadConsoleInputW(h, &rec, 1, &recRead); /* FIXME: We should handle rec.Event.KeyEvent.wRepeatCount > 1, too. */ if (recRead == 1 && rec.EventType == KEY_EVENT && rec.Event.KeyEvent.bKeyDown && (rec.Event.KeyEvent.wVirtualKeyCode < VK_SHIFT || rec.Event.KeyEvent.wVirtualKeyCode > VK_MENU)) { if (rec.Event.KeyEvent.uChar.UnicodeChar) { if ((rec.Event.KeyEvent.dwControlKeyState == SHIFT_PRESSED) && (rec.Event.KeyEvent.wVirtualKeyCode == VK_TAB)) { return 034; /* remap Shift-Tab */ } else { int i, count; char mbchar[8]; count = WideCharToMultiByte(WinGetCodepage(encoding), 0, &rec.Event.KeyEvent.uChar.UnicodeChar, 1, mbchar, sizeof(mbchar), NULL, NULL); for (i = 1; i < count; i++) { console_input[last_input_char] = mbchar[i]; last_input_char++; last_input_char %= max_input; } return mbchar[0]; } } else { switch (rec.Event.KeyEvent.wVirtualKeyCode) { case VK_UP: return 020; case VK_DOWN: return 016; case VK_LEFT: return 002; case VK_RIGHT: return 006; case VK_HOME: return 001; case VK_END: return 005; case VK_DELETE: return 0117; } } } /* Error reading event or, key up or, one of the following event records: MOUSE_EVENT_RECORD, WINDOW_BUFFER_SIZE_RECORD, MENU_EVENT_RECORD, FOCUS_EVENT_RECORD */ return NUL; }
/************************************************************************** * ISF_Desktop_fnGetDisplayNameOf * * NOTES * special case: pidl = null gives desktop-name back */ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet) { IGenericSFImpl *This = (IGenericSFImpl *)iface; HRESULT hr = S_OK; LPWSTR pszPath; TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet); pdump (pidl); if (!strRet) return E_INVALIDARG; pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR)); if (!pszPath) return E_OUTOFMEMORY; if (_ILIsDesktop (pidl)) { if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)) wcscpy(pszPath, This->sPathTarget); else HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH); } else if (_ILIsPidlSimple (pidl)) { GUID const *clsid; if ((clsid = _ILGetGUIDPointer (pidl))) { if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING) { int bWantsForParsing; /* * We can only get a filesystem path from a shellfolder if the * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists. * * Exception: The MyComputer folder doesn't have this key, * but any other filesystem backed folder it needs it. */ if (IsEqualIID (clsid, &CLSID_MyComputer)) { bWantsForParsing = TRUE; } else { /* get the "WantsFORPARSING" flag from the registry */ static const WCHAR clsidW[] = { 'C','L','S','I','D','\\',0 }; static const WCHAR shellfolderW[] = { '\\','s','h','e','l','l','f','o','l','d','e','r',0 }; static const WCHAR wantsForParsingW[] = { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n', 'g',0 }; WCHAR szRegPath[100]; LONG r; wcscpy (szRegPath, clsidW); SHELL32_GUIDToStringW (clsid, &szRegPath[6]); wcscat (szRegPath, shellfolderW); r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath, wantsForParsingW, NULL, NULL, NULL); if (r == ERROR_SUCCESS) bWantsForParsing = TRUE; else bWantsForParsing = FALSE; } if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) { /* * we need the filesystem path to the destination folder. * Only the folder itself can know it */ hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, pszPath, MAX_PATH); } else { /* parsing name like ::{...} */ pszPath[0] = ':'; pszPath[1] = ':'; SHELL32_GUIDToStringW (clsid, &pszPath[2]); } } else { /* user friendly name */ HCR_GetClassNameW (clsid, pszPath, MAX_PATH); } } else { int cLen = 0; /* file system folder or file rooted at the desktop */ if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) && (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) { lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1); PathAddBackslashW(pszPath); cLen = wcslen(pszPath); } _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen); if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); if (GetFileAttributes(pszPath) == INVALID_FILE_ATTRIBUTES) { /* file system folder or file rooted at the AllUsers desktop */ if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) && (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) { SHGetSpecialFolderPathW(0, pszPath, CSIDL_COMMON_DESKTOPDIRECTORY, FALSE); PathAddBackslashW(pszPath); cLen = wcslen(pszPath); } _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen); if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); } } } else { /* a complex pidl, let the subfolder do the work */ hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, pszPath, MAX_PATH); } if (SUCCEEDED(hr)) { /* Win9x always returns ANSI strings, NT always returns Unicode strings */ if (GetVersion() & 0x80000000) { strRet->uType = STRRET_CSTR; if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH, NULL, NULL)) strRet->u.cStr[0] = '\0'; CoTaskMemFree(pszPath); } else { strRet->uType = STRRET_WSTR; strRet->u.pOleStr = pszPath; } } else CoTaskMemFree(pszPath); TRACE ("-- (%p)->(%s,0x%08x)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr), hr); return hr; }
static rc_uint_type wind_WideCharToMultiByte (rc_uint_type cp, const unichar *u, char *mb, rc_uint_type mb_len) { rc_uint_type ret = 0; #if defined (_WIN32) || defined (__CYGWIN__) WINBOOL used_def = FALSE; ret = (rc_uint_type) WideCharToMultiByte (cp, 0, u, -1, mb, mb_len, NULL, & used_def); #elif defined (HAVE_ICONV) int first = 1; char tmp[32]; char *p_tmp; const char *iconv_name = wind_iconv_cp (cp); if (!u || !iconv_name) return 0; iconv_t cd = iconv_open (iconv_name, "UTF-16LE"); while (1) { int iret; const char *n_u = ""; char *n_tmp = ""; p_tmp = tmp; iret = iconv_onechar (cd, (ICONV_CONST char *) u, p_tmp, 32, &n_u, & n_tmp); if (first) { first = 0; continue; } if (!iret) { size_t l_tmp = (size_t) (n_tmp - p_tmp); if (mb) { if ((size_t) mb_len < l_tmp) break; memcpy (mb, tmp, l_tmp); mb += l_tmp; mb_len -= l_tmp; } ret += l_tmp; } else break; if (u[0] == 0) break; u = (const unichar *) n_u; } iconv_close (cd); #else if (cp) ret = 0; while (u[ret] != 0) ++ret; ++ret; if (mb) { while (*u != 0 && mb_len != 0) { if (u[0] == (u[0] & 0x7f)) *mb++ = (char) u[0]; else *mb++ = '_'; ++u; --mb_len; } if (mb_len != 0) *mb = 0; } #endif return ret; }
/*{ ** Name: TMget_stamp - Return timestamp. ** ** Description: ** Return a TM timestamp. ** Note, this routine is for the sole use of DMF for ** auditing and rollforward. ** ** Inputs: ** ** Outputs: ** time Pointer to location to return stamp. ** Returns: ** void ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 20-jan-1986 (Derek) ** Created. ** 06-jul-1987 (mmm) ** Initial Jupiter unix cl. ** 28-jul-1988 (daveb) ** Can't call input parameter "time" because that confilcts with the ** "time" system call you need on System V. ** 1-sep-89 (daveb) ** Enhance the uniqueness of the stamp by salting in the low ** 8 bits of the pid. ** 21-jun-93 (mikem) ** Only call getpid() once per process. ** 20-apr-94 (mikem) ** Added use of 2 new #defines (xCL_GETTIMEOFDAY_TIMEONLY and ** xCL_GETTIMEOFDAY_TIME_AND_TZ) in TMget_stamp() to describe 2 ** versions of gettimeofday() available. ** 29-Aug-2002 (hanal04) Bug 108609 INGSRV 1869. ** Explicitly set _daylight, _timezone and _tzname[0] in the ** DLL's global space. tzset() failed to pickup these values ** from the Date & Time application when TZ is not set so ** we must derrive them from GetTimezoneInformation() values. */ void TMget_stamp( TM_STAMP *stamp) { static int pid = 0; static TM_STAMP last_stamp = { 0, 0 }; time_t secs; SYSTEMTIME stime; TIME_ZONE_INFORMATION tz; static bool tz_init = TRUE; if(tz_init) { tz_init = FALSE; GetTimeZoneInformation( &tz ); /* Now setup the values tzset() should set but doesn't */ if(tz.DaylightBias) _daylight = 1; else _daylight = 0; _timezone = tz.Bias * 60; WideCharToMultiByte( CP_OEMCP, 0, tz.StandardName, -1, _tzname[0], sizeof(_tzname[0]), NULL, NULL); } secs = time(NULL); GetSystemTime( &stime ); stamp->tms_sec = (i4)secs; stamp->tms_usec = stime.wMilliseconds * 1000; /* To enhance the uniqueness of the returned value as a stamp, ** salt in the low 8 bits worth of the pid (daveb) */ gen_Psem(&CL_misc_sem); if (!pid) { pid = getpid(); /* B63625 (canor01) ** Since the low-order bits of the pid could potentially ** affect the above calculations, as a medium-term fix ** (suggested by sweeney) left shift the pid by two bits ** before or'ing it in. Really, though, we need two ** functions--one for unique stamp and one for time. */ pid <<= 2; } /* B63625: To further enhance the uniqueness of the returned value ** as a stamp in the case of *very* fast machines, make sure ** returns on consecutive calls are different. (canor01) */ if ( stamp->tms_sec == last_stamp.tms_sec && stamp->tms_usec <= last_stamp.tms_usec ) stamp->tms_usec = ++last_stamp.tms_usec; last_stamp.tms_sec = stamp->tms_sec; last_stamp.tms_usec = stamp->tms_usec; gen_Vsem(&CL_misc_sem); stamp->tms_usec |= (pid & 0xff); }
static char * getWmiInfo (int mode) { /* for more details about this wonderful API, see http://msdn.microsoft.com/en-us/site/aa394138 http://msdn.microsoft.com/en-us/site/aa390423 http://msdn.microsoft.com/en-us/library/windows/desktop/aa394138%28v=vs.85%29.aspx http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/d6420012-e432-4964-8506-6f6b65e5a451 */ char *buffer = (char *) malloc (128); HRESULT hres; HRESULT hr; IWbemLocator *pLoc = NULL; IWbemServices *pSvc = NULL; IEnumWbemClassObject *pEnumerator = NULL; IWbemClassObject *pclsObj; ULONG uReturn = 0; hres = CoInitializeEx (0, COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); if (FAILED (hres)) { strcpy (buffer, "Error Code 0"); return buffer; } hres = CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); /* mysteriously failing after the first execution, but only when used as a plugin, skip it */ /*if (FAILED (hres)) { CoUninitialize (); strcpy (buffer, "Error Code 1"); return buffer; }*/ hres = CoCreateInstance (CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc); if (FAILED (hres)) { CoUninitialize (); strcpy (buffer, "Error Code 2"); return buffer; } hres = pLoc->ConnectServer (_bstr_t (L"root\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &pSvc); if (FAILED (hres)) { pLoc->Release (); CoUninitialize (); strcpy (buffer, "Error Code 3"); return buffer; } hres = CoSetProxyBlanket (pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); if (FAILED (hres)) { pSvc->Release (); pLoc->Release (); CoUninitialize (); strcpy (buffer, "Error Code 4"); return buffer; } switch (mode) { case 0: hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_OperatingSystem"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); break; case 1: hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_Processor"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); break; case 2: hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_VideoController"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); break; } if (FAILED (hres)) { pSvc->Release (); pLoc->Release (); CoUninitialize (); strcpy (buffer, "Error Code 5"); return buffer; } while (pEnumerator) { hr = pEnumerator->Next (WBEM_INFINITE, 1, &pclsObj, &uReturn); if (0 == uReturn) { break; } VARIANT vtProp; switch (mode) { case 0: hr = pclsObj->Get (L"Caption", 0, &vtProp, 0, 0); break; case 1: hr = pclsObj->Get (L"Name", 0, &vtProp, 0, 0); break; case 2: hr = pclsObj->Get (L"Name", 0, &vtProp, 0, 0); break; } WideCharToMultiByte (CP_ACP, 0, vtProp.bstrVal, -1, buffer, SysStringLen (vtProp.bstrVal)+1, NULL, NULL); VariantClear (&vtProp); } pSvc->Release (); pLoc->Release (); pEnumerator->Release (); pclsObj->Release (); CoUninitialize (); return buffer; }
static void test_GetCalendarInfo(void) { char bufferA[20]; WCHAR bufferW[20]; DWORD val1, val2; int ret, ret2; if (!pGetCalendarInfoA || !pGetCalendarInfoW) { trace( "GetCalendarInfo missing\n" ); return; } ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER, NULL, 0, &val1 ); ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() ); ok( ret == sizeof(val1), "wrong size %u\n", ret ); ok( val1 >= 2000 && val1 < 2100, "wrong value %u\n", val1 ); ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER, NULL, 0, &val2 ); ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() ); ok( ret == sizeof(val2)/sizeof(WCHAR), "wrong size %u\n", ret ); ok( val1 == val2, "A/W mismatch %u/%u\n", val1, val2 ); ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, bufferA, sizeof(bufferA), NULL ); ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() ); ok( ret == 5, "wrong size %u\n", ret ); ok( atoi( bufferA ) == val1, "wrong value %s/%u\n", bufferA, val1 ); ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, bufferW, sizeof(bufferW), NULL ); ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() ); ok( ret == 5, "wrong size %u\n", ret ); memset( bufferA, 0x55, sizeof(bufferA) ); WideCharToMultiByte( CP_ACP, 0, bufferW, -1, bufferA, sizeof(bufferA), NULL, NULL ); ok( atoi( bufferA ) == val1, "wrong value %s/%u\n", bufferA, val1 ); ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER, NULL, 0, NULL ); ok( !ret, "GetCalendarInfoA succeeded\n" ); ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); ret = pGetCalendarInfoA( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, NULL, 0, NULL ); ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() ); ok( ret == 5, "wrong size %u\n", ret ); ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER, NULL, 0, NULL ); ok( !ret, "GetCalendarInfoW succeeded\n" ); ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, NULL, 0, NULL ); ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() ); ok( ret == 5, "wrong size %u\n", ret ); ret = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1, bufferA, sizeof(bufferA), NULL); ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() ); ret2 = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1, bufferA, 0, NULL); ok( ret2, "GetCalendarInfoA failed err %u\n", GetLastError() ); ok( ret == ret2, "got %d, expected %d\n", ret2, ret ); ret2 = pGetCalendarInfoW( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1, bufferW, sizeof(bufferW), NULL); ok( ret2, "GetCalendarInfoW failed err %u\n", GetLastError() ); ret2 = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL ); ok( ret == ret2, "got %d, expected %d\n", ret, ret2 ); }
void LIB_DATABASE_EXPORT CaUnicode2Utf8Len(unsigned short* src,int len,char*tar) { unsigned int n; n=WideCharToMultiByte(CP_UTF8,0,src,(unsigned int)-1,(unsigned char*)tar,len,0,0); tar[n]=0; }
static void test_legacy_filter_registration(void) { IFilterMapper2 *pMapper2 = NULL; IFilterMapper *pMapper = NULL; HRESULT hr; static const WCHAR wszFilterName[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', 0 }; static const CHAR szFilterName[] = "Testfilter"; static const WCHAR wszPinName[] = {'P', 'i', 'n', '1', 0 }; CLSID clsidFilter; CHAR szRegKey[MAX_PATH]; static const CHAR szClsid[] = "CLSID"; WCHAR wszGuidstring[MAX_PATH]; CHAR szGuidstring[MAX_PATH]; LONG lRet; HKEY hKey = NULL; IEnumMoniker *pEnum = NULL; BOOL found; IEnumRegFilters *pRegEnum = NULL; /* Test if legacy filter registration scheme works (filter is added to HKCR\Filter). IFilterMapper_RegisterFilter * registers in this way. Filters so registered must then be accessible through both IFilterMapper_EnumMatchingFilters * and IFilterMapper2_EnumMatchingFilters. */ hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper2); ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr); if (FAILED(hr)) goto out; hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterMapper, (LPVOID)&pMapper); ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %x\n", hr); if (FAILED(hr)) goto out; /* Register a test filter. */ hr = CoCreateGuid(&clsidFilter); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); lRet = StringFromGUID2(&clsidFilter, wszGuidstring, MAX_PATH); ok(lRet > 0, "StringFromGUID2 failed\n"); if (!lRet) goto out; WideCharToMultiByte(CP_ACP, 0, wszGuidstring, -1, szGuidstring, MAX_PATH, 0, 0); lstrcpyA(szRegKey, szClsid); lstrcatA(szRegKey, "\\"); lstrcatA(szRegKey, szGuidstring); /* Register---- functions need a filter class key to write pin and pin media type data to. Create a bogus * class key for it. */ lRet = RegCreateKeyExA(HKEY_CLASSES_ROOT, szRegKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (lRet == ERROR_ACCESS_DENIED) skip("Not authorized to register filters\n"); else { ok(lRet == ERROR_SUCCESS, "RegCreateKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet)); /* Set default value - this is interpreted as "friendly name" later. */ lRet = RegSetValueExA(hKey, NULL, 0, REG_SZ, (LPBYTE)szFilterName, lstrlenA(szFilterName) + 1); ok(lRet == ERROR_SUCCESS, "RegSetValueExA failed with %x\n", HRESULT_FROM_WIN32(lRet)); if (hKey) RegCloseKey(hKey); hKey = NULL; hr = IFilterMapper_RegisterFilter(pMapper, clsidFilter, wszFilterName, MERIT_UNLIKELY); ok(hr == S_OK, "IFilterMapper_RegisterFilter failed with %x\n", hr); hr = IFilterMapper_RegisterPin(pMapper, clsidFilter, wszPinName, TRUE, FALSE, FALSE, FALSE, GUID_NULL, NULL); ok(hr == S_OK, "IFilterMapper_RegisterPin failed with %x\n", hr); hr = IFilterMapper_RegisterPinType(pMapper, clsidFilter, wszPinName, GUID_NULL, GUID_NULL); ok(hr == S_OK, "IFilterMapper_RegisterPinType failed with %x\n", hr); hr = IFilterMapper2_EnumMatchingFilters(pMapper2, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE, 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL); ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pEnum) { found = enum_find_filter(wszFilterName, pEnum); ok(found, "IFilterMapper2_EnumMatchingFilters failed to return the test filter\n"); } if (pEnum) IEnumMoniker_Release(pEnum); pEnum = NULL; found = FALSE; hr = IFilterMapper_EnumMatchingFilters(pMapper, &pRegEnum, MERIT_UNLIKELY, TRUE, GUID_NULL, GUID_NULL, FALSE, FALSE, GUID_NULL, GUID_NULL); ok(hr == S_OK, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pRegEnum) { ULONG cFetched; REGFILTER *prgf; while(!found && IEnumRegFilters_Next(pRegEnum, 1, &prgf, &cFetched) == S_OK) { CHAR val[512]; WideCharToMultiByte(CP_ACP, 0, prgf->Name, -1, val, sizeof(val), 0, 0); if (!lstrcmpA(val, szFilterName)) found = TRUE; CoTaskMemFree(prgf); } IEnumRegFilters_Release(pRegEnum); } ok(found, "IFilterMapper_EnumMatchingFilters failed to return the test filter\n"); hr = IFilterMapper_UnregisterFilter(pMapper, clsidFilter); ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr); lRet = RegOpenKeyExA(HKEY_CLASSES_ROOT, szClsid, 0, KEY_WRITE | DELETE, &hKey); ok(lRet == ERROR_SUCCESS, "RegOpenKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet)); lRet = RegDeleteKeyA(hKey, szGuidstring); ok(lRet == ERROR_SUCCESS, "RegDeleteKeyA failed with %x\n", HRESULT_FROM_WIN32(lRet)); } if (hKey) RegCloseKey(hKey); hKey = NULL; out: if (pMapper) IFilterMapper_Release(pMapper); if (pMapper2) IFilterMapper2_Release(pMapper2); }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR szCmdLine, int iCmdShow) { int argc = __argc; wchar_t **argv = __wargv; #else #define WERL 0 int wmain(int argc, wchar_t **argv) { #endif HANDLE erlexec_handle; /* Instance */ ErlexecFunction *win_erlexec; wchar_t *path = malloc(100*sizeof(wchar_t)); wchar_t *npath; int pathlen; char ** utf8argv; int i, len; get_parameters(); if ((pathlen = GetEnvironmentVariableW(L"PATH",path,100)) == 0) { error("No PATH variable (!)"); } else if (pathlen > 100) { path = realloc(path,pathlen*sizeof(wchar_t)); GetEnvironmentVariableW(L"PATH",path,pathlen); } pathlen = (wcslen(path) + wcslen(erlexec_dir) + 2); npath = (wchar_t *) malloc(pathlen*sizeof(wchar_t)); swprintf(npath,pathlen,L"%s;%s",erlexec_dir,path); SetEnvironmentVariableW(L"PATH",npath); if ((erlexec_handle = LoadLibraryW(erlexec_name)) == NULL) { error("Could not load module %S.",erlexec_name); } if ((win_erlexec = (ErlexecFunction *) GetProcAddress(erlexec_handle,"win_erlexec")) == NULL) { error("Could not find entry point \"win_erlexec\" in %S.", erlexec_name); } /* Convert argv to utf8 */ utf8argv = malloc((argc+1) * sizeof(char*)); for (i=0; i<argc; i++) { len = WideCharToMultiByte(CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL); utf8argv[i] = malloc(len*sizeof(char)); WideCharToMultiByte(CP_UTF8, 0, argv[i], -1, utf8argv[i], len, NULL, NULL); } utf8argv[argc] = NULL; #ifdef HARDDEBUG { wchar_t tempbuf[2048] = L""; wchar_t *sbuf; int i; sbuf=tempbuf; sbuf += swprintf(sbuf, 2048, L"utf16: %d\n", argc); for (i = 0; i < argc; ++i) { sbuf += swprintf(sbuf, 2048, L"|%s|", argv[i]); }; sbuf += swprintf(sbuf, 2048, L"\nutf8: \n"); for (i = 0; i < argc; ++i) { sbuf += swprintf(sbuf, 2048, L"|%S|", utf8argv[i]); }; MessageBoxW(NULL, tempbuf, L"erl_exec args", MB_OK|MB_ICONERROR); } #endif return (*win_erlexec)(argc,utf8argv,erlexec_handle,WERL); }
void CFolderInfo::CalculateSize() { std::list<CRawString> folderQueue; folderQueue.push_back(m_Path.c_str()); WCHAR searchPattern[MAX_PATH + 10]; WCHAR buffer[MAX_PATH]; char utf8Buf[MAX_PATH * 3]; WIN32_FIND_DATA findData; HANDLE findHandle; while (!folderQueue.empty()) { const CRawString& ref = folderQueue.front(); wsprintf(searchPattern, L"%s%s", ref.c_str(), L"\\*.*"); findHandle = FindFirstFile(searchPattern, &findData); if (INVALID_HANDLE_VALUE == findHandle) { folderQueue.pop_front(); continue; } do { // special case for "." and ".." if (wcscmp(findData.cFileName, L".") == 0 || wcscmp(findData.cFileName, L"..") == 0) { continue; } bool isFolder = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0; if (!m_IncludeHiddenFiles && (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) { continue; } else if (!m_IncludeSystemFiles && (findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)) { continue; } else if (!isFolder && m_RegExpFilter) { int utf8BufLen = WideCharToMultiByte(CP_UTF8, 0, findData.cFileName, wcslen(findData.cFileName) + 1, utf8Buf, MAX_PATH * 3, NULL, NULL); if (0 != pcre_exec(m_RegExpFilter, NULL, utf8Buf, utf8BufLen, 0, 0, NULL, 0)) { continue; } } if (isFolder) { m_FolderCount++; if (m_IncludeSubFolders) { wsprintf(buffer, L"%s\\%s", ref.c_str(), findData.cFileName); folderQueue.push_back(buffer); } } else { m_FileCount++; m_Size += ((UINT64)findData.nFileSizeHigh << 32) + findData.nFileSizeLow; } } while (FindNextFile(findHandle, &findData)); FindClose(findHandle); folderQueue.pop_front(); } }
static void SendWordToServer() { DWORD_PTR SendMsgAnswer; DWORD flags; LRESULT lr; if( !IsWindow( GlobalData->ServerWND ) ) return; // Ask for needing to retrieve word - WPARAM = 1 lr = SendMessageTimeout(GlobalData->ServerWND, WM_MY_SHOW_TRANSLATION, 1, 0, SMTO_ABORTIFHUNG, MOUSEOVER_INTERVAL, &SendMsgAnswer); if( lr == 0 || SendMsgAnswer == 0) //No answer or no needing return; flags = SendMsgAnswer; if (hGetWordLib == 0 && ( flags & GD_FLAG_METHOD_STANDARD ) ) { hGetWordLib = LoadLibraryW(GlobalData->LibName); if (hGetWordLib) { GetWordProc = (GetWordProc_t)GetProcAddress(hGetWordLib, "__gdGetWord"); } else { hGetWordLib = INVALID_HANDLE_VALUE; } } GlobalData->CurMod.MatchedWord[0] = 0; GlobalData->CurMod.WordLen = 0; GlobalData->CurMod.BeginPos = 0; if( ( flags & GD_FLAG_METHOD_GD_MESSAGE ) != 0 && uGdAskMessage != 0 ) { int n; gds.dwSize = sizeof(gds); gds.cwData = Buffer; gds.dwMaxLength = sizeof(Buffer) / sizeof(Buffer[0]); Buffer[0] = 0; gds.hWnd = GlobalData->LastWND; gds.Pt = GlobalData->LastPt; lr = SendMessageTimeout(gds.hWnd, uGdAskMessage, 0, (LPARAM)&gds, SMTO_ABORTIFHUNG, REQUEST_MESSAGE_INTERVAL, &SendMsgAnswer); if(lr != 0 && SendMsgAnswer != 0) { n = WideCharToMultiByte(CP_UTF8, 0, gds.cwData, lstrlenW(gds.cwData), GlobalData->CurMod.MatchedWord, sizeof(GlobalData->CurMod.MatchedWord) - 1, 0, 0); GlobalData->CurMod.MatchedWord[n] = 0; GlobalData->CurMod.WordLen = n; GlobalData->CurMod.BeginPos = 0; if(n > 0) { if( IsWindow( GlobalData->ServerWND ) ) { #ifdef __WIN64 GlobalData32->LastWND = HandleToLong( GlobalData->LastWND ); GlobalData32->CurMod.WordLen = n; GlobalData32->CurMod.BeginPos = 0; lstrcpyn( GlobalData32->CurMod.MatchedWord, GlobalData->CurMod.MatchedWord, sizeof( GlobalData32->CurMod.MatchedWord ) ); #endif SendMessageTimeout(GlobalData->ServerWND, WM_MY_SHOW_TRANSLATION, 0, 0, SMTO_ABORTIFHUNG, MOUSEOVER_INTERVAL, &SendMsgAnswer); } } return; } } if( ( flags & GD_FLAG_METHOD_STANDARD ) != 0 && GetWordProc != 0 ) { GlobalData->CurMod.WND = GlobalData->LastWND; GlobalData->CurMod.Pt = GlobalData->LastPt; GetWordProc(&(GlobalData->CurMod)); if (GlobalData->CurMod.WordLen > 0) { if( IsWindow( GlobalData->ServerWND ) ) { #ifdef __WIN64 GlobalData32->LastWND = HandleToLong( GlobalData->LastWND ); GlobalData32->CurMod.WordLen = GlobalData->CurMod.WordLen; GlobalData32->CurMod.BeginPos = GlobalData->CurMod.BeginPos; lstrcpyn( GlobalData32->CurMod.MatchedWord, GlobalData->CurMod.MatchedWord, sizeof( GlobalData32->CurMod.MatchedWord ) ); #endif SendMessageTimeout(GlobalData->ServerWND, WM_MY_SHOW_TRANSLATION, 0, 0, SMTO_ABORTIFHUNG, MOUSEOVER_INTERVAL, &SendMsgAnswer); } return; } } if( ( flags & GD_FLAG_METHOD_IACCESSIBLEEX ) != 0 ) { getWordByAccEx( GlobalData->LastPt ); if (GlobalData->CurMod.WordLen > 0 ) { if( IsWindow( GlobalData->ServerWND ) ) { #ifdef __WIN64 GlobalData32->LastWND = HandleToLong( GlobalData->LastWND ); GlobalData32->CurMod.WordLen = GlobalData->CurMod.WordLen; GlobalData32->CurMod.BeginPos = GlobalData->CurMod.BeginPos; lstrcpyn( GlobalData32->CurMod.MatchedWord, GlobalData->CurMod.MatchedWord, sizeof( GlobalData32->CurMod.MatchedWord ) ); #endif SendMessageTimeout(GlobalData->ServerWND, WM_MY_SHOW_TRANSLATION, 0, 0, SMTO_ABORTIFHUNG, MOUSEOVER_INTERVAL, &SendMsgAnswer); } return; } } if( ( flags & GD_FLAG_METHOD_UI_AUTOMATION ) != 0 && IsWindow( GlobalData->ServerWND ) ) { PostMessage( GlobalData->ServerWND, WM_MY_SHOW_TRANSLATION, 0, 0 ); } }
// // Function: LoadProviderPath // // Description: // This function retrieves the provider's DLL path, expands any environment // variables, loads the DLL, and retrieves it's WSPStartup function. // BOOL LoadProviderPath( PROVIDER *loadProvider, int *lpErrno ) { int rc; *lpErrno = 0; // Retrieve the provider path of the lower layer loadProvider->ProviderPathLen = MAX_PATH - 1; rc = WSCGetProviderPath( &loadProvider->NextProvider.ProviderId, loadProvider->ProviderPathW, &loadProvider->ProviderPathLen, lpErrno ); if ( SOCKET_ERROR == rc ) { dbgprint("LoadProviderPath: WSCGetProviderPath failed: %d", *lpErrno ); goto cleanup; } rc = ExpandEnvironmentStringsW( loadProvider->ProviderPathW, loadProvider->LibraryPathW, MAX_PATH - 1 ); if ( ( 0 != rc ) && ( MAX_PATH-1 >= rc ) ) { loadProvider->Module = LoadLibraryW( loadProvider->LibraryPathW ); if ( NULL == loadProvider->Module ) { dbgprint("LoadProviderPath: LoadLibraryW failed: %d", GetLastError() ); goto cleanup; } } else if ( 0 == rc ) { char ProviderPathA[ MAX_PATH ], LibraryPathA[ MAX_PATH ]; // No UNICODE so we must be on Win9x rc = WideCharToMultiByte( CP_ACP, 0, loadProvider->ProviderPathW, loadProvider->ProviderPathLen, ProviderPathA, MAX_PATH, NULL, NULL ); if ( 0 == rc ) { dbgprint("LoadProviderPath: WideCharToMultiByte failed: %d", GetLastError() ); goto cleanup; } rc = ExpandEnvironmentStringsA( ProviderPathA, LibraryPathA, MAX_PATH - 1 ); if ( ( 0 == rc ) || ( MAX_PATH - 1 < rc ) ) { dbgprint("LoadProviderPath: ExpandEnvironmentStringsA failed: %d", GetLastError() ); goto cleanup; } loadProvider->Module = LoadLibraryA( LibraryPathA ); if ( NULL == loadProvider->Module ) { dbgprint("LoadProviderPath: LoadLibraryA failed: %d", GetLastError() ); goto cleanup; } } // Retrieve the next provider's WSPSTartup function loadProvider->fnWSPStartup = (LPWSPSTARTUP) GetProcAddress( loadProvider->Module, "WSPStartup" ); if ( NULL == loadProvider->fnWSPStartup ) { dbgprint("LoadProviderPath: GetProcAddress failed: %d", GetLastError() ); goto cleanup; } return TRUE; cleanup: if ( *lpErrno == 0 ) *lpErrno = GetLastError(); return FALSE; }
/*++ Function: RemoveDirectoryW See MSDN doc. --*/ BOOL PALAPI RemoveDirectoryW( IN LPCWSTR lpPathName) { PathCharString mb_dirPathString; int mb_size; DWORD dwLastError = 0; BOOL bRet = FALSE; size_t length; char * mb_dir; PERF_ENTRY(RemoveDirectoryW); ENTRY("RemoveDirectoryW(lpPathName=%p (%S))\n", lpPathName?lpPathName:W16_NULLSTRING, lpPathName?lpPathName:W16_NULLSTRING); if (lpPathName == NULL) { dwLastError = ERROR_PATH_NOT_FOUND; goto done; } length = (PAL_wcslen(lpPathName)+1) * 3; mb_dir = mb_dirPathString.OpenStringBuffer(length); if (NULL == mb_dir) { dwLastError = ERROR_NOT_ENOUGH_MEMORY; goto done; } mb_size = WideCharToMultiByte( CP_ACP, 0, lpPathName, -1, mb_dir, length, NULL, NULL ); mb_dirPathString.CloseBuffer(mb_size); if( mb_size == 0 ) { dwLastError = GetLastError(); if( dwLastError == ERROR_INSUFFICIENT_BUFFER ) { WARN("lpPathName is larger than MAX_LONGPATH (%d)!\n", MAX_LONGPATH); dwLastError = ERROR_FILENAME_EXCED_RANGE; } else { ASSERT("WideCharToMultiByte failure! error is %d\n", dwLastError); dwLastError = ERROR_INTERNAL_ERROR; } goto done; } if ((bRet = RemoveDirectoryHelper (mb_dir, &dwLastError))) { TRACE("Removal of directory [%s] was successful.\n", mb_dir); } done: if( dwLastError ) { SetLastError( dwLastError ); } LOGEXIT("RemoveDirectoryW returns BOOL %d\n", bRet); PERF_EXIT(RemoveDirectoryW); return bRet; }
int IsRealUnicode(TCHAR *value) { BOOL nonascii = 0; WideCharToMultiByte(Langpack_GetDefaultCodePage(), WC_NO_BEST_FIT_CHARS, value, -1, NULL, 0, NULL, &nonascii); return nonascii; }
static const char *debugstr_w(LPCWSTR str) { static char buf[1024]; WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL); return buf; }