Example #1
0
void CIISxpressHttpModule::OpenLog(IHttpContext* pHttpContext)
{
	if (pHttpContext != NULL && m_Config.GetLoggingLevel() >= IISXPRESS_LOGGINGLEVEL_BASIC)
	{
		CAtlString installPath;
		m_Config.GetInstallPath(installPath);

		if (installPath.GetLength() > 0)
		{		
			CPathT<CAtlString> LogPath(installPath);			
			LogPath.Append(_T("\\Logs"));

			if (LogPath.IsDirectory() == FALSE)
			{
				::CreateDirectory(LogPath, NULL);	
			}

			CAtlString sLogFilePrefix;
			sLogFilePrefix.LoadString(IDS_LOGFILENAMEPREFIX);

			CAtlString sAppName;
			if (GetAppPoolName(pHttpContext, sAppName) == true)
			{
				sLogFilePrefix += sAppName;
				sLogFilePrefix += "-";
			}		

			m_Log.Init(LogPath, sLogFilePrefix, _T("log"));		
		}
	}
}
Example #2
0
CAtlString GetErrorDescription(HRESULT hr)
{

	CAtlString aStr;
	aStr.Format("HRESULT=0x%x; ErrorString=%s; Description=%s", hr, DXGetErrorString8(hr), DXGetErrorDescription8(hr));
	return aStr; 
}
Example #3
0
int Runner::NewCmd(LPCTSTR taskname, LPTSTR lpCmdLine)
{
	Params::Save(lpCmdLine);

	DWORD dwProcessId = ::GetCurrentProcessId();
    CHandle hEventRun( ::CreateEvent( NULL, FALSE, TRUE, c_szEventRun));
	if (::WaitForSingleObject(hEventRun, c_dwRunTimeout) != WAIT_OBJECT_0)
		return ecSimultanius;

	CString strEvent;
	strEvent.Format(c_szEventExit, dwProcessId);
	CHandle hEventExit( ::CreateEvent( NULL, TRUE, FALSE, strEvent));
	::ResetEvent( hEventExit);

    CAtlString sApp;
	sApp.Format(_T("schtasks /run /TN \"%s\""), taskname);

    STARTUPINFO startup_info = {0};
    startup_info.cb = sizeof( STARTUPINFO );
    PROCESS_INFORMATION process_info = {0};

    BOOL bStatus = ::CreateProcess( NULL, sApp.GetBuffer(MAX_PATH), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startup_info, &process_info );
    if ( bStatus == FALSE)
        return ecRunTask;
    ::CloseHandle( process_info.hProcess );
    ::CloseHandle( process_info.hThread );

	if (::WaitForSingleObject(hEventRun, c_dwRunTimeout) != WAIT_OBJECT_0)
		return ecUnknown;

    ::WaitForSingleObject(hEventExit, INFINITE);

    return ecNoError;
}
Example #4
0
	std::wstring Desc() const
	{
		CAtlString s;
		s.Format(L"<TCP PID:%d Local:(%s:%d) Remote:(%s:%d), State:%d>",
			dwOwningPid, Local().c_str(), dwLocalPort, Remote().c_str(), dwRemotePort, dwState);
		return (LPCTSTR)s;
	}
void CFilePage::OnBnClickedBtnIocpTest()
{
    //BOOL bRet = FALSE;
    BOOL bRet = FALSE;

    //CFIocpFileReadTask  fileReadTask;
    //API_VERIFY(fileReadTask.Create(TEXT("D:\\test.jpg"), 
    //    GENERIC_WRITE | GENERIC_READ, 
    //    FILE_SHARE_READ, NULL,
    //    OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED));

    CFElapseCounter counter;
    for (INT i = 0; i < m_nCopyFileCount; i++)
    {
        CFIocpCopyFileTask* pFileCopyTask = new CFIocpCopyFileTask(&m_iocpMgr);
        CAtlString strTagetFile;
        strTagetFile.Format(TEXT("E:\\TargetCopy_%d.txt"), counter.GetElapseTime() % LONG_MAX);
        pFileCopyTask->OpenFiles(m_strCopySrcFile, strTagetFile);
        m_iocpMgr.AssociateTask(pFileCopyTask, TRUE);
    }


    //fileIocpTask.m_OverLapped.overLapped.Offset = 0;

    //fileIocpTask.WriteFileHeader((LPOVERLAPPED)&fileIocpTask.m_OverLapped);

    //fileReadTask.Close();

    //iocpMgr.Stop();
    //iocpMgr.Close();
}
Example #6
0
std::wstring Helpers::LoadString(UINT uID)
{
	CAtlString localized;

	if(localized.LoadStringW(uID))
		return std::wstring(localized);
	else
		return std::wstring(L"LoadString failed");
}
Example #7
0
void CChatLog::adjust(const TCHAR* format, ...)
{
	CAtlString cs;
	va_list ap;

	va_start(ap, format);
	cs.FormatV(format, ap);
	va_end(ap);

	write(reinterpret_cast<const void*>(static_cast<const TCHAR*>(cs)), cs.GetLength());
}
Example #8
0
/*
 * Converts the specified (sub-)string into a Variant value.
 */
