• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ MultiByteToWideChar函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中MultiByteToWideChar函数的典型用法代码示例。如果您正苦于以下问题:C++ MultiByteToWideChar函数的具体用法?C++ MultiByteToWideChar怎么用?C++ MultiByteToWideChar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MultiByteToWideChar函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: MultiByteToWideChar

const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT codepage, int lenMbcs, int *pLenWc, int *pBytesNotProcessed)
{
    // Do not process NULL pointer
    if (!mbcs2Convert) return NULL;

    // Do not process empty strings
    if (lenMbcs == 0 || lenMbcs == -1 && mbcs2Convert[0] == 0) {
        _wideCharStr.empty();
        return _wideCharStr;
    }

    int bytesNotProcessed = 0;
    int lenWc = 0;

    // If length not specified, simply convert without checking
    if (lenMbcs == -1)
    {
        lenWc = MultiByteToWideChar(codepage, 0, mbcs2Convert, lenMbcs, NULL, 0);
    }
    // Otherwise, test if we are cutting a multi-byte character at end of buffer
    else if(lenMbcs != -1 && codepage == CP_UTF8) // For UTF-8, we know how to test it
    {
        int indexOfLastChar = Utf8::characterStart(mbcs2Convert, lenMbcs-1); // get index of last character
        if (indexOfLastChar != 0 && !Utf8::isValid(mbcs2Convert+indexOfLastChar, lenMbcs-indexOfLastChar)) // if it is not valid we do not process it right now (unless its the only character in string, to ensure that we always progress, e.g. that bytesNotProcessed < lenMbcs)
        {
            bytesNotProcessed = lenMbcs-indexOfLastChar;
        }
        lenWc = MultiByteToWideChar(codepage, 0, mbcs2Convert, lenMbcs-bytesNotProcessed, NULL, 0);
    }
    else // For other encodings, ask system if there are any invalid characters; note that it will not correctly know if last character is cut when there are invalid characters inside the text
    {
        lenWc = MultiByteToWideChar(codepage, (lenMbcs == -1) ? 0 : MB_ERR_INVALID_CHARS, mbcs2Convert, lenMbcs, NULL, 0);
        if (lenWc == 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION)
        {
            // Test without last byte
            if (lenMbcs > 1) lenWc = MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, mbcs2Convert, lenMbcs-1, NULL, 0);
            if (lenWc == 0) // don't have to check that the error is still ERROR_NO_UNICODE_TRANSLATION, since only the length parameter changed
            {
                // TODO: should warn user about incorrect loading due to invalid characters
                // We still load the file, but the system will either strip or replace invalid characters (including the last character, if cut in half)
                lenWc = MultiByteToWideChar(codepage, 0, mbcs2Convert, lenMbcs, NULL, 0);
            }
            else
            {
                // We found a valid text by removing one byte.
                bytesNotProcessed = 1;
            }
        }
    }

    if (lenWc > 0)
    {
        _wideCharStr.sizeTo(lenWc);
        MultiByteToWideChar(codepage, 0, mbcs2Convert, lenMbcs-bytesNotProcessed, _wideCharStr, lenWc);
    }
    else
        _wideCharStr.empty();

    if(pLenWc) *pLenWc = lenWc;
    if(pBytesNotProcessed) *pBytesNotProcessed = bytesNotProcessed;
    return _wideCharStr;
}
开发者ID:bruderstein,项目名称:nppscintilla,代码行数:62,代码来源:Common.cpp


示例2: ILibFileDir_GetDirFirstFile

void* ILibFileDir_GetDirFirstFile(const char* directory, /*INOUT*/ char* filename, int filenamelength, /*INOUT*/ int* filesize)
{
#if defined(WIN32) || defined(_WIN32_WCE)
	WIN32_FIND_DATA FileData;
	HANDLE* hSearch;
	char* direx;
	#if defined(_WIN32_WCE)
		wchar_t *tempChar;
		int tempCharLength;
	#endif


	hSearch = malloc(sizeof(HANDLE));
	direx = malloc(filenamelength + 5);

	if (directory[(int) strlen(directory) - 1] == '\\')
	{
		sprintf(direx,"%s*.*",directory);
	}
	else
	{
		sprintf(direx,"%s\\*.*",directory);
	}

	#if defined(_WIN32_WCE)
		tempCharLength = MultiByteToWideChar(CP_UTF8,0,direx,-1,NULL,0);
		tempChar = (wchar_t*)malloc(sizeof(wchar_t)*tempCharLength);
		MultiByteToWideChar(CP_UTF8,0,direx,-1,tempChar,tempCharLength);
		*hSearch = FindFirstFile(tempChar, &FileData);
		free(direx);
		free(tempChar);
	#else
		*hSearch = FindFirstFile(direx, &FileData);
		free(direx);
	#endif

	if (*hSearch == INVALID_HANDLE_VALUE)
	{
		free(hSearch);
		hSearch = NULL;
	}
	else
	{
		if (filename != NULL)
		{
#if defined(UNICODE)
			WideCharToMultiByte(CP_UTF8,0,(LPCWSTR)FileData.cFileName,-1,filename,filenamelength,NULL,NULL);
#else
			memcpy(filename,FileData.cFileName,1+(int)strlen(FileData.cFileName));
#endif
		}

		if (filesize != NULL)
		{
			*filesize = FileData.nFileSizeLow;
		}
	}

	return hSearch;
#else
	DIR* dirObj;
	struct dirent* dirEntry;	/* dirEntry is a pointer to static memory in the C runtime lib for readdir()*/
	struct stat _si;
	char fullPath[1024];
	
	dirObj = opendir(directory);

	if (dirObj != NULL)
	{
		dirEntry = readdir(dirObj);

		if ((dirEntry != NULL) && ((int) strlen(dirEntry->d_name) < filenamelength))
		{
			if (filename != NULL)
			{
				strcpy(filename,dirEntry->d_name);
				sprintf(fullPath, "%s%s", directory, dirEntry->d_name);

				if (filesize != NULL)
				{
					if (stat(fullPath, &_si) != -1)
					{
						if ((_si.st_mode & S_IFDIR) == S_IFDIR)
						{
							*filesize = 0;
						}
						else
						{
							*filesize = _si.st_size;
						}
					}
				}
			}
		}
	}

	return dirObj;
#endif
}
开发者ID:ebichu,项目名称:dd-wrt,代码行数:99,代码来源:FileIoAbstraction.c


示例3: wcePutFile

