bool GetCurrentDirectoryX(std::basic_string<Char, Traits, Alloc>& out) { Blob<Char> buf; //TCHAR* tsz = 0; DWORD dwRet = 0; bool r = false; dwRet = GetCurrentDirectoryW(static_cast<DWORD>(buf.Size()), buf.GetBuffer()); if(dwRet) { if(dwRet > static_cast<DWORD>(buf.Size())) { // It needs more space. if(buf.Alloc(dwRet+2)) { if(::GetCurrentDirectory(static_cast<DWORD>(buf.Size()), buf.GetBuffer())) { out = buf.GetBuffer(); r = true; } } } else { out = buf.GetBuffer(); r = true; } } return r; }
inline HMODULE LoadLibraryX(const Char* buffer) { Blob<wchar_t, false, BlobTraits<true, MAX_PATH> > t; t.Alloc(StringLength(buffer) + 1); t.GetWritableBuffer()[0] = 0; XLastDitchStringCopy(buffer, t.GetWritableBuffer()); return LoadLibraryW(t.GetBuffer()); }
inline int LoadStringX(HINSTANCE hInstance, UINT id, Char* buffer, int buffermax) { Blob<wchar_t, false, BlobTraits<true, 1024> > t; t.Alloc(buffermax + 1); t.GetWritableBuffer()[0] = 0; int r = LoadStringW(hInstance, id, t.GetWritableBuffer(), buffermax); XLastDitchStringCopy(t.GetBuffer(), buffer); return r; }