CComVariant CMELCommand::MakeVariantNotArray(const CAtlString& strText)
{
	CComVariant variant(strText);
	if (strText.SpanExcluding(L"0123456789.-+e").IsEmpty()) {
		if (strText.Find(L".") < 0) {
			variant.ChangeType(VT_I4);
		} else {
			variant.ChangeType(VT_R8);
		}
	}
	return variant;
}
Example #9
0
HTREEITEM DlgSettingsMain::AddDialogToTree(const UINT id, const std::shared_ptr<DlgSettingsBase>& newDlg, CRect& rect, HTREEITEM htiParent /*= NULL*/)
{
	newDlg->Create(m_hWnd, rect);
	newDlg->SetWindowPos(HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOSIZE);

	CAtlString strName;
	strName.LoadString (id);
	HTREEITEM hItem = m_treeCtrl.InsertItem(strName, htiParent, NULL);

	if (hItem != NULL) m_settingsDlgMap.insert(SettingsDlgsMap::value_type(hItem, newDlg));

	return hItem;
}
Example #10
0
	virtual void debugout(TCHAR* format, ...)
	{
		CAtlString ds;
		va_list ap;

		va_start(ap, format);
		ds.FormatV(format, ap);
		va_end(ap);

		if (_out_type == DEBUGOUT_STRING)
			_output_string(ds);
		else if (_out_type == DEBUGOUT_FILE)
			_output_file(ds);
	}
