예제 #1
0
std::wstring strconv::utf82w(std::string str)
{
#ifdef _WIN32

	 // Calculate required buffer size
	int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
	if(count==0)
	{
		return NULL;
	}

	// Convert UNICODE->UTF8
	LPWSTR buf = new wchar_t[count];
	int result = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, (LPWSTR)buf, count);
	if(result==0)
	{
		delete [] buf;
		return NULL;
	}

	std::wstring wstr(buf);
	delete [] buf;
	return wstr;

#else
	// On Linux do multibyte->widechar conversion.
	return a2w(str);
#endif
}
예제 #2
0
char *a2utf(const char *as) 
{
	wchar_t *ws = a2w(as);
	char *ret = w2utf(ws);
	mir_free(ws);
	return ret;
}
예제 #3
0
파일: NIconv.cpp 프로젝트: 3rdexp/nui
        std::string t2utf8(LPCTSTR arg, size_t length)
        {
#ifdef _UNICODE
            return w2utf8(arg, length);
#else
            std::wstring data = a2w(arg, length);
            return w2utf8(data.c_str(), data.length());
#endif
        }
예제 #4
0
bool a2utf(const char *as, char *buff, int bufflen) 
{
	if (!as) return false;

	wchar_t *ws = a2w(as);
	if (ws) WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, bufflen, 0, 0);
	mir_free(ws);
	return true;
}
예제 #5
0
CStringW CSySkin::A2CStringW(CString in_Str)
{
	CStringW strResult;
#ifndef _UNICODE
	CA2W a2w(in_Str);
	PWCHAR pszResult = (LPWSTR)a2w;
	strResult.Format( L"%s", pszResult);
#else
	strResult = in_Str;
#endif
	return strResult;
}
	int Voice::speak(const char * txt) const
	{
		if (!spVoice)
			return 0;

		WCHAR wtxt[800];
		a2w(txt, wtxt);

		ULONG pulstream = 0;
		HRESULT hr = spVoice->Speak(wtxt, 0, &pulstream);

		return hr == S_OK;
	}
예제 #7
0
    virtual HRESULT STDMETHODCALLTYPE MoveNext(BOOL* hasCurrentFile)
    {
        OutputDebugString("fontfile_enumerator::MoveNext");
        if(hasCurrentFile == nullptr) {
            return E_INVALIDARG;
        }

        iunknown_release(curfile);
        *hasCurrentFile = FALSE;
        if (curiter != fontpaths.end()) {
            HRESULT result = factory_->CreateFontFileReference(a2w(*curiter).c_str(), nullptr, &curfile);
            if (SUCCEEDED(result)) {
                *hasCurrentFile = TRUE;
            }
            ++curiter;
        }
        return S_OK;
    }