bool wcePutFile(const char *host_file, const char *wce_file)
{
	TCHAR tszSrcFile[MAX_PATH];
	WCHAR wszDestFile[MAX_PATH];
	BYTE  buffer[5120];
    WIN32_FIND_DATA wfd;
	HRESULT hr;
	DWORD dwAttr, dwNumRead, dwNumWritten;
	HANDLE hSrc, hDest, hFind;
	int nResult;

#ifdef UNICODE
	nResult = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
									host_file, strlen(host_file)+1,
									tszSrcFile, ARRAYSIZE(tszSrcFile));
	if(0 == nResult)
		return false;
#else
	hr = StringCchCopy(tszSrcFile, ARRAYSIZE(tszSrcFile), argv[1]);
	if(FAILED(hr))
		return false;
#endif
	nResult = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
									wce_file, strlen(wce_file)+1,
									wszDestFile, ARRAYSIZE(wszDestFile));
    if(0 == nResult)
        return false;

    hFind = FindFirstFile( tszSrcFile, &wfd);
    if (INVALID_HANDLE_VALUE == hFind) {
        _tprintf(TEXT("Host file does not exist\n"));
        return false;
    }
    FindClose( hFind);
	if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
        _tprintf( TEXT("Host file specifies a directory\n"));
        return false;
    }
	
	if (wceConnect()) {
		dwAttr = CeGetFileAttributes( wszDestFile);
		if (dwAttr & FILE_ATTRIBUTE_DIRECTORY) {
            hr = StringCchCatW(wszDestFile, ARRAYSIZE(wszDestFile), L"\\");
            if(FAILED(hr)) return false;
#ifdef UNICODE
            hr = StringCchCatW(wszDestFile, ARRAYSIZE(wszDestFile), wfd.cFileName);
            if(FAILED(hr)) return false;
#else
            nResult = MultiByteToWideChar(
                        CP_ACP,    
                        MB_PRECOMPOSED,
                        wfd.cFileName,
                        strlen(wfd.cFileName)+1,
                        wszDestFile+wcslen(wszDestFile),
                        ARRAYSIZE(wszDestFile)-wcslen(wszDestFile));
            if(0 == nResult)
            {
                return 1;
            }
#endif
		}
		hSrc = CreateFile(tszSrcFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if (INVALID_HANDLE_VALUE == hSrc) {
			_tprintf( TEXT("Unable to open host file\n"));
			return false;
		}

		hDest = CeCreateFile(wszDestFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (INVALID_HANDLE_VALUE == hDest ) {
			_tprintf( TEXT("Unable to open target WinCE file\n"));
			return false;
		}

		//copy file
		do {
			if(ReadFile(hSrc, &buffer, sizeof(buffer), &dwNumRead, NULL)) {
				if (!CeWriteFile(hDest, &buffer, dwNumRead, &dwNumWritten, NULL)) {
					_tprintf( TEXT("Error !!! Writing WinCE file\n"));
					goto FatalError;
				}
			} else {
				_tprintf( TEXT("Error !!! Reading host file\n"));
				goto FatalError;
			}
			_tprintf( TEXT("."));                                        
		} while (dwNumRead);
		//_tprintf( TEXT("\n"));

		CeCloseHandle( hDest);
		CloseHandle (hSrc);
	}
	wceDisconnect();
	return true;

FatalError:
	CeCloseHandle( hDest);
	CloseHandle (hSrc);
	wceDisconnect();
	return false;
}
开发者ID:sanyaade-mobiledev,项目名称:rhodes,代码行数:100,代码来源:detool.cpp


示例4: cli_AddEvent

struct CListEvent* cli_AddEvent(CLISTEVENT *cle)
{
	struct CListEvent* p = corecli.pfnAddEvent(cle);
	if (p == NULL)
		return NULL;

	if (p->cle.hContact != 0 && p->cle.hDbEvent != (HANDLE) 1 && !(p->cle.flags & CLEF_ONLYAFEW)) {
		MENUITEMINFO mii = { sizeof(mii) };
		mii.fMask = MIIM_DATA | MIIM_BITMAP | MIIM_ID;
		if (p->cle.pszService && 
			(!strncmp("SRMsg/ReadMessage", p->cle.pszService, SIZEOF("SRMsg/ReadMessage")) ||
			 !strncmp("GChat/DblClickEvent", p->cle.pszService, SIZEOF("GChat/DblClickEvent"))))
		{
			// dup check only for msg events
			for (int j = 0; j < GetMenuItemCount(g_CluiData.hMenuNotify); j++) {
				if (GetMenuItemInfo(g_CluiData.hMenuNotify, j, TRUE, &mii) != 0) {
					NotifyMenuItemExData *nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
					if (nmi != 0 && (HANDLE) nmi->hContact == (HANDLE) p->cle.hContact && nmi->iIcon == p->imlIconIndex)
						return p;
		}	}	}

		char *szProto = GetContactProto(p->cle.hContact);
		TCHAR *szName = pcli->pfnGetContactDisplayName(p->cle.hContact, 0);
		if (szProto && szName) {
			NotifyMenuItemExData *nmi = (struct NotifyMenuItemExData *) malloc(sizeof(struct NotifyMenuItemExData));
			if (nmi) {
				TCHAR szBuffer[128];
				TCHAR* szStatus = pcli->pfnGetStatusModeDescription(db_get_w(p->cle.hContact, szProto, "Status", ID_STATUS_OFFLINE), 0);
				TCHAR szwProto[64];
				MultiByteToWideChar(CP_ACP, 0, szProto, -1, szwProto, 64);
				szwProto[63] = 0;
				mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s: %s (%s)"), szwProto, szName, szStatus);
				szBuffer[127] = 0;
				AppendMenu(g_CluiData.hMenuNotify, MF_BYCOMMAND | MF_STRING, g_CluiData.wNextMenuID, szBuffer);
				mii.hbmpItem = HBMMENU_CALLBACK;
				nmi->hContact = p->cle.hContact;
				nmi->iIcon = p->imlIconIndex;
				nmi->hIcon = p->cle.hIcon;
				nmi->hDbEvent = p->cle.hDbEvent;
				mii.dwItemData = (ULONG_PTR) nmi;
				mii.wID = g_CluiData.wNextMenuID;
				SetMenuItemInfo(g_CluiData.hMenuNotify, g_CluiData.wNextMenuID, FALSE, &mii);
				p-> menuId = g_CluiData.wNextMenuID;
				g_CluiData.wNextMenuID++;
				if (g_CluiData.wNextMenuID > 0x7fff)
					g_CluiData.wNextMenuID = 1;
				g_CluiData.iIconNotify = p->imlIconIndex;
			}
		}
	}
	else if (p->cle.hContact != 0 && (p->cle.flags & CLEF_ONLYAFEW)) {
		g_CluiData.iIconNotify = p->imlIconIndex;
		g_CluiData.hUpdateContact = p->cle.hContact;
	}

	if (pcli->events.count > 0) {
		g_CluiData.bEventAreaEnabled = TRUE;
		if (g_CluiData.bNotifyActive == FALSE) {
			g_CluiData.bNotifyActive = TRUE;
			EventArea_HideShowNotifyFrame();
		}
	}

	CLUI__cliInvalidateRect(g_CluiData.hwndEventFrame, NULL, FALSE);
	return p;
}
开发者ID:0xmono,项目名称:miranda-ng,代码行数:66,代码来源:modern_clistevents.cpp


示例5: CreateThread


//.........这里部分代码省略.........
			   

			 CString n_tcpport;
			 n_tcpport.Format(_T("%d"),m_product_isp_auto_flash.ncomport);
			 
			  temp_isp_info.Format(_T("Port : "));
			  temp_isp_info = temp_isp_info + n_tcpport;
			  m_download_info.InsertString(m_download_info.GetCount(),temp_isp_info);

			 WritePrivateProfileStringW(_T("Data"),_T("IPPort"),n_tcpport,AutoFlashConfigPath);
			 if(is_net_device == false)
			 {
				   WritePrivateProfileStringW(_T("Data"),_T("Subnote"),_T("1"),AutoFlashConfigPath);
				   CString nsub_id;
				   nsub_id.Format(_T("%d"),m_product_isp_auto_flash.product_id);
				   WritePrivateProfileStringW(_T("Data"),_T("SubID"),nsub_id,AutoFlashConfigPath);

				   temp_isp_info.Format(_T("Device is subnote."));
				   m_download_info.InsertString(m_download_info.GetCount(),temp_isp_info);
			 }
			 else
			 {
				  WritePrivateProfileStringW(_T("Data"),_T("Subnote"),_T("0"),AutoFlashConfigPath);
				  temp_isp_info.Format(_T("Device is not a subnote."));
				  m_download_info.InsertString(m_download_info.GetCount(),temp_isp_info);
			 }
		}
		CString exe_folder;
		GetModuleFileName(NULL, exe_folder.GetBuffer(MAX_PATH), MAX_PATH);
		PathRemoveFileSpec(exe_folder.GetBuffer(MAX_PATH));
		exe_folder.ReleaseBuffer();

		CString file_name;
		MultiByteToWideChar( CP_ACP, 0, download_filename, (int)strlen((char *)download_filename)+1, file_name.GetBuffer(MAX_PATH), MAX_PATH );
		file_name.ReleaseBuffer();
		CString mypath =  exe_folder + _T("\\Database\\Firmware");
		mypath = mypath + _T("\\") + file_name;
		WritePrivateProfileStringW(_T("Data"),_T("FirmwarePath"),mypath,AutoFlashConfigPath);
		

		temp_isp_info.Format(_T("FirmwarePath = "));
		temp_isp_info = temp_isp_info + mypath;
		m_download_info.InsertString(m_download_info.GetCount(),temp_isp_info);
		m_download_info.SetTopIndex(m_download_info.GetCount()-1);

		//HANDLE Call_ISP_Application = NULL;
		//Call_ISP_Application =CreateThread(NULL,NULL,isp_thread,this,NULL, NULL);
		
		
	}
	else if(ncommand == DOWNLOAD_PERSENT)
	{

		int npersent = (int)lParam;
		CString persent_message;
		persent_message.Format(_T("File download finished %d%%"),npersent);
		//bool is_the_first = true;
		//if(!is_the_first)
		m_download_info.DeleteString(m_download_info.GetCount() - 1);

		//m_download_info.AddString(persent_message);
		m_download_info.InsertString(m_download_info.GetCount(),persent_message);
		m_download_info.SetTopIndex(m_download_info.GetCount()-1);
	}
	else if(ncommand == DOWNLOAD_FINISHED)
	{
开发者ID:bhojtemco,项目名称:T3000_Building_Automation_System,代码行数:67,代码来源:Dowmloadfile.cpp


示例6: _setmbcp

/*********************************************************************
 *		_setmbcp ([email protected])
 * @implemented
 */
int CDECL _setmbcp(int cp)
{
  int newcp;
  CPINFO cpi;
  BYTE *bytes;
  WORD chartypes[256];
  WORD *curr_type;
  char bufA[256];
  WCHAR bufW[256];
  int charcount;
  int ret;
  int i;

  TRACE("_setmbcp %d\n",cp);
  switch (cp)
  {
    case _MB_CP_ANSI:
      newcp = GetACP();
      break;
    case _MB_CP_OEM:
      newcp = GetOEMCP();
      break;
    case _MB_CP_LOCALE:
      newcp = MSVCRT___lc_codepage;
      break;
    case _MB_CP_SBCS:
      newcp = 20127;   /* ASCII */
      break;
    default:
      newcp = cp;
      break;
  }

  if (!GetCPInfo(newcp, &cpi))
  {
    ERR("Codepage %d not found\n", newcp);
    __set_errno(EINVAL);
    return -1;
  }

  /* setup the _mbctype */
  memset(_mbctype, 0, sizeof(_mbctype));

  bytes = cpi.LeadByte;
  while (bytes[0] || bytes[1])
  {
    for (i = bytes[0]; i <= bytes[1]; i++)
      _mbctype[i + 1] |= _M1;
    bytes += 2;
  }

  if (cpi.MaxCharSize > 1)
  {
    /* trail bytes not available through kernel32 but stored in a structure in msvcrt */
    struct cp_extra_info_t *cpextra = g_cpextrainfo;

    g_mbcp_is_multibyte = 1;
    while (TRUE)
    {
      if (cpextra->cp == 0 || cpextra->cp == newcp)
      {
        if (cpextra->cp == 0)
          ERR("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp);

        bytes = cpextra->TrailBytes;
        while (bytes[0] || bytes[1])
        {
          for (i = bytes[0]; i <= bytes[1]; i++)
            _mbctype[i + 1] |= _M2;
          bytes += 2;
        }
        break;
      }
      cpextra++;
    }
  }
  else
    g_mbcp_is_multibyte = 0;

  /* we can't use GetStringTypeA directly because we don't have a locale - only a code page
   */
  charcount = 0;
  for (i = 0; i < 256; i++)
    if (!(_mbctype[i + 1] & _M1))
      bufA[charcount++] = i;

  ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount);
  if (ret != charcount)
    ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());

  GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes);

  curr_type = chartypes;
  for (i = 0; i < 256; i++)
    if (!(_mbctype[i + 1] & _M1))
    {
//.........这里部分代码省略.........
开发者ID:HBelusca,项目名称:NasuTek-Odyssey,代码行数:101,代码来源:locale.c


示例7: MultiByteToWideChar

LRESULT CBacnetAlarmLog::Fresh_Alarmlog_List(WPARAM wParam,LPARAM lParam)
{
	bac_show_alarm_window = 0;
	for (int i=0;i<(int)m_alarmlog_data.size();i++)
	{
		bac_show_alarm_window = m_alarmlog_data.at(i).alarm || bac_show_alarm_window;
	}
	int Fresh_Item;
	int isFreshOne = (int)lParam;
	if(isFreshOne == REFRESH_ON_ITEM)
	{
		Fresh_Item = (int)wParam;
	}
	else
	{
		if(m_alarmlog_list.IsDataNewer((char *)&m_alarmlog_data.at(0),sizeof(Alarm_point) * BAC_ALARMLOG_COUNT))
		{
			//避免list 刷新时闪烁;在没有数据变动的情况下不刷新List;
			m_alarmlog_list.SetListData((char *)&m_alarmlog_data.at(0),sizeof(Alarm_point) * BAC_ALARMLOG_COUNT);
		}
		//else
		//{
		//	return 0;
		//}
	}


	for (int i=0;i<(int)m_alarmlog_data.size();i++)
	{
		if(isFreshOne)
		{
			i = Fresh_Item;
		}
		CString temp_item;
		CString temp_message;
		CString temp_panel;
		CString temp_time;

		if(m_alarmlog_data.at(i).alarm == 1)
		{
			temp_item.Format(_T("%d"),i+1);
			temp_panel.Format(_T("%d"),(unsigned char)m_alarmlog_data.at(i).alarm_panel);
			MultiByteToWideChar( CP_ACP, 0, (char *)m_alarmlog_data.at(i).alarm_message, (int)strlen((char *)m_alarmlog_data.at(i).alarm_message)+1, 
				temp_message.GetBuffer(MAX_PATH), MAX_PATH );
			temp_message.ReleaseBuffer();



			time_t tempalarm_time ;
			tempalarm_time = m_alarmlog_data.at(i).alarm_time;
			CTime time_alarmtime;
			time_alarmtime = tempalarm_time;
			temp_time = time_alarmtime.Format("%y/%m/%d %H:%M:%S");

		}
		else
		{
			temp_time.Empty();
			temp_panel.Empty();
			temp_message.Empty();
			temp_item.Empty();
			m_alarmlog_list.SetItemText(i,ALARMLOG_DEL,_T(""));
		}



		m_alarmlog_list.SetItemText(i,ALARMLOG_NUM,temp_item);
		m_alarmlog_list.SetItemText(i,ALARMLOG_PANEL,temp_panel);
		m_alarmlog_list.SetItemText(i,ALARMLOG_MESSAGE,temp_message);
		m_alarmlog_list.SetItemText(i,ALARMLOG_TIME,temp_time);

		if(m_alarmlog_data.at(i).alarm == 1)
		{
			if(m_alarmlog_data.at(i).ddelete == 0)
			{
				m_alarmlog_list.SetItemText(i,ALARMLOG_DEL,Yes_No[0]);
			}
			else
			{
				m_alarmlog_list.SetItemText(i,ALARMLOG_DEL,Yes_No[1]);
			}
		}
		else
		{
			m_alarmlog_list.SetItemText(i,ALARMLOG_MESSAGE,_T(""));
			m_alarmlog_list.SetItemText(i,ALARMLOG_DEL,_T(""));
		}

		if(isFreshOne)
		{
			break;
		}
	}
	

	return 0;
}
开发者ID:nmorrisii,项目名称:T3000_Building_Automation_System,代码行数:97,代码来源:BacnetAlarmLog.cpp


示例8: test_threadcp

static void test_threadcp(void)
{
    static const LCID ENGLISH  = MAKELCID(MAKELANGID(LANG_ENGLISH,  SUBLANG_ENGLISH_US),         SORT_DEFAULT);
    static const LCID HINDI    = MAKELCID(MAKELANGID(LANG_HINDI,    SUBLANG_HINDI_INDIA),        SORT_DEFAULT);
    static const LCID GEORGIAN = MAKELCID(MAKELANGID(LANG_GEORGIAN, SUBLANG_GEORGIAN_GEORGIA),   SORT_DEFAULT);
    static const LCID RUSSIAN  = MAKELCID(MAKELANGID(LANG_RUSSIAN,  SUBLANG_RUSSIAN_RUSSIA),     SORT_DEFAULT);
    static const LCID JAPANESE = MAKELCID(MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN),     SORT_DEFAULT);
    static const LCID CHINESE  = MAKELCID(MAKELANGID(LANG_CHINESE,  SUBLANG_CHINESE_SIMPLIFIED), SORT_DEFAULT);

    BOOL islead, islead_acp;
    CPINFOEXA cpi;
    UINT cp, acp;
    int  i, num;
    LCID last;
    BOOL ret;

    struct test {
        LCID lcid;
        UINT threadcp;
    } lcids[] = {
        { HINDI,    0    },
        { GEORGIAN, 0    },
        { ENGLISH,  1252 },
        { RUSSIAN,  1251 },
        { JAPANESE, 932  },
        { CHINESE,  936  }
    };

    struct test_islead_nocp {
        LCID lcid;
        BYTE testchar;
    } isleads_nocp[] = {
        { HINDI,    0x00 },
        { HINDI,    0x81 },
        { HINDI,    0xa0 },
        { HINDI,    0xe0 },

        { GEORGIAN, 0x00 },
        { GEORGIAN, 0x81 },
        { GEORGIAN, 0xa0 },
        { GEORGIAN, 0xe0 },
    };

    struct test_islead {
        LCID lcid;
        BYTE testchar;
        BOOL islead;
    } isleads[] = {
        { ENGLISH,  0x00, FALSE },
        { ENGLISH,  0x81, FALSE },
        { ENGLISH,  0xa0, FALSE },
        { ENGLISH,  0xe0, FALSE },

        { RUSSIAN,  0x00, FALSE },
        { RUSSIAN,  0x81, FALSE },
        { RUSSIAN,  0xa0, FALSE },
        { RUSSIAN,  0xe0, FALSE },

        { JAPANESE, 0x00, FALSE },
        { JAPANESE, 0x81,  TRUE },
        { JAPANESE, 0xa0, FALSE },
        { JAPANESE, 0xe0,  TRUE },

        { CHINESE,  0x00, FALSE },
        { CHINESE,  0x81,  TRUE },
        { CHINESE,  0xa0,  TRUE },
        { CHINESE,  0xe0,  TRUE },
    };

    last = GetThreadLocale();
    acp  = GetACP();

    for (i = 0; i < sizeof(lcids)/sizeof(lcids[0]); i++)
    {
        SetThreadLocale(lcids[i].lcid);

        cp = 0xdeadbeef;
        GetLocaleInfoA(lcids[i].lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (LPSTR)&cp, sizeof(cp));
        ok(cp == lcids[i].threadcp, "wrong codepage %u for lcid %04x, should be %u\n", cp, lcids[i].threadcp, cp);

        /* GetCPInfoEx/GetCPInfo - CP_ACP */
        SetLastError(0xdeadbeef);
        memset(&cpi, 0, sizeof(cpi));
        ret = GetCPInfoExA(CP_ACP, 0, &cpi);
        ok(ret, "GetCPInfoExA failed for lcid %04x, error %d\n", lcids[i].lcid, GetLastError());
        ok(cpi.CodePage == acp, "wrong codepage %u for lcid %04x, should be %u\n", cpi.CodePage, lcids[i].lcid, acp);

        /* WideCharToMultiByte - CP_ACP */
        num = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, NULL, 0, NULL, NULL);
        ok(num == 7, "ret is %d (%04x)\n", num, lcids[i].lcid);

        /* MultiByteToWideChar - CP_ACP */
        num = MultiByteToWideChar(CP_ACP, 0, "foobar", -1, NULL, 0);
        ok(num == 7, "ret is %d (%04x)\n", num, lcids[i].lcid);

        /* GetCPInfoEx/GetCPInfo - CP_THREAD_ACP */
        SetLastError(0xdeadbeef);
        memset(&cpi, 0, sizeof(cpi));
        ret = GetCPInfoExA(CP_THREAD_ACP, 0, &cpi);
        ok(ret, "GetCPInfoExA failed for lcid %04x, error %d\n", lcids[i].lcid, GetLastError());
//.........这里部分代码省略.........
开发者ID:Strongc,项目名称:reactos,代码行数:101,代码来源:codepage.c


示例9: StartServerProcess

void StartServerProcess(char  *cl, STARTUPINFOW* si, PROCESS_INFORMATION* pi)
{
	void *address;
	WCHAR dllPath[MAX_PATH];
	WCHAR WDFixed[MAX_PATH];
	WCHAR wappendage[20];
	WCHAR server_cast[14];
	WCHAR cl_cast[300];
	WCHAR kernel_cast[14];
	char *appendage = "\\nwnx-module.dll";
	char *server_name = "nwserver.exe";
	char *kernel_name = "Kernel32.dll";
	unsigned long numBytes, exitCode;
	HANDLE thandle;

	char debuggy[256];

	GetCurrentDirectoryW(sizeof(WCHAR) * MAX_PATH, dllPath);
	GetCurrentDirectoryW(sizeof(WCHAR) * MAX_PATH, WDFixed);
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, appendage, -1, wappendage, strlen(appendage) + 1);
	wcscat(dllPath, wappendage );

	
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, server_name, -1, server_cast, strlen(server_name) + 1);
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cl, -1, cl_cast, strlen(cl) + 1);
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, kernel_name, -1, kernel_cast, strlen(kernel_name) + 1);

	CreateProcessW(server_cast, cl_cast , NULL, NULL, FALSE, 
		            CREATE_SUSPENDED | CREATE_PRESERVE_CODE_AUTHZ_LEVEL, NULL, WDFixed, si, pi);

	// Get permission to write into the process's address space of a space about the length of the path/DLL name.
	address = VirtualAllocEx(pi->hProcess, NULL, sizeof(WCHAR)*wcsnlen(dllPath, MAX_PATH) + sizeof(WCHAR), 
						MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
	if(!address) {
		MessageBoxA(NULL, "Can't start server process; there was a memory access issue.  Does NWNX2 have the permissions it needs to run?", "Error", MB_TASKMODAL | MB_TOPMOST | MB_ICONERROR | MB_OK);
		return;
	}

	// Write the DLL name into the process's address space
	if(!WriteProcessMemory(pi->hProcess, address, (const void *) dllPath,  sizeof(WCHAR)*wcsnlen(dllPath, MAX_PATH) + sizeof(WCHAR), &numBytes)) {
		MessageBoxA(NULL, "Can't start server process; The write to memory failed.", "Error", MB_TASKMODAL | MB_TOPMOST | MB_ICONERROR | MB_OK);
		return;
	}

	// Force the process to load the DLL by creating a thread inside the process that calls LoadLibrary and exits.
	thandle = CreateRemoteThread(pi->hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) GetProcAddress(LoadLibraryW(kernel_cast), "LoadLibraryW"), address, 0, NULL);

	// Let's check if the thread ran ok-
	if(!GetExitCodeThread(thandle, &exitCode) || thandle == NULL) {
		MessageBoxA(NULL, "Can't start server process; The loading thread in nwserver failed to run.", "Error", MB_TASKMODAL | MB_TOPMOST | MB_ICONERROR | MB_OK);
		return;		
	}

	// 259 is still running
	while(exitCode == 259) {
		GetExitCodeThread(thandle, &exitCode);
	}

	// Let's check how LoadLibrary() exited
	if(!exitCode) {
		exitCode = GetLastError();
	// don't do this normally...
		sprintf(debuggy, "%d", exitCode);
		MessageBoxA(NULL, debuggy, "Error", MB_TASKMODAL | MB_TOPMOST | MB_ICONERROR | MB_OK);
		//MessageBoxA(NULL, "Can't start server process; nwnx-module.dll failed to load into nwserver.exe", "Error", MB_TASKMODAL | MB_TOPMOST | MB_ICONERROR | MB_OK);
		return;		
	}



	// All good to go, let's kick the football-
	if(!ResumeThread(pi->hThread)) {
		MessageBoxA(NULL, "There was a threading problem, possibly a bad handle.", "Error", MB_TASKMODAL | MB_TOPMOST | MB_ICONERROR | MB_OK);
	}

}
开发者ID:Shad000w,项目名称:NWNX2-windows,代码行数:76,代码来源:nwnserver.cpp