void CTedTransformDialog::PopulateCategory(DMOCategory& category) 
{
    TVINSERTSTRUCT treeInserter;
    treeInserter.hParent = TVI_ROOT;
    treeInserter.hInsertAfter = TVI_FIRST;

    CAtlString strName = LoadAtlString(category.m_nID);
    TVITEM item;
    item.mask = TVIF_TEXT;
    item.pszText = strName.GetBuffer();
    item.cchTextMax = strName.GetLength();

    treeInserter.item = item;
    HTREEITEM hBaseItem = (HTREEITEM) TreeView_InsertItem(m_hList, &treeInserter);

    assert(hBaseItem != NULL);

    treeInserter.hParent = hBaseItem;
    item.mask = TVIF_TEXT | TVIF_PARAM;

    DMO_PARTIAL_MEDIATYPE mediaType;
    CComPtr<IEnumDMO> spDMOList;

    mediaType.type = GUID_NULL;
    mediaType.subtype = GUID_NULL;
    
    IMFActivate** ppActivates = NULL;
    UINT32 cMFTs = 0;
    ::MFTEnumEx(category.m_GUID, MFT_ENUM_FLAG_ALL, NULL, NULL, &ppActivates, &cMFTs);

    for(DWORD i = 0; i < cMFTs; i++)
    {
        m_Activates.Add(ppActivates[i]);

        LPWSTR pszName = NULL;
        ppActivates[i]->GetAllocatedString(MFT_FRIENDLY_NAME_Attribute, &pszName, NULL);
        
        m_strNames.Add(CAtlStringW(pszName));
        item.pszText = m_strNames.GetAt(m_strNames.GetCount() - 1).GetBuffer();
        item.lParam = (LPARAM)  m_Activates.GetCount() - 1;

        treeInserter.item = item;

        TreeView_InsertItem(m_hList, &treeInserter);
        
        CoTaskMemFree(pszName);
    }

    CoTaskMemFree(ppActivates);
}
Example #12
0
bool CIISxpressHttpModule::GetAppPoolName(IHttpContext* pHttpContext, CAtlString& name)
{
	bool status = false;

	if (m_pHttpServer != NULL)
	{
		LPCWSTR pszAppPoolName = m_pHttpServer->GetAppPoolName();
		if (pszAppPoolName != NULL)
		{
			name = CAtlString(pszAppPoolName);
			status = true;
		}
	}

	// if we didn't get the application pool name from the server then at least try and fall back to the application id
	if (!status && pHttpContext != NULL)
	{
		IHttpApplication* pApp = pHttpContext->GetApplication();
		if (pApp != NULL)
		{
			PCWSTR pszAppId = pApp->GetApplicationId();
			if (pszAppId != NULL)
			{
				name = CAtlString(pszAppId);
				name.Replace('/', '_');
				status = true;
			}
		}
	}
	
	return status;
}
Example #13
0
size_t Misc::SplitString(const CString & str, LPCTSTR tokens, CAtlList<CString> & list)
{
  list.RemoveAll();
  CAtlString token;
  int curPos = 0;

  token = str.Tokenize(tokens, curPos);
  while (-1 != curPos)
  {
    if (!token.IsEmpty())
    {
      list.AddTail(token);
    }
    token = str.Tokenize(tokens, curPos);
  }
  return list.GetCount();
}
Example #14
0
HRESULT CIIS7XMLConfigHelper::GetSiteNode(IXMLDOMDocument* pDoc, LPCWSTR pszId, IXMLDOMNode** ppSite)
{
	if (pDoc == NULL || pszId == NULL || ppSite == NULL)
		return E_POINTER;

	// we want the site corresponding to the instance string
	CAtlString sSitesQuery;
	sSitesQuery.Format(_T("/configuration/system.applicationHost/sites/site[@id='%ls']"), pszId);

	CComPtr<IXMLDOMNode> pSite;
	HRESULT hr = pDoc->selectSingleNode(CComBSTR(sSitesQuery), &pSite);
	if (hr != S_OK)
		return hr;
		
	if (pSite == NULL)
		return E_FAIL;

	return pSite.CopyTo(ppSite);
}
Example #15
0
CAtlString RegValue::GetString(LPCTSTR lpValue)
{
	CheckReadPerissions();

	DWORD dLen;
	DWORD dwType;
	m_stResult = ::RegQueryValueEx( (HKEY)m_hKey.m_h, lpValue, 0, &dwType, NULL, &dLen);
    CheckError("Can't query registry value");

	if (dwType != REG_SZ)
		throw std::runtime_error("Incompatible types");

    CAtlString str;
	m_stResult = ::RegQueryValueEx( (HKEY)m_hKey.m_h, lpValue, 0, NULL,
		(LPBYTE)str.GetBuffer(dLen / sizeof(TCHAR) + 1), &dLen);
    CheckError("Can't query registry value");

    str.ReleaseBuffer(dLen / sizeof(TCHAR));
	str.ReleaseBuffer();
	return str;
}
Example #16
0
void ChatControl::addUserToMessageText(const tstring& sUser) {
  int iSelBegin, iSelEnd;
  ctrlMessage.GetSel(iSelBegin, iSelEnd);
  if ((iSelBegin == 0) && (iSelEnd == 0)) {
    CAtlString sText;
    ctrlMessage.GetWindowText(sText);
    tstring text = sUser + _T(": ");
    if (sText.GetLength() == 0) {
      ctrlMessage.SetWindowText(text.c_str());
      ctrlMessage.SetFocus();
      ctrlMessage.SetSel(text.length(), text.length(), FALSE);
    } 
    else {
      ctrlMessage.ReplaceSel(text.c_str());
      ctrlMessage.SetFocus();
    }
  } 
  else {
    tstring text = sUser + _T(": ");
    ctrlMessage.ReplaceSel(text.c_str());
    ctrlMessage.SetFocus();
  }
}
HRESULT 
CWlanManager::SetHostedNetworkKey(
    CAtlString& strKey
    )
{
    HRESULT hr = S_OK;
    DWORD dwError = ERROR_SUCCESS;
    UCHAR strKeyBuf[WLAN_MAX_NAME_LENGTH];
    DWORD dwKeyBufLen = WLAN_MAX_NAME_LENGTH;

    dwError = ConvertPassPhraseKeyStringToBuffer(
                strKey,
                strKey.GetLength(),
                DOT11_AUTH_ALGO_RSNA_PSK,
                strKeyBuf,
                &dwKeyBufLen
                );

    BAIL_ON_WIN32_ERROR(dwError, hr);

    if (0 == dwKeyBufLen)
    {
        BAIL_ON_WIN32_ERROR(ERROR_INVALID_PARAMETER, hr);
    }

    dwError = WlanHostedNetworkSetSecondaryKey(
                m_WlanHandle,
                dwKeyBufLen,
                strKeyBuf,
                TRUE,           // passphrase
                TRUE,           // persistent
                NULL,           // not interested in failure reason
                NULL            // reserved
                );

    BAIL_ON_WIN32_ERROR(dwError, hr);

error:
    return hr;
}
Example #18
0
/*
 * Converts the specified (reply) string into a Variant value.
 * If the string contains tab characters ('\t), the string is
 * considered to contain an array of values.
 */
