本文整理汇总了C++中StrUni::Chars方法的典型用法代码示例。如果您正苦于以下问题:C++ StrUni::Chars方法的具体用法?C++ StrUni::Chars怎么用?C++ StrUni::Chars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StrUni
的用法示例。
在下文中一共展示了StrUni::Chars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitNew
/*----------------------------------------------------------------------------------------------
Initialize the data from the given file, or create a new empty string.
----------------------------------------------------------------------------------------------*/
void WpDa::InitNew(StrAnsi staFileName)
{
if (staFileName == "")
{
InitNewEmpty();
return;
}
Vector<StrUni> vstu;
ReadTextFromFile(staFileName, vstu);
HVO * prghvoPara = NewObj HVO[vstu.Size()];
for (int istu = 0; istu < vstu.Size(); istu++)
prghvoPara[istu] = istu + 2;
CacheVecProp(1, kflidStText_Paragraphs, prghvoPara, vstu.Size());
ITsStrFactoryPtr qtsf;
qtsf.CreateInstance(CLSID_TsStrFactory);
int enc = 100; // replace by the right number when we figure out what it is
for (istu = 0; istu < vstu.Size(); istu++)
{
StrUni stuPara = vstu[istu];
ITsStringPtr qtss;
CheckHr(qtsf->MakeStringRgch(stuPara.Chars(), stuPara.Length(), enc, &qtss));
CacheStringProp(istu + 2, kflidStTxtPara_Contents, qtss);
}
ITsPropsBldrPtr qtpb;
qtpb.CreateInstance(CLSID_TsPropsBldr);
StrUni stuNormal = L"Normal";
CheckHr(qtpb->SetStrPropValue(kspNamedStyle,stuNormal.Bstr()));
delete[] prghvoPara;
}
示例2: LoadIntoEmpty
/*----------------------------------------------------------------------------------------------
Load the data from the given file into an empty window.
----------------------------------------------------------------------------------------------*/
void WpDa::LoadIntoEmpty(StrAnsi staFileName, WpChildWnd * pwcw)
{
Assert(staFileName != "");
int ctss;
CheckHr(get_VecSize(1, kflidStText_Paragraphs, &ctss));
Assert(ctss <= 1);
Vector<StrUni> vstu;
ReadTextFromFile(staFileName, vstu);
HVO * prghvoPara = NewObj HVO[vstu.Size()];
for (int istu = 0; istu < vstu.Size(); istu++)
prghvoPara[istu] = istu + 2;
CacheVecProp(1, kflidStText_Paragraphs, prghvoPara, vstu.Size());
ITsStrFactoryPtr qtsf;
qtsf.CreateInstance(CLSID_TsStrFactory);
int enc = 100; // replace by the right number when we figure out what it is
for (istu = 0; istu < vstu.Size(); istu++)
{
StrUni stuPara = vstu[istu];
ITsStringPtr qtss;
CheckHr(qtsf->MakeStringRgch(stuPara.Chars(), stuPara.Length(), enc, &qtss));
CacheStringProp(istu + 2, kflidStTxtPara_Contents, qtss);
}
ITsPropsBldrPtr qtpb;
qtpb.CreateInstance(CLSID_TsPropsBldr);
StrUni stuNormal = L"Normal";
CheckHr(qtpb->SetStrPropValue(kspNamedStyle, stuNormal.Bstr()));
delete[] prghvoPara;
pwcw->ChangeNumberOfStrings(vstu.Size());
}
示例3: passed
void ViewTest1::TestFontName()
{
// Trying to retrieve via get_ without a previous put_
// Something to consider is if there can be a default font name in which case this
// test would not apply
SmartBstr sbstrName1;
HRESULT hr = m_qxvoTest->get_FontName(&sbstrName1);
TestHrFail(hr, "Function get_FontName failed when passed(by reference) a SmartBstr");
if (sbstrName1 != NULL)
Failure("get_FontName without initialization via put_ should have returned error");
// Sending NULL pointers to functions
// REVIEW LukeU This test is assuming that a font name of zero length is invalid
hr = m_qxvoTest->put_FontName(NULL);
if (!FAILED(hr))
Failure("Call to function: put_FontName(NULL) should have returned error unless "
"0 character font name is allowed");
hr = m_qxvoTest->get_FontName(NULL);
if (!FAILED(hr))
Failure("Call to function: get_FontName(NULL) should have returned error on NULL "
"pointer");
// "put_ing" and "get_ing" and subsequent value comparison
StrUni stuFontName = L"Garliz";
hr = m_qxvoTest->put_FontName(stuFontName.Bstr());
TestHrFail(hr, "Function put_FontName failed when passed(by value) a bstr");
CheckHr(m_qxvoTest->get_FontName(&sbstrName1));
if (wcscmp(stuFontName.Chars(), sbstrName1.Chars()))
Failure("FontName returned wrong result");
}
示例4: WriteUni
void MacroBase::WriteUni(StrUni param)
{
if (!m_outfile.is_open()) return;
// All unicode strings are first transformed into ansi strings and then written to file as
// an ansi
StrAnsi staAnsi = param.Chars();
m_outfile << staAnsi.Chars() << "_" << " ";
}
示例5: RecordError
/*----------------------------------------------------------------------------------------------
General purpose method to set up and store an error, rather than throw an exception
in the normal way.
----------------------------------------------------------------------------------------------*/
HRESULT StackDumper::RecordError(REFGUID iid, StrUni stuDescr, StrUni stuSource,
int hcidHelpId, StrUni stuHelpFile)
{
// We are going to make a new error info object.
ICreateErrorInfoPtr qcerrinfo;
IErrorInfoPtr qerrinfo;
HRESULT hr;
// If we can't get a new error object, the only documented cause is E_OUTOFMEMORY.
if (FAILED(hr = ::CreateErrorInfo(&qcerrinfo)))
{
return E_OUTOFMEMORY;
}
if (FAILED(hr = qcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID FAR*) &qerrinfo)))
{
return E_UNEXPECTED;
}
hr = qcerrinfo->SetDescription(const_cast<OLECHAR *>(stuDescr.Chars()));
if (FAILED(hr))
return hr;
hr = qcerrinfo->SetGUID(iid);
if (FAILED(hr))
return hr;
hr = qcerrinfo->SetSource(const_cast<OLECHAR *>(stuSource.Chars()));
if (FAILED(hr))
return hr;
hr = qcerrinfo->SetHelpFile(const_cast<OLECHAR *>(stuHelpFile.Chars()));
if (FAILED(hr))
return hr;
if (!hcidHelpId)
hcidHelpId = khcidNoHelpAvailable;
hr = qcerrinfo->SetHelpContext(hcidHelpId);
if (FAILED(hr))
return hr;
::SetErrorInfo(0, qerrinfo);
return hr;
}
示例6: TransFuncDump
/*----------------------------------------------------------------------------------------------
This function can be installed to translate windows exceptions into C++ internal error
exceptions. Only the main program should do this. To install, just call
_set_se_translator(TransFuncDump);.
This is of dubious value because if the error occurs inside a COM component, the Throwable
exception will not be recognized, and exception handling will just catch "..." and generate
a new stack dump. However, installing it at least achieves better stack dumps for errors
in code linked into the main program.
We could install at the start of every COM interface method, and restore upon return.
However this would be computationally expensive. Consider doing this in a particular method
if you are trying to track down a problem in that method.
We could have each module install this function on being loaded, and check whether the
error occurs in its own code, and if not call the previous error handler. But this
only works reliably if modules are never unloaded, or only in reverse order of loading,
which I don't see how to ensure.
We could also get really fancy, with some sort of central manager which knows which error
translator to use for each module. This has not seemed worthwhile to me so far.
----------------------------------------------------------------------------------------------*/
void TransFuncDump( unsigned int u, EXCEPTION_POINTERS * pExp)
{
#ifdef WIN32
HANDLE hThread;
DWORD dwCode = pExp->ExceptionRecord->ExceptionCode;
StrUni stuException = ConvertException(dwCode);
DuplicateHandle( GetCurrentProcess(), GetCurrentThread(),
GetCurrentProcess(), &hThread, 0, false, DUPLICATE_SAME_ACCESS );
StrAnsi staMsg;
staMsg.Format("Stack Dump for exception: %S (%d)", stuException.Chars(), dwCode);
StackDumper::ShowStack( hThread, *(pExp->ContextRecord), const_cast<char *>(staMsg.Chars()) );
CloseHandle( hThread );
StrUni stuMsg(staMsg.Chars());
throw ThrowableSd(E_UNEXPECTED, stuMsg.Chars(), 0, StackDumper::GetDump());
#endif
}
示例7: DisplayEmbeddedObject
/*----------------------------------------------------------------------------------------------
Insert material as appropriate to display the specified object.
This method has not yet been tested...maybe not even compiled?
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwBaseVc::DisplayEmbeddedObject(IVwEnv * pvwenv, HVO hvo)
{
BEGIN_COM_METHOD;
ChkComArgPtr(pvwenv);
// See if it is a CmPicture.
ISilDataAccessPtr qsda;
CheckHr(pvwenv->get_DataAccess(&qsda));
int clsid;
CheckHr(qsda->get_IntProp(hvo, kflidCmObject_Class, &clsid));
if (clsid != kclidCmPicture)
return S_OK; // don't know how to deal with it.
StrUni stuRootDir = DirectoryFinder::FwRootDataDir();
HVO hvoFile;
CheckHr(qsda->get_ObjectProp(hvo, kflidCmPicture_PictureFile, &hvoFile));
if (hvoFile == 0)
return S_OK;
SmartBstr sbstrFileName;
CheckHr(qsda->get_UnicodeProp(hvoFile, kflidCmFile_InternalPath, &sbstrFileName));
if (sbstrFileName.Length() == 0)
return S_OK;
StrUni stuPath;
stuPath.Format(L"%s,%s,%s", stuRootDir.Chars(), L"\\", sbstrFileName.Chars());
IPicturePtr qpic;
try
{
IStreamPtr qstrm;
FileStream::Create(stuPath, STGM_READ, &qstrm);
STATSTG stg;
CheckHr(qstrm->Stat(&stg, STATFLAG_NONAME));
LONG cbdata = (LONG)stg.cbSize.QuadPart;
CheckHr(::OleLoadPicture(qstrm, cbdata, FALSE, IID_IPicture, (LPVOID *)&qpic));
CheckHr(pvwenv->AddPicture(qpic, ktagNotAnAttr, 0, 0));
}
catch (...)
{
return S_OK; // if anything goes wrong (e.g., file not found), just give up for now.
// Todo: insert a 'file XXX not found string.
}
// Todo: also add the caption.
END_COM_METHOD(g_fact, IID_IVwViewConstructor);
}
示例8: sizeof
DEFINE_THIS_FILE
#if !WIN32
#include <netdb.h>
#include <unistd.h>
#include <sys/wait.h>
#include <time.h>
#endif
/*----------------------------------------------------------------------------------------------
Get the name of the local FieldWorks database server.
----------------------------------------------------------------------------------------------*/
const wchar * SilUtil::LocalServerName()
{
static StrUni s_stuLocalServer;
if (!s_stuLocalServer.Length())
{
#if WIN32
wchar rgchComputer[MAX_COMPUTERNAME_LENGTH + 1];
DWORD cch = MAX_COMPUTERNAME_LENGTH + 1;
::GetComputerNameW(rgchComputer, &cch);
s_stuLocalServer.Format(L"%s\\SILFW", rgchComputer);
#else
const int max_compname_len = 4096; // TODOLinix this should be set to the maximun host length name
char bufHost[max_compname_len + 1];
size_t len = sizeof(bufHost);
if(gethostname(bufHost, len) != 0)
{
hostent * host = gethostbyname(bufHost);
s_stuLocalServer = host->h_name;
s_stuLocalServer.Append("/SILFW");
}
else
{
s_stuLocalServer.Format(L"%S", bufHost);
s_stuLocalServer.Append("/SILFW");
}
#endif //WIN32
}
return s_stuLocalServer.Chars();
}
示例9: fetch
DEFINE_THIS_FILE
//:>********************************************************************************************
//:> FwGrTxtSrc
//:>********************************************************************************************
size_t FwGrTxtSrc::fetch(toffset ichMin, size_t cch, gr::utf16 * prgchwBuffer)
{
HRESULT hr;
int cchLen;
IgnoreHr(hr = (gr::GrResult)m_qts->get_Length(&cchLen));
if (FAILED(hr))
throw;
if (!m_useNFC)
{
int cchGet = min(cch, cchLen - ichMin);
IgnoreHr(hr = (gr::GrResult)m_qts->Fetch(ichMin, ichMin + cchGet, (OLECHAR*)prgchwBuffer));
if (FAILED(hr))
throw;
return cchGet;
}
else
{
int vwIchMin = GrToVwOffset(ichMin);
int len = cchLen - vwIchMin;
wchar_t* pchNfd;
StrUni stuText;
stuText.SetSize(len + 1, &pchNfd);
IgnoreHr(hr = (gr::GrResult)m_qts->Fetch(vwIchMin, vwIchMin + len, pchNfd));
if (FAILED(hr))
throw;
pchNfd[len] = '\0';
stuText.SetSize(len, &pchNfd);
StrUtil::NormalizeStrUni(stuText, UNORM_NFC);
int cchGet = min((int) cch, stuText.Length());
wcsncpy((wchar_t*) prgchwBuffer, stuText.Chars(), cchGet);
return cchGet;
}
}
示例10: CheckHrCore
/*----------------------------------------------------------------------------------------------
This method is called by CheckHr (with punk and iid null) or CheckExtHr, after confirming
that hrErr is an error HRESULT.
It first confirms that there is an error info object available. If punk and iid
are supplied, it further checks that the error info object is relevant to that object and
interface.
If a relevant error object is available, and it indicates that a programming error has
occurred, and its Description does not yet contain a stack dump, we add one if possible.
Then we ThrowHr, with a special HelpId to indicate that HandleThrowable need not generate
a new error object.
If no relevant error object is available, we generate a stack dump and treat the problem
as an internal error.
----------------------------------------------------------------------------------------------*/
void CheckHrCore(HRESULT hrErr)
{
IErrorInfoPtr qerrinfo;
::GetErrorInfo(0, &qerrinfo); // This clears the system wide error info
if (!qerrinfo)
{
// We didn't have any (relevant) error info
ThrowInternalError(hrErr);
}
SmartBstr sbstrDesc;
qerrinfo->GetDescription(&sbstrDesc);
// We have an error info object, and presume that it is relevant.
// If it indicates a programming error, and doesn't already contain a
// stack dump, try to add one.
if (hrErr == E_INVALIDARG || hrErr == E_POINTER || hrErr == E_UNEXPECTED)
{
// If so look for stack dump type info.
std::wstring strDesc = sbstrDesc;
if (!wcsstr(strDesc.c_str(), ThrowableSd::MoreSep()))
{
// no stack there, so add one
DumpStackHere("Error was detected by CheckHr here:\r\n");
StrUni stuDescNew;
stuDescNew.Format(L"%s%s%S", sbstrDesc.Chars(), ThrowableSd::MoreSep(),
StackDumper::GetDump());
sbstrDesc.Append(const_cast<OLECHAR *>(stuDescNew.Chars()));
// Now modify the error info
ICreateErrorInfoPtr qcerrinfo;
if (SUCCEEDED(qerrinfo->QueryInterface(IID_ICreateErrorInfo, (LPVOID FAR*) &qcerrinfo)))
qcerrinfo->SetDescription(sbstrDesc);
}
}
// Throw an error indicating there is already a good error object in place.
ThrowHr(hrErr, sbstrDesc.Bstr(), -1, qerrinfo);
}
示例11: Process
/*----------------------------------------------------------------------------------------------
Crawl through the database and rename/delete the given styles.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP FwDbMergeStyles::Process(DWORD hWnd)
{
BEGIN_COM_METHOD;
Assert(m_vstuOldNames.Size() == m_vstuNewNames.Size());
if (!m_hvoRoot)
return E_UNEXPECTED;
if (!m_pclsidApp)
return E_UNEXPECTED;
if (LogFile())
{
ULONG cbLog;
StrAnsi staLog;
staLog.Format("Changing style names in %S (%S)%n",
DbName().Chars(), ServerName().Chars());
LogFile()->Write(staLog.Chars(), staLog.Length(), &cbLog);
}
m_qprog->DoModeless((HWND)hWnd);
StrUni stuMsg(kstidChgStyleLabel);
m_qprog->put_Title(stuMsg.Bstr());
ResetConnection();
BeginTrans();
CreateCommand();
SetPercentComplete(0);
// We want to affect only a subset of the formatting and style information in the database,
// based on which program is currently running, since different programs may be using
// different sets of styles. This information is derived from m_hvoRoot and m_pclsidApp.
// (Unfortunately, there's no way to derive one of these values from the other one.) The
// current scheme works for Data Notebook, List Editor, TE, and LexText. Additional
// programs may introduce even more complexities.
// 1. Find all the owners of StStyle objects. This should match up to LangProject (Data
// Notebook and List Editor), Scripture (TE), or LexDb (LexText).
// 2. If an owner equals m_hvoRoot, then only those objects owned by m_hvoRoot have the
// string and paragraph formatting fixed. Except that LexText also wants to fix all the
// Text objects owned by the LangProject in addition to all the objects owned by the
// LexDb, so those have to be added to the collection of objects.
// 3. If none of the owners equals m_hvoRoot, we must be dealing with Data Notebook or List
// Editor, which share a common set of styles owned by the LangProject itself. In
// this case, we want all the objects owned by the LangProject except those owned by
// another owner of styles (or the LangProject Text objects, since those use the
// LexText styles even though they're not owned by the root object). (This isn't quite
// right if either TE or LexText does not actually own any styles yet, but we won't worry
// about this nicety.)
// 4. After creating a temp table containing just the ids of those objects of interest, we
// can then process all the relevant string formatting (via a string crawler) and
// paragraph StyleRules (later in this method)
// 5. Finally, we may need to fix the Style fields of the relevant UserViewField objects.
// These are limited by the psclsidApp argument, since the UserView objects are specific
// to specific applications. If pssclidApp indicates either Data Notebook or List
// Editor, then UserViewField objects belonging to both of those programs are fixed.
// Otherwise, only those UserViewField objects belonging to the specific program
// identified by psclsidApp are fixed.
ComBool fMoreRows;
UINT cbSpaceTaken;
ComBool fIsNull;
int hobj = 0;
int clid = 0;
bool fFixOwned = false;
int clidOwned = 0;
int hvoLangProj = 0;
Vector<int> vhvoOwners;
Vector<int> vclidOwners;
Vector<int> vhvoTexts;
StrUni stuCmd;
stuCmd.Format(L"SELECT DISTINCT c.Owner$, co.Class$ "
L"FROM CmObject c "
L"JOIN CmObject co on co.Id = c.Owner$ "
L"WHERE c.Class$ = %d",
kclidStStyle);
CheckHr(GetOleDbCommand()->ExecCommand(stuCmd.Bstr(), knSqlStmtSelectWithOneRowset));
CheckHr(GetOleDbCommand()->GetRowset(0));
CheckHr(GetOleDbCommand()->NextRow(&fMoreRows));
while (fMoreRows)
{
CheckHr(GetOleDbCommand()->GetColValue(1, reinterpret_cast <BYTE *>(&hobj),
isizeof(hobj), &cbSpaceTaken, &fIsNull, 0));
CheckHr(GetOleDbCommand()->GetColValue(2, reinterpret_cast <BYTE *>(&clid),
isizeof(clid), &cbSpaceTaken, &fIsNull, 0));
if (hobj == m_hvoRoot)
{
fFixOwned = true;
clidOwned = clid;
}
else if (clid == kclidLangProject)
{
hvoLangProj = hobj;
}
else
{
vhvoOwners.Push(hobj);
vclidOwners.Push(clid);
//.........这里部分代码省略.........
示例12: HandleThrowable
/*----------------------------------------------------------------------------------------------
// This method is called when a Throwable exception is caught at the end of a COM method,
// or (with a dummy ThrowableSd) when some other exception is caught. It transforms the info
// in the Throwable into a standard COM error report (creating an IErrorInfo and registering
// it.) It returns the HRESULT that should be returned by the COM method.
// There are several different situations which this method has to handle. The following
// comments describe the situations, and how they are indicated. Each "indication" presumes
// that the previous "indications" failed.
// 1. We called a COM method which supports IErrorInfo and already provides all the information
// we need to pass to our own caller. This is indicated by a help ID of -1.
// 2. We, or a method we called that doesn't support IErrorInfo, ran out of memory.
// We need to set up the special error object pre-created for this case. This is
// indicated by thr.Error() being E_OUTOFMEMORY.
// 3. A programming error has been caught and a stack dump generated, either in our own code
// or in the code that called us. This is indicated by finding that thr is actually
// a ThrowableSd. Make an error object, with a description that includes the stack dump.
----------------------------------------------------------------------------------------------*/
HRESULT HandleThrowable(Throwable & thr, REFGUID iid, DummyFactory * pfact)
{
StrUni stuDesc;
HRESULT hrErr = thr.Error();
HRESULT hr;
// If we already have error info, we set it again (very likely got cleared by previous
// CheckHr), and then just return the HRESULT.
if (thr.GetErrorInfo())
{
::SetErrorInfo(0, thr.GetErrorInfo());
return hrErr;
}
// We need a Unicode version of the ProgId, but we should avoid allocating memory
// since we don't yet know that we have not run out.
// Since all our progids are in simple ascii, we can do the simplest possible conversion.
// Since we hopefully have at least a little stack to work with, use _alloca.
OLECHAR * pszSrc = (OLECHAR *)_alloca((StrLen(pfact->GetProgId()) + 1) * isizeof(OLECHAR));
OLECHAR * pchw = pszSrc;
for (const TCHAR * pch = pfact->GetProgId(); *pch; pch++, pchw++)
*pchw = *pch;
*pchw = 0;
if (hrErr == E_OUTOFMEMORY)
{
// Use the pre-created error info object so we don't have to allocate now.
// It already has a description, help file path, and help context ID.
// If a further E_OUTOFMEMORY occurs calling SetGUID or SetSource, just ignore it.
s_qcerrinfoMem->SetGUID(iid);
s_qcerrinfoMem->SetSource(pszSrc);
SetErrorInfo(0, s_qerrinfoMem);
return hrErr;
}
// Otherwise we are going to make a new error info object.
// Get any message supplied by the Throwable.
StrUni stuUserMsg(thr.Message());
// See if a stack dump is available.
ThrowableSd * pthrs = dynamic_cast<ThrowableSd *>(&thr);
char * pchDump = NULL;
if (pthrs)
pchDump = const_cast<char *>(pthrs->GetDump());
else if (!stuUserMsg.Length())
{
// If we don't have any sort of nice message, treat it as an internal error.
DumpStackHere("HandleThrowable caught an error with no description");
pchDump = const_cast<char *>(StackDumper::GetDump());
}
if (pchDump)
{
// We have a stack dump.
StrUni stuModName = ModuleEntry::GetModulePathName();
// Do we already have a description? If not make one.
if (!stuUserMsg.Length())
{
// No, use a default one.
StrUni stuHrMsg = ConvertException((DWORD)hrErr);
StrUni stuUserMsgFmt;
stuUserMsgFmt.Load(kstidInternalError);
// Would it be better to strip off the path?
stuUserMsg.Format(stuUserMsgFmt, stuHrMsg.Chars(), stuModName.Chars());
}
stuDesc.Format(L"%s%s%S\r\n\r\n%s", stuUserMsg.Chars(), ThrowableSd::MoreSep(), pchDump,
GetModuleVersion(stuModName.Chars()).Chars());
}
else
{
// We've made sure we have a message already; use it.
stuDesc = stuUserMsg;
}
StrUni stuSource(pszSrc);
hr = StackDumper::RecordError(iid, stuDesc, stuSource, thr.HelpId(),
GetModuleHelpFilePath());
if (FAILED(hr))
{
if (hr == E_OUTOFMEMORY)
{
//.........这里部分代码省略.........
示例13: ThrowBuiltInError
/*----------------------------------------------------------------------------------------------
Throw an exception indicating UNEXPECTED failure of a built-in function. This should be
used only when we believe there is no reason ever to expect failure, but are checking it
just to be sure. For now treat it as an internal error.
----------------------------------------------------------------------------------------------*/
void ThrowBuiltInError(char * pchFnName)
{
StrUni stuMsg;
stuMsg.Format(L"%S unexpectedly failed", pchFnName);
ThrowInternalError(E_UNEXPECTED, stuMsg.Chars());
}
示例14: Init
/*----------------------------------------------------------------------------------------------
This method opens the given file according to the given mode settings.
NOTE: This now creates a file if it doesn't already exist, but opens it if it does exist,
if STGM_READWRITE alone is set.
NOTE: STGM_SHARE_* flags are ignored on Linux, files are always 'shared'
@param pszFile Name (or path) of the desired file
@param grfstgm Combination of flags kfstgmXxxx from enum in FileStrm.h
----------------------------------------------------------------------------------------------*/
void FileStream::Init(LPCOLESTR pszFile, int grfstgm)
{
/* TODO: To access another file this stream should be closed and another created.
*/
AssertPsz(pszFile);
Assert(*pszFile);
#if WIN32
Assert(!m_hfile);
HANDLE hfile = 0;
DWORD dwDesiredAccess = 0;
DWORD dwShareMode;
DWORD dwCreationDisposition = 0;
// Set the dwShareMode parameter.
if (grfstgm & kfstgmShareDenyNone)
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
else if (grfstgm & kfstgmShareDenyRead)
dwShareMode = FILE_SHARE_WRITE;
else if (grfstgm & kfstgmShareExclusive)
dwShareMode = 0;
else
dwShareMode = FILE_SHARE_READ;
if (grfstgm & kfstgmReadWrite)
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
else if (grfstgm & kfstgmWrite)
dwDesiredAccess = GENERIC_WRITE;
else
dwDesiredAccess = GENERIC_READ;
if (dwDesiredAccess & GENERIC_WRITE)
{
if (grfstgm & kfstgmCreate)
dwCreationDisposition = CREATE_ALWAYS;
else if (grfstgm & kfstgmReadWrite)
dwCreationDisposition = OPEN_ALWAYS; // Allows writing to existing file.
else
dwCreationDisposition = CREATE_NEW;
}
else
dwCreationDisposition = OPEN_EXISTING;
hfile = ::CreateFileW(pszFile, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hfile == INVALID_HANDLE_VALUE)
{
HRESULT hr = (HRESULT)::GetLastError();
int stid = ErrorStringId(hr);
StrUni stuRes(stid);
StrUni stuMsg;
stuMsg.Format(L"%s%n%s", stuRes.Chars(), pszFile);
ThrowHr(hr, stuMsg.Chars()); // Caller should handle. (This is not a COM method).
}
m_hfile = hfile;
m_staPath = pszFile;
m_grfstgm = grfstgm; // Store the access mode for the stat method.
#else
Assert(m_file < 0);
int file = -1;
int flags = 0;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
//std::cout << kfstgmReadWrite << ", " << kfstgmRead << ", " << kfstgmWrite << ", " << kfstgmCreate << std::endl;
//std::cout << O_RDWR << ", " << O_RDONLY << ", " << O_WRONLY << ", " << O_CREAT << std::endl;
if (grfstgm & kfstgmReadWrite) {
flags |= O_RDWR;
}
else if (grfstgm & kfstgmWrite) {
flags |= O_WRONLY;
}
else {
flags |= O_RDONLY;
}
if (grfstgm & kfstgmCreate) {
flags |= O_CREAT;
}
if (grfstgm == kfstgmReadWrite) {
flags |= O_CREAT;
}
if (flags & O_WRONLY | flags & O_RDWR)
{
if (grfstgm & kfstgmCreate)
flags |= O_TRUNC;
else if (grfstgm & kfstgmReadWrite)
flags |= O_CREAT;
else
//.........这里部分代码省略.........
示例15: ThrowHrEx
void ThrowHrEx(HRESULT hr, int hHelpId)
{
StrUni msg = ConvertException(::GetLastError());
ThrowHr(hr, msg.Chars(), hHelpId);
}