示例10: test_other_invalid_parameters

static void test_other_invalid_parameters(void)
{
    char c_string[] = "Hello World";
    size_t c_string_len = sizeof(c_string);
    WCHAR w_string[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
    size_t w_string_len = sizeof(w_string) / sizeof(WCHAR);
    BOOL used;
    INT len;

    /* srclen=0 => ERROR_INVALID_PARAMETER */
    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_ACP, 0, w_string, 0, c_string, c_string_len, NULL, NULL);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());

    SetLastError(0xdeadbeef);
    len = MultiByteToWideChar(CP_ACP, 0, c_string, 0, w_string, w_string_len);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());


    /* dst=NULL but dstlen not 0 => ERROR_INVALID_PARAMETER */
    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_ACP, 0, w_string, w_string_len, NULL, c_string_len, NULL, NULL);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());

    SetLastError(0xdeadbeef);
    len = MultiByteToWideChar(CP_ACP, 0, c_string, c_string_len, NULL, w_string_len);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());


    /* CP_UTF7, CP_UTF8, or CP_SYMBOL and defchar not NULL => ERROR_INVALID_PARAMETER */
    /* CP_SYMBOL's behavior here is undocumented */
    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_UTF7, 0, w_string, w_string_len, c_string, c_string_len, c_string, NULL);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());

    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_UTF8, 0, w_string, w_string_len, c_string, c_string_len, c_string, NULL);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());

    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_SYMBOL, 0, w_string, w_string_len, c_string, c_string_len, c_string, NULL);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());


    /* CP_UTF7, CP_UTF8, or CP_SYMBOL and used not NULL => ERROR_INVALID_PARAMETER */
    /* CP_SYMBOL's behavior here is undocumented */
    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_UTF7, 0, w_string, w_string_len, c_string, c_string_len, NULL, &used);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());

    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_UTF8, 0, w_string, w_string_len, c_string, c_string_len, NULL, &used);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());

    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_SYMBOL, 0, w_string, w_string_len, c_string, c_string_len, NULL, &used);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());


    /* CP_UTF7, flags not 0 and used not NULL => ERROR_INVALID_PARAMETER */
    /* (tests precedence of ERROR_INVALID_PARAMETER over ERROR_INVALID_FLAGS) */
    /* The same test with CP_SYMBOL instead of CP_UTF7 gives ERROR_INVALID_FLAGS
       instead except on Windows NT4 */
    SetLastError(0xdeadbeef);
    len = WideCharToMultiByte(CP_UTF7, 1, w_string, w_string_len, c_string, c_string_len, NULL, &used);
    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "len=%d error=%x\n", len, GetLastError());
}
开发者ID:Strongc,项目名称:reactos,代码行数:67,代码来源:codepage.c