CComVariant CMELCommand::MakeVariant(const CAtlString& strText)
{
	int tabCount = 0;
	int tabPos = 0;
	while (tabPos < strText.GetLength()) {
		tabPos = strText.Find(L'\t', tabPos);
		if (tabPos < 0)
			break;
		++tabCount;
		++tabPos;
	}
	if (!tabCount) {
		return MakeVariantNotArray(strText);
	}
	CComSafeArray<VARIANT> safeArray;
	safeArray.Create(tabCount + 1);
	int curPos = 0;
	int index = 0;
	tabPos = strText.Find(L'\t');
	for (;;) {
		CAtlString strElement;
		if (tabPos > curPos) {
			strElement = strText.Mid(curPos, tabPos - curPos).Trim();
		}
		safeArray[index++] = MakeVariantNotArray(strElement);
		curPos = tabPos + 1;
		if (curPos == strText.GetLength()) {
			safeArray[index] = CComVariant(L"");
			break;
		}
		tabPos = strText.Find(L'\t', curPos);
		if (tabPos < 0) {
			safeArray[index] = MakeVariant(strText.Mid(curPos).Trim());
			break;
		}
	}
	return CComVariant(safeArray);
}
   // typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

   CAtlString s(_T("ABC"));

   ASSERT(s.MakeLower() == _T("abc"));   
   // typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

   CAtlString strBang(_T("Everybody likes epee fencing"));
   int n = strBang.Replace(_T("epee"), _T("foil"));
   ASSERT(n == 1);   