예제 #8
0
RS232_LIB unsigned int
rs232_open(struct rs232_port_t *p)
{
	wchar_t *wname = a2w(fix_device_name(p->dev));
	struct rs232_windows_t *wx = p->pt;

	DBG("p=%p p->pt=%p name='%s' fix='%s'\n",
	    (void *)p, p->pt, p->dev, fix_device_name(p->dev));

	if (wname == NULL)
		return RS232_ERR_UNKNOWN;

	wx->fd = CreateFile(wname, GENERIC_READ | GENERIC_WRITE,
			    FILE_SHARE_READ | FILE_SHARE_WRITE,
			    NULL, OPEN_EXISTING, 0, NULL);

	if (wname)
		free(wname);

	if (wx->fd == INVALID_HANDLE_VALUE) {
		DBG("CreateFile() %s\n", last_error());
		return RS232_ERR_OPEN;
	}

	p->status = RS232_PORT_OPEN;
	rs232_flush(p);

	GET_PORT_STATE(wx->fd, &wx->old_dcb);
	GET_PORT_TIMEOUTS(wx->fd, &wx->old_tm);

	port_timeout(p, wx->r_timeout, wx->w_timeout);
	port_buffers(p, wx->r_buffer, wx->w_buffer);

	rs232_set_baud(p, p->baud);
	rs232_set_data(p, p->data);
	rs232_set_parity(p, p->parity);
	rs232_set_stop(p, p->stop);
	rs232_set_flow(p, p->flow);

	return RS232_ERR_NOERROR;
}
예제 #9
0
CUniString FormatResult(result_t r)
{
	switch (RESULT_TYPE(r))
	{
		case RESULT_TYPE_ERRNO:
		{
			CUniString str;
#ifdef _MSC_VER
			_wcserror_s(str.GetBuffer(1024), 1024, RESULT_CODE(r));
#else
			CAnsiString strTemp;
			str=a2w(strerror_r(RESULT_CODE(r), strTemp.GetBuffer(1024), 1024));
#endif
			str=StringReplace(str, L"\r\n", L"", false);
			str=StringReplace(str, L"\n", L"", false);
		}

		case RESULT_TYPE_GENERIC:
		{
			switch (r)
			{
				case s_ok: return L"No error";
				case e_notimpl:	return L"Not implemented";
				case e_fail: return L"Unspecified error";
				case e_invalidarg: return L"Invalid argument";
				case e_accessdenied: return L"Access denied";
				case e_outofmemory: return L"Out of memory";
				case e_fileformat: return L"File format is incorrect or corrupt";
				case e_eof: return L"File format is incorrect or corrupt (unexpected eof)";
			}
		}

	}

	return Format(L"Unknown error: 0x%.8x", r);

}
예제 #10
0
WideString const CSgmlEl::GetChrParam(const wchar_t* par) const {
  char const * val = GetChrParam(w2a(par).c_str());
  return a2w(val);
}
예제 #11
0
파일: runner.cpp 프로젝트: rotanov/Spawner
void runner::create_process() {
    //WaitForSingleObject(init_semaphore, INFINITE);

    if (process_status == process_spawner_crash) {
        ReleaseSemaphore(init_semaphore, 10, NULL);
        return;
    }
    ZeroMemory(&si, sizeof(si));

    si.cb = sizeof(si);
    {//if (!options.delegated) {//#TODO fix this
        si.dwFlags = STARTF_USESTDHANDLES;
        if (pipes.find(STD_OUTPUT_PIPE) != pipes.end())
            si.hStdOutput = pipes[STD_OUTPUT_PIPE]->get_pipe();
        if (pipes.find(STD_ERROR_PIPE) != pipes.end())
            si.hStdError = pipes[STD_ERROR_PIPE]->get_pipe();
        if (pipes.find(STD_INPUT_PIPE) != pipes.end())
            si.hStdInput = pipes[STD_INPUT_PIPE]->get_pipe();
    }
    si.lpDesktop = "";
    process_creation_flags = PROCESS_CREATION_FLAGS;

    if (options.hide_gui)
    {
        si.dwFlags |= STARTF_USESHOWWINDOW;
        si.wShowWindow = SW_HIDE;
    }
    if (options.silent_errors) {
        SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
    }
    if (options.debug) {
        process_creation_flags |= DEBUG_PROCESS;
    }

    // Extracting program name and generating cmd line
    char *cmd;
    report.working_directory = options.working_directory;
    const char *wd = (options.working_directory != "")?options.working_directory.c_str():NULL;
    if (!wd)
    {
        char working_directory[MAX_PATH + 1];
        if (GetCurrentDirectoryA(MAX_PATH, working_directory))//error here is not critical
            report.working_directory = working_directory;
    }
    std::string run_program = program;

    std::string command_line;
    size_t  index_win = run_program.find_last_of('\\'),
        index_nix = run_program.find_last_of('/');

    if (index_win != std::string::npos) {
        command_line = run_program.substr(index_win + 1);
    } else if (index_nix != std::string::npos) {
        command_line = run_program.substr(index_nix + 1);
    } else {
        command_line = run_program;
    }

    command_line = command_line + " ";
    if (options.string_arguments == "") {
        command_line += options.get_arguments();
    } else {
        command_line += options.string_arguments;
    }
    cmd = new char [command_line.size()+1];
    strcpy(cmd, command_line.c_str());

    bool withLogon = options.login != "";

    if (withLogon) {
        report.login = a2w(options.login.c_str());
    } else {
        //IMPORTANT: if logon option selected & failed signalize it
        DWORD len = MAX_USER_NAME;
        wchar_t user_name[MAX_USER_NAME];
        if (GetUserNameW(user_name, &len)) {//error here is not critical
            report.login = user_name;
        }
    }

    running = withLogon ? init_process_with_logon(cmd, wd) : init_process(cmd, wd);

    ReleaseSemaphore(init_semaphore, 10, NULL);

    delete[] cmd;
}
예제 #12
0
파일: runner.cpp 프로젝트: rotanov/Spawner
bool runner::init_process_with_logon(char *cmd, const char *wd) {
    WaitForSingleObject(main_job_object_access_mutex, infinite);
    set_allow_breakaway(false);

    STARTUPINFOW siw;
    //USES_CONVERSION;
    ZeroMemory(&siw, sizeof(siw));
    siw.cb = sizeof(si);
    siw.dwFlags = si.dwFlags;
    siw.hStdInput = si.hStdInput;
    siw.hStdOutput = si.hStdOutput;
    siw.hStdError = si.hStdError;
    siw.wShowWindow = si.wShowWindow;
    siw.lpDesktop = NULL;//L"";
    std::string run_program = program + " " + options.get_arguments();

    wchar_t *login = a2w(options.login.c_str());
    wchar_t *password = a2w(options.password.c_str());
    wchar_t *wprogram = a2w(run_program.c_str());
    wchar_t *wcmd = a2w(cmd);
    wchar_t *wwd = a2w(wd);

    DWORD creation_flags = CREATE_SUSPENDED | CREATE_SEPARATE_WOW_VDM | CREATE_NO_WINDOW;

    HANDLE token = NULL;

    auto original = set_environment_for_process();

    if ( !CreateProcessWithLogonW(login, NULL, password, 0,
        wprogram, wcmd, creation_flags,
        NULL, wwd, &siw, &process_info) )
    {
        if (!options.use_cmd || !CreateProcessWithLogonW(login, NULL, password, 0,
            NULL, wcmd, creation_flags,
            NULL, wwd, &siw, &process_info) )
        {
            ReleaseMutex(main_job_object_access_mutex);
            PANIC("CreateProcess: \"" + run_program + "\", " + get_win_last_error_string());
            // TODO: cleanup below is useless now since we're in panic
            delete[] login;
            delete[] password;
            delete[] wprogram;
            delete[] wcmd;
            delete[] wwd;
            restore_original_environment(original);

            return false;
        }
    }

    set_allow_breakaway(true);
    ReleaseMutex(main_job_object_access_mutex);
    delete[] login;
    delete[] password;
    delete[] wprogram;
    delete[] wcmd;
    delete[] wwd;
    restore_original_environment(original);

    get_times(&creation_time, NULL, NULL, NULL);

    return true;
}
예제 #13
0
std::string strconv::a2utf8(std::string str)
{
	return w2utf8(a2w(str));
}
예제 #14
0
bool
EnsureAvailableTextEncoding(wxFontEncoding *enc, wxString *text, bool mayAskUser)
{
   CHECK( enc, false, _T("CheckEncodingAvailability: NULL encoding") );

   if ( !wxFontMapper::Get()->IsEncodingAvailable(*enc) )
   {
      // try to find another encoding
      wxFontEncoding encAlt;
      if ( wxFontMapper::Get()->
            GetAltForEncoding(*enc, &encAlt, wxEmptyString, mayAskUser) )
      {
         // translate the text (if any) to the equivalent encoding
         if ( text && !text->empty() )
         {
#if wxUSE_WCHAR_T
            // try converting via Unicode
            wxCSConv a2w(*enc);
            wxWCharBuffer wbuf(a2w.cMB2WC(text->c_str()));
            if ( *wbuf )
            {
               wxString textConv;

               // special case of UTF-8 which is used all the time under wxGTK
               if ( encAlt == wxFONTENCODING_UTF8 )
               {
                  textConv = wxConvUTF8.cWC2MB(wbuf);
               }
               else // all the other encodings, use generic converter
               {
                  wxCSConv w2a(encAlt);
                  textConv = w2a.cWC2MB(wbuf);
               }

               if ( !textConv.empty() )
               {
                  *text = textConv;
                  return true;
               }
               //else: fall back to wxEncodingConverter
            }
            //else: conversion to Unicode failed
#endif // wxUSE_WCHAR_T

            wxEncodingConverter conv;
            if ( !conv.Init(*enc, encAlt) )
            {
               // failed to convert the text
               return false;
            }

            *text = conv.Convert(*text);
         }
         //else: just return the encoding

         *enc = encAlt;
      }
      else // no equivalent encoding
      {
         return false;
      }
   }

   // we have either the requested encoding or an equivalent one
   return true;
}
예제 #15
0
bool a2t(const char *as, TCHAR *buff, int bufflen) 
{
	return a2w(as, buff, bufflen);
}
예제 #16
0
TCHAR *a2t(const char *as) 
{
	return a2w(as);
}