示例11: test_utf7_decoding


//.........这里部分代码省略.........
            "+-hi", 2, output, sizeof(output) / sizeof(WCHAR) - 1,
            {'+'}, 1, 1
        },
        /* tests len=0 but no error */
        {
            "+", 1, output, sizeof(output) / sizeof(WCHAR) - 1,
            {0}, 0, 0
        },
        /* tests a single null char */
        {
            "", -1, output, sizeof(output) / sizeof(WCHAR) - 1,
            {0}, 1, 1
        },
        /* tests a buffer that runs out while not decoding a UTF-7 sequence */
        {
            "hello", -1, output, 2,
            {'h','e'}, 2, 0
        },
        /* tests a buffer that runs out in the middle of decoding a UTF-7 sequence */
        {
            "+T2BZfQ-", -1, output, 1,
            {0x4F60}, 1, 0
        }
    };

    /* test which one-byte characters remove stray + signs */
    for (i = 0; i < 256; i++)
    {
        sprintf(input, "+%c+AAA", i);

        memset(output, 0x23, sizeof(output) - sizeof(WCHAR));
        output[sizeof(output) / sizeof(WCHAR) - 1] = 0;

        len = MultiByteToWideChar(CP_UTF7, 0, input, 7, output, sizeof(output) / sizeof(WCHAR) - 1);

        if (i == '-')
        {
            /* removes the - sign */
            expected_len = 3;
            expected[0] = 0x002B;
            expected[1] = 0;
            expected[2] = 0;
        }
        else if (i <= 0x7F && base64_decoding_table[i] != -1)
        {
            /* absorbs the character into the base64 sequence */
            expected_len = 2;
            expected[0] = (base64_decoding_table[i] << 10) | 0x03E0;
            expected[1] = 0;
        }
        else
        {
            /* removes the + sign */
            expected_len = 3;
            expected[0] = i;
            expected[1] = 0;
            expected[2] = 0;
        }
        expected[expected_len] = 0x2323;

        ok(len == expected_len, "i=0x%02x: expected len=%i, got len=%i\n", i, expected_len, len);
        ok(memcmp(output, expected, (expected_len + 1) * sizeof(WCHAR)) == 0,
           "i=0x%02x: expected output=%s, got output=%s\n",
           i, wine_dbgstr_wn(expected, expected_len + 1), wine_dbgstr_wn(output, expected_len + 1));
    }