Example #21
0
HRESULT IGConfigManager::readConfiguration (HINSTANCE hInstance, LPCWSTR pwConfigRes, BOOL bOverwrite)
{
	// read the config file
	HANDLE hFile = ::CreateFile (m_wsConfigPath.c_str(), GENERIC_READ, FILE_SHARE_READ,
								 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (bOverwrite)
	{
		if (hFile == INVALID_HANDLE_VALUE)
		{
			return E_FAIL; // cannot overwrite non existing file
		}
		else
		{
			::CloseHandle (hFile);
			BOOL bSuccess = ::DeleteFile (m_wsConfigPath.c_str());
			if (bSuccess)
				hFile = INVALID_HANDLE_VALUE;
			else
				return E_FAIL; // impossible to delete corrupted file
		}
	}
	int nRes = ::SHCreateDirectory (NULL, m_wsUserHistoryPath.c_str());
	if ((nRes != ERROR_SUCCESS) && (nRes != ERROR_FILE_EXISTS) && (nRes != ERROR_ALREADY_EXISTS))
		return E_FAIL;
	
	// delete all history files
	if ((nRes == ERROR_FILE_EXISTS) || (nRes == ERROR_ALREADY_EXISTS))
		deleteHistory();

	HRESULT hr = S_OK;
	if (!m_spXMLDoc)
		hr = ::CoCreateInstance(CLSID_DOMDocument30, NULL, CLSCTX_INPROC_SERVER, 
									IID_IXMLDOMDocument, (void**)&m_spXMLDoc);
	if (FAILED(hr))
		return E_FAIL;

	char *pXmlFileBuffer = NULL;
	if (hFile == INVALID_HANDLE_VALUE)
	{
		CAtlString strConfigPath (IGCONFIGMANAGER_CONFIGPATH);
		CAtlString resToken, nextToken, nextNextToken;
		int curPos = 0;
		wstring wsConstructPath (m_wsUserPath);
		nextToken = strConfigPath.Tokenize(_T("\\"), curPos);
		nextNextToken = strConfigPath.Tokenize(_T("\\"), curPos);
		do
		{
			resToken = nextToken;
			nextToken = nextNextToken;
			nextNextToken = strConfigPath.Tokenize(_T("\\"), curPos);
			wsConstructPath += L"\\" + resToken;
			::CreateDirectory (wsConstructPath.c_str(), NULL);			
		}while (nextNextToken != _T(""));

		hFile = ::CreateFile (m_wsConfigPath.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE,
								 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hFile == INVALID_HANDLE_VALUE)
			return E_FAIL;
		// File does not exist, open the default config file
		char *pValidXml = IGConfigManager::CreateBufferFromRes (hInstance, pwConfigRes, L"Configuration");
		VARIANT_BOOL bSucceeded;
		hr = m_spXMLDoc->loadXML (CComBSTR(pValidXml), &bSucceeded);
		if ((hr != S_OK) || !bSucceeded)
			return E_FAIL;
		delete [] pValidXml;
		::CloseHandle (hFile);
	}
	else
	{
		::CloseHandle (hFile);
		VARIANT_BOOL bSucceeded;
		hr = m_spXMLDoc->load (CComVariant(m_wsConfigPath.c_str()), &bSucceeded);
		if ((hr != S_OK) || !bSucceeded)
			return E_FAIL;
	}
	if (m_spNodeCommonConfig)
		m_spNodeCommonConfig.Release();
	hr = m_spXMLDoc->selectSingleNode (CComBSTR("./Common"), &m_spNodeCommonConfig);
	if ((hr != S_OK) || !m_spNodeCommonConfig)
		return E_FAIL;

	// get user picture folder
	if (m_spNodeUserPicturesPath)
		m_spNodeUserPicturesPath.Release();
	hr = m_spNodeCommonConfig->selectSingleNode (CComBSTR("./UserPicturesPath"), &m_spNodeUserPicturesPath);
	if ((hr != S_OK) || !m_spNodeUserPicturesPath)
		return E_FAIL;

	VARIANT_BOOL bHasChild = VARIANT_FALSE;
	m_spNodeUserPicturesPath->hasChildNodes (&bHasChild);
	if (m_spNodeUserPicturesPathValue)
		m_spNodeUserPicturesPathValue.Release();
	if (bHasChild)
		m_spNodeUserPicturesPath->get_firstChild (&m_spNodeUserPicturesPathValue);

	// get picture list
	if (m_spNodeListPicturesPath)
		m_spNodeListPicturesPath.Release();
	hr = m_spNodeCommonConfig->selectSingleNode (CComBSTR("./Pictures"), &m_spNodeListPicturesPath);
	if ((hr != S_OK) || !m_spNodeListPicturesPath)
		return E_FAIL;

	initializeListPicturesPath ();

	m_bLoaded = true;
	return S_OK;
}
Example #22
0
std::string getStringFromResource(UINT resourceID)
{
	CAtlString s;
	s.LoadString(resourceID);
	return std::string(s);
}
   // typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

   CAtlString str;
   str = _T("\t\t   ****Soccer is best!");

   _tprintf_s(_T("Before: \"%s\"\n"), (LPCTSTR)str);
   _tprintf_s(_T("After: \"%s\"\n"), (LPCTSTR)str.TrimLeft(_T("\t *")));
   
   // Output:
   // --------------------------
   // Before:		****Soccer is best!
   // After: Soccer is best!
   // typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

   CAtlString str(_T("cabbage"));
   CAtlString res = str.SpanIncluding(_T("abc"));
   ASSERT(res == _T("cabba"));
   res = str.SpanIncluding(_T("xyz"));
   ASSERT(res.IsEmpty());   
Example #25
0
int rho_sysimpl_get_property(char* szPropName, VALUE* resValue)
{
	if (strcasecmp("webview_framework",szPropName) == 0)
	{
#ifdef RHODES_EMULATOR
		*resValue = rho_ruby_create_string("WEBKIT/" QTWEBKIT_VERSION_STR);
#elif defined(APP_BUILD_CAPABILITY_WEBKIT_BROWSER)
		*resValue = rho_ruby_create_string("WEBKIT");
#else
		rho::String msieVer = "IE";
		get_msie_version(msieVer);
		*resValue = rho_ruby_create_string(msieVer.c_str());
#endif
		return 1;
	}

#ifdef RHODES_EMULATOR
    if (strcasecmp("main_window_closed",szPropName) == 0) 
        {*resValue = rho_ruby_create_boolean(CMainWindow::mainWindowClosed); return 1;}
#endif

	if (strcasecmp("has_camera",szPropName) == 0) 
        {*resValue = rho_ruby_create_boolean(has_camera()); return 1;}

	if (strcasecmp("phone_number",szPropName) == 0)
        {*resValue = phone_number();return 1;}

	if (strcasecmp("ppi_x",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_x()); return 1;}

	if (strcasecmp("ppi_y",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_y()); return 1; }

	if (strcasecmp("locale",szPropName) == 0)
		{*resValue = rho_sys_get_locale(); return 1;}

	if (strcasecmp("country",szPropName) == 0)
	{
		wchar_t szCountry[20];
		int nRes = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME , szCountry, sizeof(szCountry)/sizeof(szCountry[0]));
		szCountry[2] = 0;

		*resValue = rho_ruby_create_string(convertToStringA(szCountry).c_str());
		return 1;
	}

	if (strcasecmp("device_name",szPropName) == 0)
	{
#ifdef OS_WINDOWS
		*resValue = rho_ruby_create_string("Win32");
        return 1;
#else
		HKEY hKey;
        int nRes = 0;
		if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Ident"),
			0, KEY_READ, &hKey ) != ERROR_SUCCESS)
			return nRes;

		DWORD dwType = REG_SZ;
		DWORD dwDataSize = 0;
		if ( RegQueryValueEx( hKey, _T("name"), 0, &dwType, (PBYTE)NULL, &dwDataSize ) == ERROR_SUCCESS)
        {
		    CAtlString deviceName;
		    RegQueryValueEx( hKey, _T("name"), 0, &dwType, 
                (PBYTE)deviceName.GetBuffer((dwDataSize/sizeof(TCHAR) + sizeof(TCHAR))), &dwDataSize );
            deviceName.ReleaseBuffer();

		    *resValue = rho_ruby_create_string( convertToStringA(deviceName.GetString()).c_str() );

            nRes = 1;
        }

		RegCloseKey(hKey);
		return nRes;
