예제 #1
0
HWND WINAPI CreateWindowExCenterA(ULONG dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, ULONG dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
    HWND    Window;
    RECT    rcWordArea;
    ULONG   Length;
    PWSTR   pszClassName, pszWindowName;

    Length = StrLengthA(lpClassName) + 1;
    pszClassName = (PWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(pszClassName, Length, lpClassName, Length);

    Length = StrLengthA(lpWindowName) + 1;
    pszWindowName = (PWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(pszWindowName, Length, lpWindowName, Length);

    if (SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWordArea, 0))
    {
        X = ((rcWordArea.right - rcWordArea.left) - nWidth) / 2;
        Y = ((rcWordArea.bottom - rcWordArea.top) - nHeight) / 2;
    }

    Window = CreateWindowExW(dwExStyle, pszClassName, pszWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
    ChangeMainWindowProc(Window);

    return Window;
}
예제 #2
0
파일: memshare.cpp 프로젝트: jeppeter/game
HANDLE CreateMapFile(const char* pMapFileName,int size,int create)
{
    HANDLE hMapFile=NULL;
    int ret;
#ifdef _UNICODE
    wchar_t* pMapFileW=NULL;
    int mapfilesize=0;
    ret = AnsiToUnicode((char*)pMapFileName,&pMapFileW,&mapfilesize);
    if(ret < 0)
    {
        ret = LAST_ERROR_CODE();
        goto fail;
    }
    if(create)
    {
        hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,size,pMapFileW);
    }
    else
    {
        hMapFile =  OpenFileMapping(FILE_MAP_ALL_ACCESS,FALSE,pMapFileW);
    }
#else
    if(create)
    {
        hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,size,pMapFileName);
    }
    else
    {
        hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS,FALSE,pMapFileName);
    }
#endif

    if(hMapFile == NULL)
    {
        ret = LAST_ERROR_CODE();
        goto fail;
    }

#ifdef _UNICODE
    AnsiToUnicode(NULL,&pMapFileW,&mapfilesize);
#endif

    return hMapFile;
fail:
    if(hMapFile)
    {
        CloseHandle(hMapFile);
    }
    hMapFile = NULL;
#ifdef _UNICODE
    AnsiToUnicode(NULL,&pMapFileW,&mapfilesize);
#endif
    SetLastError(ret);
    return NULL;
}
예제 #3
0
DWORD ChildProcess::ListenerThread()
{
	// wait for someone to connect to the pipe
	if (ConnectNamedPipe(hPipe_, NULL) || GetLastError() == ERROR_PIPE_CONNECTED)
	{
		// Acquire the lock while writing to processOutput_
		char buffer[1024];
		DWORD dwRead;
		while (ReadFile(hPipe_, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE)
		{
			if (dwRead > 0)
			{
				CSingleLock locker(&outputLock_);
				buffer[dwRead] = 0;
				OutputDebugStringA(buffer);
				processOutput_ += AnsiToUnicode(buffer);
			}
			SetEvent(hOutputAvailable_);
		}
	}
	else
	{
		OutputDebugString(L"Connect failed.\n");
	}

	DisconnectNamedPipe(hPipe_);

	return 0;
}
예제 #4
0
파일: XMLPaser.cpp 프로젝트: F5000/spree
HRESULT XMLPaser::ND_hrOpenMemory( LPCTSTR strFile )
{
	try 
	{
		ND_TESTHR( CoInitialize(NULL) );
		ND_TESTHR( m_docPtr.CreateInstance("msxml2.domdocument") );

		// load a document
		_variant_t varOut(true); // BOOL 이 없다..
		_bstr_t bsXML(strFile);

		varOut = m_docPtr->loadXML( BSTR(bsXML) );

		if ((bool)varOut == false)
			throw(0);

		BSTR bstrItem; 
		LPOLESTR pszDataW;
		AnsiToUnicode( _T("Worksheet"), &pszDataW );
		bstrItem = SysAllocString( pszDataW );
 
		m_pNodeList = m_docPtr->getElementsByTagName( bstrItem );

		if ( FAILED( m_pNodeList->get_length( &m_lTableCount ) ) )
			throw (0);
	} 
	catch (...)
	{
		return ( E_FAIL );
	}

	return ( S_OK );
}
예제 #5
0
int MultiExPlugin::GetArchiveItem(int hArchive, int& hSearch, ArchiveItem* pItem)
{
	AnsiGuard guard;

	bool bLast = false;

	if ( hSearch == NULL )
		hSearch = m_pfnMpFindFirstFile(hArchive, "*");
	else
		bLast = !m_pfnMpFindNextFile(hSearch);

	if ( hSearch == 0 )
		return E_BROKEN;

	AnsiString strFileSize = m_pfnMpFindInfo(hSearch, "FileSize");

	pItem->nFileSize = atoi(strFileSize);

#ifdef UNICODE
	pItem->lpFileName = AnsiToUnicode(m_pfnMpFindInfo(hSearch, "FileName"));
#else
	pItem->lpFileName = StrDuplicate(m_pfnMpFindInfo(hSearch, "FileName"));
#endif

	if ( bLast )
	{
		m_pfnMpFindClose(hSearch);
		hSearch = 0;

		return E_EOF;
	}

	return E_SUCCESS;
}
예제 #6
0
// Load a file and convert to a string. If the file contains
// an embedded NUL then the resulting string will be truncated.
std::wstring LoadFileAsText(const std::wstring& fileName)
{
	std::ifstream f;
	f.open(fileName, std::ios_base::binary);
	if (!f)
		return L"";

	// Find the file length.
	f.seekg(0, std::ios_base::end);
	size_t length = (size_t)f.tellg();
	f.seekg(0, std::ios_base::beg);

	// Allocate a buffer and read the file.
	std::vector<char> data(length + 2);
	f.read(&data[0], length);
	if (!f)
		return L"";

	// Add a multi-byte null terminator.
	data[length] = 0;
	data[length+1] = 0;

	const wchar_t bom = 0xFEFF;
	if (memcmp(&bom, &data[0], sizeof(bom)) == 0)
	{
		// Assume UTF-16, strip bom, and return.
		return reinterpret_cast<const wchar_t*>(&data[sizeof(bom)]);
	}

	// If not-UTF-16 then convert from ANSI to wstring and return
	return AnsiToUnicode(&data[0]);
}
예제 #7
0
Gdiplus::Status __fastcall TTiffImage::LoadFromFile(String filn) {
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
    WCHAR *LoadBitmapFiln;
    String mes;
    Gdiplus::Status s;

    if (fbm != NULL) delete fbm;

    Page = 0;
    LoadBitmapFiln = new WCHAR[filn.Length() + 1];
    AnsiToUnicode(filn.c_str(), -1, LoadBitmapFiln);

    fbm = new Gdiplus::Bitmap(LoadBitmapFiln);
    delete[] LoadBitmapFiln;
    s = fbm->GetLastStatus();
    if (s != Gdiplus::Ok) {
        delete fbm;
        fbm = NULL;
        return s;
    }
    Filn = filn;
    UINT count = 0;
    count = fbm->GetFrameDimensionsCount();
    GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);
    fbm->GetFrameDimensionsList(pDimensionIDs, count);
    DimensionID = pDimensionIDs[0];
    NPages = fbm->GetFrameCount(&DimensionID);
    free(pDimensionIDs);

    return Gdiplus::Ok;
}
예제 #8
0
//----------------------------------------------------------------------------
void InitDW (void)
{
	cLoadString(IDS_WATSON_CRASH_MSG,WatsonCrashMessage,4095);
	AnsiToUnicode(WatsonCrashMessage,&WatsonCrashMessageUnicode);

	SetUnhandledExceptionFilter(DwExceptionFilter);
}
예제 #9
0
extern "C" __declspec(dllexport) void CreateImgKeyOld(const char* szFileExts, BOOL bDo)
{
	TSERROR4CXX("CreateImgKey, szFileExts = "<<szFileExts);
	WCHAR* szFileExtsW = AnsiToUnicode(szFileExts);
	FileAssociation::Instance()->CreateImgKeyALL(szFileExtsW, bDo);
	delete [] szFileExtsW;
}
예제 #10
0
int ObserverPlugin::ExtractItem(
		HANDLE hArchive, 
		int nIndex,
		const TCHAR* lpDestPath, 
		ExtractProcessCallbacks* pCallbacks 
		)
{
	ExtractOperationParams params;

	memset(&params, 0, sizeof(params));
	memcpy(&params.callbacks, pCallbacks, sizeof(ExtractProcessCallbacks));

#ifdef UNICODE
	const wchar_t* lpDestPathCopy = lpDestPath;
#else
	wchar_t* lpDestPathCopy = AnsiToUnicode(lpDestPath);
#endif

	params.destFilePath = lpDestPathCopy;
	params.flags = 0;
	params.item = nIndex;

	int nResult = E_BROKEN; //TO DO REAL RESULT

	if ( m_pfnExtract )
		nResult = m_pfnExtract(hArchive, params); 

#ifdef UNICODE
#else
	free(lpDestPathCopy);
#endif

	return ConvertResult(nResult);
}
예제 #11
0
HANDLE ObserverPlugin::OpenStorage(const TCHAR* lpFileName, StorageGeneralInfo* pInfo)
{

#ifdef UNICODE
	const wchar_t* lpName = lpFileName;
#else
	wchar_t* lpName = AnsiToUnicode(lpFileName);
#endif

	HANDLE hResult = NULL;

	if ( m_pfnOpenStorage )
	{
		HANDLE hArchive;
		StorageOpenParams params;

		params.FilePath = lpFileName;
		params.Password = nullptr; //oops

		if ( m_pfnOpenStorage(params, &hArchive, pInfo) == TRUE )
			hResult = hArchive;
	}

#ifdef UNICODE
#else
	free(lpName);
#endif


	return hResult;
}
예제 #12
0
HFONT WINAPI HookCreateFontA(int cHeight, int cWidth, int cEscapement, int cOrientation, int cWeight, DWORD bItalic, DWORD bUnderline, __in DWORD bStrikeOut, __in DWORD iCharSet, __in DWORD iOutPrecision, __in DWORD iClipPrecision, DWORD iQuality, DWORD iPitchAndFamily, LPCSTR pszFaceName)
{
    LOGFONTW lf;

    lf.lfHeight         = cHeight;
    lf.lfWidth          = cWidth;
    lf.lfEscapement     = cEscapement;
    lf.lfOrientation    = cOrientation;
    lf.lfWeight         = cWeight;
    lf.lfItalic         = (BYTE)bItalic;
    lf.lfUnderline      = (BYTE)bUnderline;
    lf.lfStrikeOut      = (BYTE)bStrikeOut;
    lf.lfOutPrecision   = (BYTE)iOutPrecision;
    lf.lfClipPrecision  = (BYTE)iClipPrecision;
    lf.lfQuality        = CLEARTYPE_QUALITY;
    lf.lfPitchAndFamily = (BYTE)iPitchAndFamily;

    if (iCharSet == SHIFTJIS_CHARSET && g_TextTable != NULL)
    {
        iCharSet = GB2312_CHARSET;
        CopyStruct(lf.lfFaceName, L"SIMHEI", sizeof(L"SIMHEI"));
    }
    else
    {
        AnsiToUnicode(lf.lfFaceName, countof(lf.lfFaceName), pszFaceName);
    }

    lf.lfCharSet = (BYTE)iCharSet;

    return CreateFontIndirectW(&lf);
}
예제 #13
0
bool WindowsHttpDownloader::Initialize(const char* user_agent, int timeout_sec, unsigned buf_block_size_kb, unsigned buf_block_count)
{
	if (!WinHttpCheckPlatform())
		return false;
	if (_http.session != NULL)
		return false;

	WCHAR ua[MAX_PATH] = {};
	if (user_agent)
		AnsiToUnicode(user_agent, ua);

	_http.session = WinHttpOpen(ua[0] != 0 ? ua : NULL,
		WINHTTP_ACCESS_TYPE_NO_PROXY,
		WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
	if (_http.session == NULL)
		return false;

	int timeout = timeout_sec * 1000;
	if (timeout > 100)
		WinHttpSetTimeouts(_http.session, timeout, timeout, timeout, timeout);

	for (int i = 0; i < _countof(_events); i++) {
		_events[i] = CreateEventExW(NULL, NULL,
			(i != EventBuf && i != EventDataAvailable) ? CREATE_EVENT_MANUAL_RESET : 0,
			EVENT_ALL_ACCESS);
	}
	return _buffered.Initialize(buf_block_size_kb, buf_block_count);
}
예제 #14
0
extern "C" __declspec(dllexport) void SetAssociateOld(const char* szFileExts, BOOL bDo)
{
	TSERROR4CXX("SetAssociate, bDo = "<<bDo<<", szFileExts = "<<szFileExts);
	WCHAR* szFileExtsW = AnsiToUnicode(szFileExts);
	FileAssociation::Instance()->AssociateAll(szFileExtsW, bDo, TRUE);
	FileAssociation::Instance()->Update();
	delete [] szFileExtsW;
}
예제 #15
0
extern "C" __declspec(dllexport) void RefleshIcon(char* szPath)
{
	wchar_t* pwstr_Path = AnsiToUnicode(szPath);
	::SHChangeNotify(SHCNE_UPDATEDIR|SHCNE_INTERRUPT|SHCNE_ASSOCCHANGED, SHCNF_IDLIST |SHCNF_FLUSH | SHCNF_PATH|SHCNE_ASSOCCHANGED,
								pwstr_Path,0);
	delete [] pwstr_Path;

}
예제 #16
0
bool KAppRes::LoadFontRes()
{
	bool retval = false;
	void* pBuffer = NULL;
	unsigned long dwBuffer = 0;
	TiXmlDocument xmlDoc;
	const TiXmlElement* pXmlChild = NULL;
	const TiXmlElement* pXmlItem = NULL;

	if (!GetRawDataFromRes("fonts.xml", &pBuffer, dwBuffer))
		goto clean0;

	if (!xmlDoc.LoadBuffer((char*)pBuffer, (long)dwBuffer, TIXML_ENCODING_UTF8))
		goto clean0;

	pXmlChild = xmlDoc.FirstChildElement("fonts");
	if (!pXmlChild)
		goto clean0;

	pXmlItem = pXmlChild->FirstChildElement("font");
	while (pXmlItem) 
	{
		std::string strId;
		std::wstring strFontface;
		int nFontSize = 11;
		int nUnderline = 0;
		int nBold = 0;
		int nItalic = 0;

		strId = pXmlItem->Attribute("id");
		strFontface = AnsiToUnicode(pXmlItem->Attribute("fontface"));
		pXmlItem->Attribute("fontsize", &nFontSize);
		pXmlItem->Attribute("underline", &nUnderline);
		pXmlItem->Attribute("bold", &nBold);
		pXmlItem->Attribute("italic", &nItalic);

		if (strId.length() && strFontface.length())
		{
			m_mapFontTable[strId] = CreateFont(
				strFontface,
				nFontSize,
				nBold ? TRUE : FALSE,
				nUnderline ? TRUE : FALSE,
				nItalic ? TRUE : FALSE
				);
		}

		pXmlItem = pXmlItem->NextSiblingElement("font");
	}

clean0:
	if (pBuffer)
	{
		FreeRawData(pBuffer);
	}

	return retval;
}
예제 #17
0
std::string AnsiToUtf8(const std::string& strAnsi) 
{
	std::string retval;
	std::wstring strTemp;

	strTemp = AnsiToUnicode(strAnsi);
	retval = UnicodeToUtf8(strTemp);

	return retval;
}
예제 #18
0
void uni::set(const char st_source[])
{
 	
    if (us_data) 
	{
		free(us_data);
		us_data = NULL;
	}
	AnsiToUnicode(st_source, (LPOLESTR*)&this->us_data);
	return;
}
예제 #19
0
파일: Utils.cpp 프로젝트: 03050903/MingQQ
BOOL AnsiToUtf8(const CHAR * lpszAnsi, CHAR * lpszUtf8, int nLen)
{
	WCHAR * lpszUnicode = AnsiToUnicode(lpszAnsi);
	if (NULL == lpszUnicode)
		return FALSE;

	int nRet = UnicodeToUtf8(lpszUnicode, lpszUtf8, nLen);

	delete []lpszUnicode;

	return (0 == nRet) ? FALSE : TRUE;
}
예제 #20
0
int MaPlugin::GetArchiveItem(ArchiveItem* pItem, ArcItemInfo* pInfo)
{
	oldfar::PluginPanelItem item;
	memset(&item, 0, sizeof(oldfar::PluginPanelItem)); //модули глючат и считают, что тут нули

	ArcItemInfo MaItemInfo;
	memset(&MaItemInfo, 0, sizeof(ArcItemInfo));

	int nResult = m_pfnGetArcItem(&item, &MaItemInfo);

	if ( nResult == GETARC_SUCCESS )
	{
#ifdef UNICODE
		pItem->lpFileName = AnsiToUnicode(item.FindData.cFileName);
		pItem->lpAlternateFileName = AnsiToUnicode(item.FindData.cAlternateFileName);
#else
		pItem->lpFileName = StrDuplicate(item.FindData.cFileName);
		pItem->lpAlternateFileName = StrDuplicate(item.FindData.cFileName);
#endif

		pItem->nFileSize = ((unsigned __int64)item.FindData.nFileSizeHigh << 32)+(unsigned __int64)item.FindData.nFileSizeLow;
		pItem->dwFileAttributes = item.FindData.dwFileAttributes;

		pItem->nPackSize = ((unsigned __int64)item.PackSizeHigh << 32)+(unsigned __int64)item.PackSize;
		pItem->dwCRC32 = item.CRC32;

		if ( MaItemInfo.Encrypted )
			pItem->dwFlags |= AIF_CRYPTED;

		if ( MaItemInfo.Solid )
			pItem->dwFlags |= AIF_SOLID;

		if ( pInfo )
			memcpy(pInfo, &MaItemInfo, sizeof(ArcItemInfo));

		return E_SUCCESS;
	}

	return ConvertResult (nResult);
}
예제 #21
0
	//--------------------------------------------------------------------
	char* AnsiToUtf8(const char* pSrcString)
	{
		char* pUtf8String = NULL;
		//首先把Ansi字符串转换成Unicode格式。
		wchar_t* pUnicodeString = AnsiToUnicode(pSrcString);
		if (pUnicodeString)
		{
			//再把Unicode字符串转换成Utf8格式。
			pUtf8String = UnicodeToUtf8(pUnicodeString);
			delete[] pUnicodeString;
		}
		return pUtf8String;
	}
예제 #22
0
파일: Utils.cpp 프로젝트: 03050903/MingQQ
std::wstring AnsiToUnicode(const std::string& strAnsi)
{
	std::wstring strUnicode;

	WCHAR * lpszUnicode = AnsiToUnicode(strAnsi.c_str());
	if (lpszUnicode != NULL)
	{
		strUnicode = lpszUnicode;
		delete []lpszUnicode;
	}

	return strUnicode;
}
예제 #23
0
파일: Control.cpp 프로젝트: ds-hwang/d2bs
void SetControlText(Control* pControl, const char* Text)
{
	if(ClientState() != ClientStateMenu)
		return;

	if(pControl && Text)
	{
		wchar_t* szwText = AnsiToUnicode(Text);
		if(!szwText)
			return;
		D2WIN_SetControlText(pControl, szwText);
		delete[] szwText;
	}
}
예제 #24
0
파일: GifImage.cpp 프로젝트: ybtq/FxIM
BOOL CGifImage::SaveAsFile(LPCTSTR pszFileName)
{
	if (NULL == pszFileName || NULL == m_pImage)
		return FALSE;

	LPCTSTR lpExtension = _tcsrchr(pszFileName, _T('.'));
	if (NULL == lpExtension)
		return FALSE;

#if defined(UNICODE) || defined(_UNICODE)
	CLSID clsid = GetEncoderClsidByExtension(lpExtension);
#else
	CLSID	clsid = CLSID_NULL;
	LPCWSTR pszExtensionW = AnsiToUnicode(lpExtension);
	if (pszExtensionW != NULL)
	{
		clsid = GetEncoderClsidByExtension(pszExtensionW);
		delete pszExtensionW;
	}
#endif
	
	if (CLSID_NULL == clsid)
		return FALSE;

#if defined(UNICODE) || defined(_UNICODE)
	Gdiplus::Status status = m_pImage->Save(pszFileName, &clsid, NULL);
#else
	Gdiplus::Status status = Gdiplus::GenericError;
	LPCWSTR pszFileNameW = AnsiToUnicode(pszFileName);
	if (pszFileNameW != NULL)
	{
		status = m_pImage->Save(pszFileNameW, &clsid, NULL);
		delete pszFileNameW;
	}
#endif
	return (status != Gdiplus::Ok) ? FALSE : TRUE;
}
예제 #25
0
	//----------------------------------------------------------------------------------------------------
	EEFont::EEFont(const FLOAT3& _position, const EEColor& _color, char* _text)
		:
		EEQuad2D(_position),
		m_text(AnsiToUnicode(_text)),
		m_isTextDirty(true),
		m_isDynamic(true),
		m_isAdaptive(false),
		m_adaptivePos(1.f, 1.f)
	{
		InitializeFont();

		SetColor(_color);
		SetIsUseColor(true);
		SetIsUseTex(true);
	}
예제 #26
0
ULONG STDCALL ACPToUnicode(PSTR *Ansi, PSTR AnsiEnd, PWSTR *Unicode, PLONG CpIndex)
{
    ULONG_PTR Length;

    --*Ansi;

    Length = AnsiEnd - *Ansi;
    AnsiToUnicode(*Unicode, Length, *Ansi, Length, &Length);

    *Unicode    = PtrAdd(*Unicode, Length);
    *Ansi       = AnsiEnd;
    *CpIndex    = STCP_ACP;

    return 0;
}
예제 #27
0
HWND WINAPI HookCreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
    RECT    rcWordArea;
    ULONG   Length;
    LPWSTR  ClassName, WindowName;
    HWND    hWnd;

    Length = StrLengthA(lpClassName) + 1;
    ClassName = (LPWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(ClassName, Length * sizeof(WCHAR), lpClassName, Length);

    Length = StrLengthA(lpWindowName) + 1;
    WindowName = (LPWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(WindowName, Length * sizeof(WCHAR), lpWindowName, Length);

    hWnd = CreateWindowExW(dwExStyle, ClassName, WindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
    if (hWnd == NULL)
        return hWnd;

    OrigWndProc = (WNDPROC)SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR)CMVS_MainWindowProc);
    DragAcceptFiles(hWnd, TRUE);

    return hWnd;
}
예제 #28
0
파일: Utility.cpp 프로젝트: fdoray/UIforETW
// Load a file and convert to a string. If the file contains
// an embedded NUL then the resulting string will be truncated.
std::wstring LoadFileAsText(const std::wstring& fileName)
{
	if (!::PathFileExistsW(fileName.c_str()))
		return L"";

	std::ifstream f;
	f.open(fileName, std::ios_base::binary);
	if (!f)
	{
		outputPrintf(L"Failed to load file `%s` as text - f.open failed!\n", fileName.c_str());
		return L"";
	}
	// Find the file length.
	f.seekg(0, std::ios_base::end);
	const std::streamoff len_int = f.tellg();
	if (len_int == -1)
	{
		outputPrintf(L"Failed to load file `%s` as text - f.tellg failed!\n", fileName.c_str());
		return L"";
	}
	const size_t length = static_cast<size_t>(len_int);
	f.seekg(0, std::ios_base::beg);

	// Allocate a buffer and read the file.
	std::vector<char> data(length + 2);
	f.read(&data[0], length);
	if (!f)
	{
		outputPrintf(L"Failed to load file `%s` as text - f.read failed!\n", fileName.c_str());
		return L"";
	}

	// Add a multi-byte null terminator.
	data[length] = 0;
	data[length+1] = 0;

	const wchar_t bom = 0xFEFF;
	UIETWASSERT(data.size() > sizeof(bom));
	if (memcmp(&bom, &data[0], sizeof(bom)) == 0)
	{
		// Assume UTF-16, strip bom, and return.
		return reinterpret_cast<const wchar_t*>(&data[sizeof(bom)]);
	}

	// If not-UTF-16 then convert from ANSI to wstring and return
	return AnsiToUnicode(&data[0]);
}
예제 #29
0
파일: D2Helpers.cpp 프로젝트: ds-hwang/d2bs
// TODO: make this use SIZE for clarity
POINT CalculateTextLen(const char* szwText, INT Font)
{
	POINT ret = {0,0};

	if(!szwText)
		return ret;

	wchar_t* Buffer = AnsiToUnicode(szwText);

	DWORD dwWidth, dwFileNo;
	DWORD dwOldSize = D2WIN_SetTextSize(Font);
	ret.y = D2WIN_GetTextWidthFileNo(Buffer, &dwWidth, &dwFileNo);
	ret.x = dwWidth;
	D2WIN_SetTextSize(dwOldSize);

	delete[] Buffer;
	return ret;
}
예제 #30
0
void TCPServer::handleAccept(
	PSocketContext pSocketContext, 
	PIOContext pIOContext)
{
	setsockopt(pIOContext->fd, SOL_SOCKET, 
		SO_UPDATE_ACCEPT_CONTEXT, 
		(char*)&pSocketContext->fd, sizeof(SOCKET));

	sockaddr_in* clientAddr = nullptr;
	sockaddr_in* localAddr = nullptr;

	int clientLen = sizeof(sockaddr_in);
	int localLen = clientLen;  

	_fnGetAcceptExSockAddrs(
		pIOContext->overlappedBuffer.buf, 0, 
		sizeof(sockaddr_in) + 16, sizeof(sockaddr_in) + 16,
		(sockaddr**)&localAddr, &localLen, 
		(sockaddr**)&clientAddr, &clientLen);

	auto clientPort = ntohs(clientAddr->sin_port);
	auto wClientIP = AnsiToUnicode(inet_ntoa(clientAddr->sin_addr));
	LOG("创建新会话[%s-%d]", wClientIP.c_str(), clientPort);

	PSocketContext pClientSocketContext = new SocketContext();
	pClientSocketContext->fd = pIOContext->fd;
	pClientSocketContext->clientIP = wClientIP;
	pClientSocketContext->clientPort = clientPort;

	if(!bind2IOCP(pClientSocketContext)){
		delete pClientSocketContext;
		pClientSocketContext = nullptr;
		return;
	}

	// 立即投递接受数据请求
	auto client = new TCPServerSession(this, pClientSocketContext);
	client->postRecv(nullptr);
	addClients(client);

	// 立即投递下一个accept请求
	pIOContext->resetBuffer();
	postAccept(pIOContext);
}