开发者ID:Strongc,项目名称:reactos,代码行数:66,代码来源:codepage.c


示例12: verify_trust

int verify_trust(const char source[], int warn_unsigned=0) {

	int nchars = MultiByteToWideChar(CP_ACP, 0, source, -1, NULL, 0);

	wchar_t* wsource = new wchar_t[nchars];
	if (wsource == NULL) {
		fprintf(stderr, "SECURITY FAILURE: out-of-memory allocating wsource\n");
		return -2;
		}

	MultiByteToWideChar(CP_ACP, 0, source, -1, wsource, nchars);

	/* code adapted from 
	 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa382384%28v=vs.85%29.aspx
	 */

    /* Initialize the WINTRUST_FILE_INFO structure. */

    WINTRUST_FILE_INFO FileData;
    memset(&FileData, 0, sizeof(FileData));
    FileData.cbStruct = sizeof(WINTRUST_FILE_INFO);
    FileData.pcwszFilePath = wsource;
    FileData.hFile = NULL;
    FileData.pgKnownSubject = NULL;

    GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
    WINTRUST_DATA WinTrustData;

    /* Initialize the WinVerifyTrust input data structure. */

    memset(&WinTrustData, 0, sizeof(WinTrustData));
    WinTrustData.cbStruct = sizeof(WinTrustData);
    WinTrustData.pPolicyCallbackData = NULL;
    WinTrustData.pSIPClientData = NULL;
    WinTrustData.dwUIChoice = WTD_UI_NONE;
    WinTrustData.fdwRevocationChecks = WTD_REVOKE_NONE; 
    WinTrustData.dwUnionChoice = WTD_CHOICE_FILE;
    WinTrustData.dwStateAction = WTD_STATEACTION_VERIFY;
    WinTrustData.hWVTStateData = NULL;
    WinTrustData.pwszURLReference = NULL;
    WinTrustData.dwUIContext = 0;
    WinTrustData.pFile = &FileData;

	int trusted = 0;

    LONG status = WinVerifyTrust( NULL, &WVTPolicyGUID, &WinTrustData);
	DWORD err;

    switch (status) {

        case ERROR_SUCCESS:
			trusted = 1;
            break;
        
        case TRUST_E_NOSIGNATURE:
            /* check the error details */
            err = GetLastError();
            if (TRUST_E_NOSIGNATURE == err ||
				TRUST_E_SUBJECT_FORM_UNKNOWN == err ||
				TRUST_E_PROVIDER_UNKNOWN == err) {
				if (warn_unsigned)
					fprintf(stderr, "SECURITY WARNING: '%s' not signed\n", source);
				trusted = -1;
            	} 
            else{
				/* unknown error verifying signature */
				fprintf(stderr, "SECURITY FAILURE: trying to verify '%s' "
						"status=0x%lx, error=0x$lx\n", source, status, err);
				trusted = -2;
				}
            break;

        case TRUST_E_EXPLICIT_DISTRUST:
        case CRYPT_E_SECURITY_SETTINGS:
			/* subject or publisher was invalidated by machine admin */
			fprintf(stderr, "SECURITY VIOLATION: '%s' is blocked by local policy\n", source);
			trusted = 0;
            break;

        case TRUST_E_SUBJECT_NOT_TRUSTED:
            /* user clicked "No" when asked to install/run. */
			fprintf(stderr, "SECURTIY VIOLATION: '%s' has untrusted signature\n", source);
			trusted = 0;
            break;

		case TRUST_E_BAD_DIGEST:
			/* tampered binary */
			fprintf(stderr, "SECURITY VIOLATION: '%s' tampered binary\n", source);
			break;

        default:
			fprintf(stderr, "SECURITY FAILURE: verifying '%s' status=0x%lx\n", source, status);
            break;
    	}

	/* cleanup */

    WinTrustData.dwStateAction = WTD_STATEACTION_CLOSE;
    WinVerifyTrust( NULL, &WVTPolicyGUID, &WinTrustData);

//.........这里部分代码省略.........
开发者ID:yann-lty,项目名称:signet,代码行数:101,代码来源:verifytrust.cpp


示例13: ThreadProc

DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor makensis
{
  TCHAR buf[1024];
  char iobuf[1024];           //i/o buffer
  STARTUPINFO si={sizeof(si),};
  SECURITY_ATTRIBUTES sa={sizeof(sa),};
  SECURITY_DESCRIPTOR sd={0,};               //security information for pipes
  PROCESS_INFORMATION pi={0,};
  HANDLE newstdout=0,read_stdout=0;         //pipe handles

  OSVERSIONINFO osv={sizeof(osv)};
  GetVersionEx(&osv);
  if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT)        //initialize security descriptor (Windows NT)
  {
    InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(&sd, true, NULL, false);
    sa.lpSecurityDescriptor = &sd;
  }
  else sa.lpSecurityDescriptor = NULL;
  sa.bInheritHandle = true;         //allow inheritable handles

  if (!CreatePipe(&read_stdout,&newstdout,&sa,0))  //create stdout pipe
  {
    ErrorMessage(_T("CreatePipe"));
    PostMessage(g_hwnd,WM_USER+1203,0,1);
    return 1;
  }

  GetStartupInfo(&si);      //set startupinfo for the spawned process
  /*
    The dwFlags member tells CreateProcess how to make the process.
    STARTF_USESTDHANDLES validates the hStd* members. STARTF_USESHOWWINDOW
    validates the wShowWindow member.
  */
  si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
  si.wShowWindow = SW_HIDE;
  si.hStdOutput = newstdout;
  si.hStdError = newstdout;     //set the new handles for the child process

  // *******************************************************************
  // If there is a command line in the config file, use it for create process

  //spawn the child process
  if (!CreateProcess(NULL,g_cmdline,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,
      NULL,tempzip_path,&si,&pi))
  {
    ErrorMessage(_T("CreateProcess"));
    wnd_printf(_T("\r\nPlease make sure the path to makensis.exe is correct."));
    CloseHandle(newstdout);
    CloseHandle(read_stdout);
    PostMessage(g_hwnd,WM_USER+1203,0,1);
    return 1;
  }
  CloseHandle(newstdout); // close this handle (duplicated in subprocess) now so we get ERROR_BROKEN_PIPE
  DWORD dwLeft = 0, dwRead = 0;
  while (ReadFile(read_stdout, iobuf+dwLeft, sizeof(iobuf)-dwLeft-1, &dwRead, NULL)) //wait for buffer, or fails with ERROR_BROKEN_PIPE when subprocess exits
  {
    dwRead += dwLeft;
    iobuf[dwRead] = '\0';
#ifdef _UNICODE
    // this tweak is to prevent LogMessage from cutting in the middle of an UTF-8 sequence
    // we print only up to the latest \n of the buffer, and keep the remaining for the next loop
    char* lastLF = strrchr(iobuf,'\n');
    if (lastLF == NULL) lastLF = iobuf+dwRead-1;
    char ch = *++lastLF;
    *lastLF = '\0';
    MultiByteToWideChar(CP_UTF8,0,iobuf,lastLF+1-iobuf,buf,COUNTOF(buf));
    wnd_printf(buf);
    *lastLF = ch;
    dwLeft = iobuf+dwRead-lastLF;
    memmove(iobuf, lastLF, dwLeft);
#else
    wnd_printf(iobuf);
#endif
  }
#ifdef _UNICODE
  // because of UTF-8 tweak, in rare case there can be some data remaining
  dwRead += dwLeft;
  iobuf[dwRead] = 0;
  MultiByteToWideChar(CP_UTF8,0,iobuf,dwRead+1,buf,COUNTOF(buf));
  wnd_printf(buf);
#endif
  CloseHandle(pi.hThread);
  CloseHandle(pi.hProcess);
  CloseHandle(read_stdout);


  wsprintf(buf,_T("(source ZIP size was %d bytes)\r\n"),g_zipfile_size);
  wnd_printf(buf);

  PostMessage(g_hwnd,WM_USER+1203,0,0);
  return 0;
}
开发者ID:kichik,项目名称:nsis-1,代码行数:93,代码来源:main.cpp