#endif
	}

	if (strcasecmp("os_version",szPropName) == 0)
	{
		OSVERSIONINFO osv;
		osv.dwOSVersionInfoSize = sizeof(osv);
		if (!GetVersionEx(&osv))
			return 0;
		char buf[50];
		buf[sizeof(buf) - 1] = '\0';
		snprintf(buf, sizeof(buf) - 1, "%u.%u.%u", (unsigned)osv.dwMajorVersion,
			(unsigned)osv.dwMinorVersion, (unsigned)osv.dwBuildNumber);
		*resValue = rho_ruby_create_string(&buf[0]);
		return 1;
	}

	if (strcasecmp("is_emulator",szPropName) == 0)
    {
        bool bEmulator = false;
#ifdef OS_WINDOWS
        bEmulator = true;
#else

#endif
        *resValue = rho_ruby_create_boolean(bEmulator?1:0);
        return 1;
    }

	if (strcasecmp("has_calendar",szPropName) == 0)
    {
        *resValue = rho_ruby_create_boolean(1);
        return 1;
    }

	if (strcasecmp("has_touchscreen",szPropName) == 0)
    {
        *resValue = rho_ruby_create_boolean( rho_wmsys_has_touchscreen() );
        return 1;
    }
	if (strcasecmp("screen_orientation",szPropName) == 0)
    {
        if (rho_sys_get_screen_width() <= rho_sys_get_screen_height()) 
        {
		    *resValue = rho_ruby_create_string("portrait");
	    }
	    else {
		    *resValue = rho_ruby_create_string("landscape");
	    }                                                          
        return 1;
    }

#if defined( OS_WINCE )&& !defined( OS_PLATFORM_MOTCE )
    if (strcasecmp("device_id",szPropName) == 0) 
    {
        rho::String strDeviceID = "";
        String strAppData = "RHODES_" + RHODESAPP().getAppName() + "_DEVICEID";

        BYTE rgDeviceId[20];
        DWORD cbDeviceId = sizeof(rgDeviceId);
        HRESULT hr = GetDeviceUniqueID( (PBYTE)(strAppData.c_str()),
           strAppData.length(),
           GETDEVICEUNIQUEID_V1,
           rgDeviceId,
           &cbDeviceId);

        if ( SUCCEEDED(hr) )
        {
            for(unsigned int i = 0; i < cbDeviceId; i++)
            {
                toHexString( rgDeviceId[i], strDeviceID, 16);
            }
        }

        *resValue = rho_ruby_create_string(strDeviceID.c_str());

        return 1;
    }
#endif

	if (strcasecmp("has_cell_network",szPropName) == 0) 
    {
        *resValue = rho_ruby_create_boolean( g_rho_has_cellnetwork != 0 );
        return 1;
    }

	if (strcasecmp("has_wifi_network",szPropName) == 0) 
    {
        *resValue = rho_ruby_create_boolean( g_rho_has_network != 0 );
        return 1;
    }

    return 0;
}
   // typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

   CAtlString s(_T("abcdef"));
   ASSERT(s.Right(2) == _T("ef"));   
Example #27
0
int rho_sysimpl_get_property(char* szPropName, VALUE* resValue)
{
	if (strcasecmp("has_camera",szPropName) == 0) 
        {*resValue = rho_ruby_create_boolean(has_camera()); return 1;}

	if (strcasecmp("phone_number",szPropName) == 0)
        {*resValue = phone_number();return 1;}

	if (strcasecmp("ppi_x",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_x()); return 1;}

	if (strcasecmp("ppi_y",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_y()); return 1; }

	if (strcasecmp("locale",szPropName) == 0)
		{*resValue = rho_sys_get_locale(); return 1;}

	if (strcasecmp("country",szPropName) == 0)
	{
		wchar_t szCountry[20];
		int nRes = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME , szCountry, sizeof(szCountry)/sizeof(szCountry[0]));
		szCountry[2] = 0;

		*resValue = rho_ruby_create_string(convertToStringA(szCountry).c_str());
		return 1;
	}

	if (strcasecmp("device_name",szPropName) == 0)
	{
#ifdef OS_WINDOWS
		*resValue = rho_ruby_create_string("Win32");
        return 1;
#else
		HKEY hKey;
        int nRes = 0;
		if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Ident"),
			0, KEY_READ, &hKey ) != ERROR_SUCCESS)
			return nRes;

		DWORD dwType = REG_SZ;
		DWORD dwDataSize = 0;
		if ( RegQueryValueEx( hKey, _T("name"), 0, &dwType, (PBYTE)NULL, &dwDataSize ) == ERROR_SUCCESS)
        {
		    CAtlString deviceName;
		    RegQueryValueEx( hKey, _T("name"), 0, &dwType, 
                (PBYTE)deviceName.GetBuffer((dwDataSize/sizeof(TCHAR) + sizeof(TCHAR))), &dwDataSize );
            deviceName.ReleaseBuffer();

		    *resValue = rho_ruby_create_string( convertToStringA(deviceName.GetString()).c_str() );

            nRes = 1;
        }

		RegCloseKey(hKey);
		return nRes;
#endif
	}

	if (strcasecmp("os_version",szPropName) == 0)
	{
		OSVERSIONINFO osv;
		osv.dwOSVersionInfoSize = sizeof(osv);
		if (!GetVersionEx(&osv))
			return 0;
		char buf[50];
		buf[sizeof(buf) - 1] = '\0';
		snprintf(buf, sizeof(buf) - 1, "%u.%u.%u", (unsigned)osv.dwMajorVersion,
			(unsigned)osv.dwMinorVersion, (unsigned)osv.dwBuildNumber);
		*resValue = rho_ruby_create_string(&buf[0]);
		return 1;
	}

	if (strcasecmp("is_emulator",szPropName) == 0)
    {
        bool bEmulator = false;
#ifdef OS_WINDOWS
        bEmulator = true;
#else

#endif
        *resValue = rho_ruby_create_boolean(bEmulator?1:0);
        return 1;
    }

    return 0;
}
Example #28
0
	virtual void _output_file(CAtlString& string) { _file.Write(static_cast<const TCHAR*>(string), string.GetLength()); }
   // typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

   CAtlString s(_T("abc"));

   ASSERT(s.MakeUpper() == _T("ABC"));   
   // typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

   CAtlString str1 = _T("Co-Op");
   CAtlString str2 = _T("con");

   int n;

   // Collation uses language rules, such as ignoring dashes.
   // NoCase version ignores case.
   n = str1.CollateNoCase(str2);
   ASSERT(n < 0);

   // Comparison is a strict ASCII comparison with no language rules
   // but still ignores case in NoCase version.
   n = str1.CompareNoCase(str2);
   ASSERT(n < 0);