示例14: tempzip_make

int tempzip_make(HWND hwndDlg, TCHAR *fn)
{
  TCHAR buf[MAX_PATH];
  GetTempPath(MAX_PATH,buf);
  GetTempFileName(buf,_T("z2e"),GetTickCount(),tempzip_path);
  if (!CreateDirectory(tempzip_path,NULL))
  {
    GetTempPath(MAX_PATH,tempzip_path);
    _tcscat(tempzip_path,_T("\\nsi"));
    if (!CreateDirectory(tempzip_path,NULL))
    {
      tempzip_path[0]=0;
      MessageBox(hwndDlg,_T("Error creating temporary directory"),g_errcaption,MB_OK|MB_ICONSTOP);
      return 1;
    }
  }
  FILE *fp=_tfopen(fn,_T("rb"));
  if (fp)
  {
    fseek(fp,0,SEEK_END);
    g_zipfile_size=ftell(fp);
    fclose(fp);
  }
  else g_zipfile_size=0;
  unzFile f;
  f = unzOpen(fn);
  if (!f || unzGoToFirstFile(f) != UNZ_OK)
  {
    if (f) unzClose(f);
    MessageBox(hwndDlg,_T("Error opening ZIP file"),g_errcaption,MB_OK|MB_ICONSTOP);
    return 1;
  }

  int nf=0, nkb=0;
  g_extracting=1;
  do {
    char filenameA[MAX_PATH];
    unz_file_info info;

    // ZREAD uses byte size, not TCHAR length.
    unzGetCurrentFileInfo(f,&info,filenameA,sizeof(filenameA),NULL,0,NULL,0);

    // was zip created on MS-DOS/Windows?
    if ((info.version & 0xFF00) == 0)
    {
      OemToCharBuffA(filenameA, filenameA, strlen(filenameA));
    }

#ifdef _UNICODE
    TCHAR filename[MAX_PATH];
    if (MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filename, MAX_PATH) == 0)
    {
      if (f) unzClose(f);
      MessageBox(hwndDlg,_T("Error converting filename to Unicode"), g_errcaption, MB_OK|MB_ICONSTOP);
      return 1;
    }
#else
    char* filename = filenameA;
#endif

    if (filename[0] &&
        filename[_tcslen(filename)-1] != _T('\\') &&
        filename[_tcslen(filename)-1] != _T('/'))
    {
      TCHAR *pfn=filename;
      while (*pfn)
      {
        if (*pfn == _T('/')) *pfn=_T('\\');
        pfn++;
      }
      pfn=filename;
      if (pfn[1] == _T(':') && pfn[2] == _T('\\')) pfn+=3;
      while (*pfn == _T('\\')) pfn++;

      TCHAR out_filename[1024];
      lstrcpy(out_filename,tempzip_path);
      lstrcat(out_filename,_T("\\"));
      lstrcat(out_filename,pfn);
      if (_tcsstr(pfn,_T("\\")))
      {
        TCHAR buf[1024];
        lstrcpy(buf,out_filename);
        TCHAR *p=buf+_tcslen(buf);
        while (p > buf && *p != _T('\\')) p--;
        *p=0;
        if (buf[0]) doMKDir(buf);
      }

      if (unzOpenCurrentFile(f) == UNZ_OK)
      {
        SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_ADDSTRING,0,(LPARAM)pfn);
        FILE *fp;
        int l;
        fp = _tfopen(out_filename,_T("wb"));
        if (fp)
        {
          do
          {
            // Jim Park: Local buf, no need to TCHAR
            char buf[1024];
//.........这里部分代码省略.........
开发者ID:kichik,项目名称:nsis-1,代码行数:101,代码来源:main.cpp


示例15: main

extern int main(int argc, char *argv[])
{
	const char *filename_cstr = "test.aaf";

#ifndef _MSC_VER
	setlocale (LC_ALL, "en_US.UTF-8");
#endif

	if (argc >= 2)
	{
		filename_cstr = argv[1];
	}

	// convert C str to wide string
	aafWChar filename[FILENAME_MAX];
	size_t status = mbstowcs(filename, filename_cstr, sizeof(filename));
	if (status == (size_t)-1) {
		fprintf(stderr, "mbstowcs failed for \"%s\"\n", filename_cstr);
		return 1;
	}
	remove(filename_cstr);

	IAAFFile *pFile = NULL;
	int mode = 0;

	aafProductIdentification_t productID;
	aafProductVersion_t TestVersion = {1, 1, 0, 0, kAAFVersionUnknown};
	productID.companyName = (aafCharacter*)L"HSC";
	productID.productName = (aafCharacter*)L"String Tester";
	productID.productVersion = &TestVersion;
	productID.productVersionString = NULL;
	productID.productID = TestProductID;
	productID.platform = (aafCharacter*)L"Linux";

	// Create new AAF file
	check(AAFFileOpenNewModify(filename, mode, &productID, &pFile));

	// Create a simple Mob
	IAAFClassDef	*classDef = NULL;
	IAAFMob			*pMob = NULL;
	IAAFHeader		*pHeader = NULL;
	IAAFDictionary	*pDictionary = NULL;

	check(pFile->GetHeader(&pHeader));
	check(pHeader->GetDictionary(&pDictionary));
	check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &classDef));
	check(classDef->CreateInstance(IID_IAAFMob, (IUnknown **)&pMob));
	classDef->Release();

	
	check(pMob->SetMobID(TEST_MobID));

	// UTF-8 for codepoint U+1D11E (musical G Clef): 0xf0,0x9d,0x84,0x9e
	// UTF-8 for codepoint U+1D122 (musical F Clef): 0xf0,0x9d,0x84,0xa2
	// http://unicode.org/charts/PDF/U1D100.pdf 
	// http://en.wikipedia.org/wiki/UTF-8
	aafCharacter *mobname;
	const unsigned char inputStr[] = {	0xf0,0x9d,0x84,0x9e,	// U+1D11E
										0xf0,0x9d,0x84,0xa2,	// U+1D122
										0x4d, 0x6f, 0x62,		// 'M' 'o' 'b'
										0x0 };

	// Convert UTF-8 inputStr to native wchar_t representation (UTF-32 Unix, UTF-16 Windows)
	int wlen = 0, n;
#ifndef _MSC_VER
	i 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Multiply函数代码示例发布时间:2022-05-30
下一篇:
C++ MultU64x32函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap