本文整理汇总了C++中SetLastError函数的典型用法代码示例。如果您正苦于以下问题:C++ SetLastError函数的具体用法?C++ SetLastError怎么用?C++ SetLastError使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetLastError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFullPathNameA
/*++
Function:
GetFullPathNameA
See MSDN doc.
--*/
DWORD
PALAPI
GetFullPathNameA(
IN LPCSTR lpFileName,
IN DWORD nBufferLength,
OUT LPSTR lpBuffer,
OUT LPSTR *lpFilePart)
{
DWORD nReqPathLen, nRet = 0;
LPSTR lpUnixPath = NULL;
BOOL fullPath = FALSE;
PERF_ENTRY(GetFullPathNameA);
ENTRY("GetFullPathNameA(lpFileName=%p (%s), nBufferLength=%u, lpBuffer=%p, "
"lpFilePart=%p)\n",
lpFileName?lpFileName:"NULL",
lpFileName?lpFileName:"NULL", nBufferLength, lpBuffer, lpFilePart);
if(NULL == lpFileName)
{
WARN("lpFileName is NULL\n");
SetLastError(ERROR_INVALID_PARAMETER);
goto done;
}
/* find out if lpFileName is a partial or full path */
if ('\\' == *lpFileName || '/' == *lpFileName)
{
fullPath = TRUE;
}
if(fullPath)
{
lpUnixPath = PAL__strdup( lpFileName );
if(NULL == lpUnixPath)
{
ERROR("strdup() failed; error is %d (%s)\n",
errno, strerror(errno));
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto done;
}
}
else
{
size_t max_len;
/* allocate memory for full non-canonical path */
max_len = strlen(lpFileName)+1; /* 1 for the slash to append */
max_len += MAX_LONGPATH + 1;
lpUnixPath = (LPSTR)PAL_malloc(max_len);
if(NULL == lpUnixPath)
{
ERROR("PAL_malloc() failed; error is %d (%s)\n",
errno, strerror(errno));
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto done;
}
/* build full path */
if(!GetCurrentDirectoryA(MAX_LONGPATH + 1, lpUnixPath))
{
/* no reason for this to fail now... */
ASSERT("GetCurrentDirectoryA() failed! lasterror is %#xd\n",
GetLastError());
SetLastError(ERROR_INTERNAL_ERROR);
goto done;
}
if (strcat_s(lpUnixPath, max_len, "/") != SAFECRT_SUCCESS)
{
ERROR("strcat_s failed!\n");
SetLastError(ERROR_FILENAME_EXCED_RANGE);
goto done;
}
if (strcat_s(lpUnixPath, max_len, lpFileName) != SAFECRT_SUCCESS)
{
ERROR("strcat_s failed!\n");
SetLastError(ERROR_FILENAME_EXCED_RANGE);
goto done;
}
}
/* do conversion to Unix path */
FILEDosToUnixPathA( lpUnixPath );
/* now we can canonicalize this */
FILECanonicalizePath(lpUnixPath);
/* at last, we can figure out how long this path is */
nReqPathLen = strlen(lpUnixPath)+1;
if(nBufferLength < nReqPathLen)
{
//.........这里部分代码省略.........
示例2: diablo_get_not_running
bool __cdecl diablo_get_not_running()
{
SetLastError(0);
CreateEventA(NULL, FALSE, FALSE, "DiabloEvent");
return GetLastError() != ERROR_ALREADY_EXISTS;
}
示例3: UnMapAndLoad
/***********************************************************************
* UnMapAndLoad ([email protected])
*/
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE LoadedImage)
{
FIXME("(%p): stub\n", LoadedImage);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
示例4: test_string_conversion
static void test_string_conversion(LPBOOL bUsedDefaultChar)
{
char mbc;
char mbs[15];
int ret;
WCHAR wc1 = 228; /* Western Windows-1252 character */
WCHAR wc2 = 1088; /* Russian Windows-1251 character not displayable for Windows-1252 */
static const WCHAR wcs[] = {'T', 'h', 1088, 'i', 0}; /* String with ASCII characters and a Russian character */
static const WCHAR dbwcs[] = {28953, 25152, 0}; /* String with Chinese (codepage 950) characters */
static const WCHAR dbwcs2[] = {0x7bb8, 0x3d, 0xc813, 0xac00, 0xb77d, 0};
static const char default_char[] = {0xa3, 0xbf, 0};
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, &wc1, 1, &mbc, 1, NULL, bUsedDefaultChar);
ok(ret == 1, "ret is %d\n", ret);
ok(mbc == '\xe4', "mbc is %d\n", mbc);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == FALSE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, &wc2, 1, &mbc, 1, NULL, bUsedDefaultChar);
ok(ret == 1, "ret is %d\n", ret);
ok(mbc == 63, "mbc is %d\n", mbc);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
if (IsValidCodePage(1251))
{
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1251, 0, &wc2, 1, &mbc, 1, NULL, bUsedDefaultChar);
ok(ret == 1, "ret is %d\n", ret);
ok(mbc == '\xf0', "mbc is %d\n", mbc);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == FALSE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef ||
broken(GetLastError() == 0), /* win95 */
"GetLastError() is %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1251, 0, &wc1, 1, &mbc, 1, NULL, bUsedDefaultChar);
ok(ret == 1, "ret is %d\n", ret);
ok(mbc == 97, "mbc is %d\n", mbc);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == FALSE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
}
else
skip("Codepage 1251 not available\n");
/* This call triggers the last Win32 error */
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, wcs, -1, &mbc, 1, NULL, bUsedDefaultChar);
ok(ret == 0, "ret is %d\n", ret);
ok(mbc == 84, "mbc is %d\n", mbc);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == FALSE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() is %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, wcs, -1, mbs, sizeof(mbs), NULL, bUsedDefaultChar);
ok(ret == 5, "ret is %d\n", ret);
ok(!strcmp(mbs, "Th?i"), "mbs is %s\n", mbs);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
mbs[0] = 0;
/* WideCharToMultiByte mustn't add any null character automatically.
So in this case, we should get the same string again, even if we only copied the first three bytes. */
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, wcs, 3, mbs, sizeof(mbs), NULL, bUsedDefaultChar);
ok(ret == 3, "ret is %d\n", ret);
ok(!strcmp(mbs, "Th?i"), "mbs is %s\n", mbs);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
ZeroMemory(mbs, 5);
/* Now this shouldn't be the case like above as we zeroed the complete string buffer. */
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, wcs, 3, mbs, sizeof(mbs), NULL, bUsedDefaultChar);
ok(ret == 3, "ret is %d\n", ret);
ok(!strcmp(mbs, "Th?"), "mbs is %s\n", mbs);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
/* Double-byte tests */
ret = WideCharToMultiByte(1252, 0, dbwcs, 3, mbs, sizeof(mbs), NULL, bUsedDefaultChar);
ok(ret == 3, "ret is %d\n", ret);
ok(!strcmp(mbs, "??"), "mbs is %s\n", mbs);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ret = WideCharToMultiByte(936, WC_COMPOSITECHECK, dbwcs2, -1, mbs, sizeof(mbs), (const char *)default_char, bUsedDefaultChar);
ok(ret == 10, "ret is %d\n", ret);
ok(!strcmp(mbs, "\xf3\xe7\x3d\xa3\xbf\xa3\xbf\xa3\xbf"), "mbs is %s\n", mbs);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
/* Length-only tests */
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, &wc2, 1, NULL, 0, NULL, bUsedDefaultChar);
ok(ret == 1, "ret is %d\n", ret);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
SetLastError(0xdeadbeef);
//.........这里部分代码省略.........
示例5: test_utf7_decoding
//.........这里部分代码省略.........
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));
}
/* test which one-byte characters terminate a sequence
* also test whether the unfinished byte pair is discarded or not */
for (i = 0; i < 256; i++)
{
sprintf(input, "+B%c+AAA", i);
memset(output, 0x23, sizeof(output) - sizeof(WCHAR));
output[sizeof(output) / sizeof(WCHAR) - 1] = 0;
len = MultiByteToWideChar(CP_UTF7, 0, input, 8, output, sizeof(output) / sizeof(WCHAR) - 1);
if (i == '-')
{
/* explicitly terminates */
expected_len = 2;
expected[0] = 0;
expected[1] = 0;
}
else if (i <= 0x7F)
{
if (base64_decoding_table[i] != -1)
{
/* absorbs the character into the base64 sequence */
expected_len = 3;
expected[0] = 0x0400 | (base64_decoding_table[i] << 4) | 0x000F;
expected[1] = 0x8000;
expected[2] = 0;
}
else
{
/* implicitly terminates and discards the unfinished byte pair */
expected_len = 3;
expected[0] = i;
expected[1] = 0;
expected[2] = 0;
}
}
else
{
/* implicitly terminates but does not the discard unfinished byte pair */
expected_len = 3;
expected[0] = i;
expected[1] = 0x0400;
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));
}
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
{
memset(output, 0x23, sizeof(output) - sizeof(WCHAR));
output[sizeof(output) / sizeof(WCHAR) - 1] = 0;
SetLastError(0xdeadbeef);
len = MultiByteToWideChar(CP_UTF7, 0, tests[i].src, tests[i].srclen,
tests[i].dst, tests[i].dstlen);
tests[i].expected_dst[tests[i].chars_written] = 0x2323;
if (!tests[i].len && tests[i].chars_written)
{
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"tests[%i]: expected error=0x%x, got error=0x%x\n",
i, ERROR_INSUFFICIENT_BUFFER, GetLastError());
}
ok(len == tests[i].len, "tests[%i]: expected len=%i, got len=%i\n", i, tests[i].len, len);
if (tests[i].dst)
{
ok(memcmp(tests[i].dst, tests[i].expected_dst, (tests[i].chars_written + 1) * sizeof(WCHAR)) == 0,
"tests[%i]: expected dst=%s, got dst=%s\n",
i, wine_dbgstr_wn(tests[i].expected_dst, tests[i].chars_written + 1),
wine_dbgstr_wn(tests[i].dst, tests[i].chars_written + 1));
}
}
}
示例6: recycle
static int recycle (const TCHAR *name)
{
DWORD dirattr = GetFileAttributesSafe (name);
bool isdir = dirattr != INVALID_FILE_ATTRIBUTES && (dirattr & FILE_ATTRIBUTE_DIRECTORY);
const TCHAR *namep;
TCHAR path[MAX_DPATH];
if (currprefs.win32_filesystem_mangle_reserved_names == false) {
_tcscpy (path, PATHPREFIX);
_tcscat (path, name);
namep = path;
} else {
namep = name;
}
if (currprefs.win32_norecyclebin || isdir || currprefs.win32_filesystem_mangle_reserved_names == false) {
if (isdir)
return RemoveDirectory (namep) ? 0 : -1;
else
return DeleteFile (namep) ? 0 : -1;
} else {
SHFILEOPSTRUCT fos;
HANDLE h;
h = CreateFile (namep, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h != INVALID_HANDLE_VALUE) {
LARGE_INTEGER size;
if (GetFileSizeEx (h, &size)) {
if (size.QuadPart == 0) {
CloseHandle (h);
return DeleteFile (namep) ? 0 : -1;
}
}
CloseHandle (h);
}
/* name must be terminated by \0\0 */
TCHAR *p = xcalloc (TCHAR, _tcslen (namep) + 2);
int v;
_tcscpy (p, namep);
memset (&fos, 0, sizeof (fos));
fos.wFunc = FO_DELETE;
fos.pFrom = p;
fos.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NORECURSION | FOF_SILENT;
v = SHFileOperation (&fos);
xfree (p);
switch (v)
{
case 0xb7: //DE_ERROR_MAX
case 0x7c: //DE_INVALIDFILES
case 0x402: // "unknown error"
v = ERROR_FILE_NOT_FOUND;
break;
case 0x75: //DE_OPCANCELLED:
case 0x10000: //ERRORONDEST:
case 0x78: //DE_ACCESSDENIEDSRC:
case 0x74: //DE_ROOTDIR:
v = ERROR_ACCESS_DENIED;
break;
}
SetLastError (v);
return v ? -1 : 0;
}
}
示例7: VFS_Archive_CreateFromFileList
// Create an Archive from the specified File List.
VFS_BOOL VFS_Archive_CreateFromFileList( const VFS_String& strArchiveFileName, const VFS_FileNameMap& Files, const VFS_FilterNameList& UsedFilters )
{
static VFS_BYTE Chunk[ FILE_COPY_CHUNK_SIZE ];
// If there's already an Archive with the same File Name and it's open...
VFS_EntityInfo Info;
if( VFS_Archive_GetInfo( ToLower( strArchiveFileName ), Info ) )
{
// Check if the Archive is open.
if( GetOpenArchives().find( ToLower( Info.strPath ) ) != GetOpenArchives().end() )
{
// Check if the Reference Count is != 0.
if( GetOpenArchives()[ ToLower( Info.strPath ) ]->GetRefCount() > 0 )
{
// We don't want to manipulate an open Archive, do we?
SetLastError( VFS_ERROR_IN_USE );
return VFS_FALSE;
}
else
{
// Free the Archive.
delete GetOpenArchives()[ ToLower( Info.strPath ) ];
GetOpenArchives().erase( ToLower( Info.strPath ) );
}
}
}
else
{
Info.strPath = ToLower( strArchiveFileName );
SetLastError( VFS_ERROR_NONE );
}
// Check the Filter Names and make a List of all Filter Pointers.
VFS_FilterList Filters;
for( VFS_FilterNameList::const_iterator iter = UsedFilters.begin(); iter != UsedFilters.end(); iter++ )
{
// Bad Filter Name?
if( !VFS_ExistsFilter( *iter ) )
{
SetLastError( VFS_ERROR_INVALID_PARAMETER );
return VFS_FALSE;
}
// Add the Filter.
Filters.push_back( VFS_GetFilter( *iter ) );
}
// Check all Files.
for( VFS_FileNameMap::const_iterator iter2 = Files.begin(); iter2 != Files.end(); iter2++ )
{
if( !VFS_File_Exists( ( *iter2 ).first ) )
{
SetLastError( VFS_ERROR_NOT_FOUND );
return VFS_FALSE;
}
VFS_String strName;
VFS_Util_GetName( ( *iter2 ).second, strName );
if( strName.size() > VFS_MAX_NAME_LENGTH )
{
SetLastError( VFS_ERROR_INVALID_PARAMETER );
return VFS_FALSE;
}
}
// Make a list of the Directories to create.
typedef vector< VFS_String > NameMap;
NameMap Dirs;
for( VFS_FileNameMap::const_iterator iter3 = Files.begin(); iter3 != Files.end(); iter3++ )
{
VFS_String strDir;
VFS_Util_GetPath( ( *iter3 ).second, strDir );
strDir = ToLower( strDir );
if( strDir != VFS_TEXT( "" ) && find( Dirs.begin(), Dirs.end(), strDir ) == Dirs.end() )
{
// Add the top-level Dirs.
while( strDir.rfind( VFS_PATH_SEPARATOR ) != VFS_String::npos )
{
if( find( Dirs.begin(), Dirs.end(), strDir ) != Dirs.end() )
break;
Dirs.push_back( ToLower( strDir ) );
if( strDir.size() > VFS_MAX_NAME_LENGTH )
{
SetLastError( VFS_ERROR_INVALID_PARAMETER );
return VFS_FALSE;
}
strDir = strDir.substr( 0, strDir.rfind( VFS_PATH_SEPARATOR ) );
}
if( find( Dirs.begin(), Dirs.end(), strDir ) == Dirs.end() )
{
Dirs.push_back( ToLower( strDir ) );
if( strDir.size() > VFS_MAX_NAME_LENGTH )
{
SetLastError( VFS_ERROR_INVALID_PARAMETER );
return VFS_FALSE;
}
}
//.........这里部分代码省略.........
示例8: wxLogDebug
// This define might be needed for VC++ I don't know
// #define STRICT
//! \test Work better if not in the class?
BOOL os_msw::best_terminate_process( HANDLE process_handle, UINT exit_code )
{
wxLogDebug( "Entering os_msw_best_terminate_process" );
BOOL successfully_killed = FALSE;
// If A 95/98/Me version of Windows...
//! \test Does this also exclude Me, and include XP and laters?
if ( wxGetOsVersion() != wxWINDOWS_NT ) {
//! \test make sure you can pass these handles around OK between functions.
// ...then just kill it with the crappy ::TerminateProcess()...
successfully_killed = ::TerminateProcess( process_handle, exit_code );
// ... and return success here, and abort the function.
return successfully_killed;
}
// Otherwise it was a 2000/NT/XP version of windows, and we should use
// our better way than MSW's ::TerminateProcess().
DWORD thread_id = 0;
DWORD temp_exit_code = 0;
DWORD error_number = 0;
HANDLE duplicate_process_handle = INVALID_HANDLE_VALUE;
HANDLE remote_thread_handle = NULL;
HINSTANCE kernel_handle = GetModuleHandle( "Kernel32" );
// Try to duplicate a handle, storing whether successful or not.
BOOL got_a_duplicate_handle_handle = DuplicateHandle( GetCurrentProcess(),
process_handle,
GetCurrentProcess(),
&duplicate_process_handle,
PROCESS_ALL_ACCESS,
FALSE,
0 );
// If it isn't the special case where the process is already dead...
if ( GetExitCodeProcess( ( got_a_duplicate_handle_handle )
? duplicate_process_handle : process_handle, &temp_exit_code )
&& ( temp_exit_code == STILL_ACTIVE ) ) {
// Get the process address.
FARPROC process_address;
process_address = GetProcAddress( kernel_handle, "ExitProcess" );
// Create a remote thread using that process address.
remote_thread_handle = CreateRemoteThread( ( got_a_duplicate_handle_handle ) ? duplicate_process_handle : process_handle,
NULL,
0,
(LPTHREAD_START_ROUTINE)process_address,
(PVOID)exit_code, 0, &thread_id );
// If couldn't get a handle to the remote thread...
if ( remote_thread_handle == NULL ) {
// ...then set the last error number for the debugger.
error_number = GetLastError();
}
// ...otherwise it is already dead.
} else {
error_number = ERROR_PROCESS_ABORTED;
}
// If we did create manage to a remote thread handle...
if ( remote_thread_handle ) {
// ...must wait for a process to terminate to guarantee that it has exited...
//! \todo INFINITE seems a bit high of a number...
WaitForSingleObject( ( got_a_duplicate_handle_handle ) ? duplicate_process_handle : process_handle,
INFINITE );
// ...then close handle...
CloseHandle( remote_thread_handle );
// ...and report that it was successfully killed.
successfully_killed = TRUE;
}
// If we made a duplicate handle...
if ( got_a_duplicate_handle_handle ) {
// ...close that handle too.
CloseHandle( duplicate_process_handle );
}
// If we couldn't kill, set the last error number for the MSW debugger.
if ( ! successfully_killed ) {
SetLastError( error_number );
}
// Return success or not.
return successfully_killed;
}
示例9: _CallPythonObject
//.........这里部分代码省略.........
Py_DECREF(cnv);
goto Done;
}
if (!CDataObject_Check(obj)) {
Py_DECREF(obj);
Py_DECREF(cnv);
PrintError("unexpected result of create argument %d:\n", i);
goto Done;
}
memcpy(obj->b_ptr, *pArgs, dict->size);
PyTuple_SET_ITEM(arglist, i, (PyObject *)obj);
#ifdef MS_WIN32
TryAddRef(dict, obj);
#endif
} else {
PyErr_SetString(PyExc_TypeError,
"cannot build parameter");
PrintError("Parsing argument %d\n", i);
Py_DECREF(cnv);
goto Done;
}
Py_DECREF(cnv);
/* XXX error handling! */
pArgs++;
}
#define CHECK(what, x) \
if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
error_object = get_error_object(&space);
if (error_object == NULL)
goto Done;
if (flags & FUNCFLAG_USE_ERRNO) {
int temp = space[0];
space[0] = errno;
errno = temp;
}
#ifdef MS_WIN32
if (flags & FUNCFLAG_USE_LASTERROR) {
int temp = space[1];
space[1] = GetLastError();
SetLastError(temp);
}
#endif
}
result = PyObject_CallObject(callable, arglist);
CHECK("'calling callback function'", result);
#ifdef MS_WIN32
if (flags & FUNCFLAG_USE_LASTERROR) {
int temp = space[1];
space[1] = GetLastError();
SetLastError(temp);
}
#endif
if (flags & FUNCFLAG_USE_ERRNO) {
int temp = space[0];
space[0] = errno;
errno = temp;
}
Py_XDECREF(error_object);
if ((restype != &ffi_type_void) && result) {
PyObject *keep;
assert(setfunc);
#ifdef WORDS_BIGENDIAN
/* See the corresponding code in callproc.c, around line 961 */
if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg))
mem = (char *)mem + sizeof(ffi_arg) - restype->size;
#endif
keep = setfunc(mem, result, 0);
CHECK("'converting callback result'", keep);
/* keep is an object we have to keep alive so that the result
stays valid. If there is no such object, the setfunc will
have returned Py_None.
If there is such an object, we have no choice than to keep
it alive forever - but a refcount and/or memory leak will
be the result. EXCEPT when restype is py_object - Python
itself knows how to manage the refcount of these objects.
*/
if (keep == NULL) /* Could not convert callback result. */
PyErr_WriteUnraisable(callable);
else if (keep == Py_None) /* Nothing to keep */
Py_DECREF(keep);
else if (setfunc != getentry("O")->setfunc) {
if (-1 == PyErr_Warn(PyExc_RuntimeWarning,
"memory leak in callback function."))
PyErr_WriteUnraisable(callable);
}
}
Py_XDECREF(result);
Done:
Py_XDECREF(arglist);
#ifdef WITH_THREAD
PyGILState_Release(state);
#endif
}
示例10: nonzero
//.........这里部分代码省略.........
// Use the most recent server for the connection attempt
serverIndex = dbIndex;
server = &dbConfigServers[serverIndex];
TRACE("Connecting to server #%d [%s] on attempt %lu/%lu.",
serverIndex, server->name, attempt+1, attemptMax);
// Set connection options
optTimeout = (UINT)dbConfigGlobal.connTimeout;
if (mysql_options(db->handle, MYSQL_OPT_CONNECT_TIMEOUT, &optTimeout) != 0) {
TRACE("Failed to set connection timeout option.");
}
optReconnect = FALSE;
if (mysql_options(db->handle, MYSQL_OPT_RECONNECT, &optReconnect) != 0) {
TRACE("Failed to set reconnection option.");
}
if (server->compression) {
if (mysql_options(db->handle, MYSQL_OPT_COMPRESS, 0) != 0) {
TRACE("Failed to set compression option.");
}
}
if (server->sslEnable) {
//
// This function always returns 0. If the SSL setup is incorrect,
// the call to mysql_real_connect() will return an error.
//
mysql_ssl_set(db->handle, server->sslKeyFile, server->sslCertFile,
server->sslCAFile, server->sslCAPath, server->sslCiphers);
}
// Attempt connection with server
connection = mysql_real_connect(db->handle,
server->host, server->user, server->password,
server->database, server->port, NULL, CLIENT_INTERACTIVE);
if (connection == NULL) {
LOG_ERROR("Unable to connect to server [%s]: %s",
server->name, mysql_error(db->handle));
} else if (mysql_get_server_version(db->handle) < 50019) {
LOG_ERROR("Unsupported version of MySQL Server [%s]: running v%s, must be v5.0.19 or newer.",
server->name, mysql_get_server_info(db->handle));
} else {
// Pointer values should be the same as from mysql_init()
ASSERT(connection == db->handle);
// Allocate pre-compiled statement structures
for (i = 0; i < ELEMENT_COUNT(db->stmt); i++) {
db->stmt[i] = mysql_stmt_init(db->handle);
if (db->stmt[i] == NULL) {
LOG_ERROR("Unable to allocate memory for statement structure.");
error = ERROR_NOT_ENOUGH_MEMORY;
goto failed;
}
}
// Successfully connected, set the global server index
InterlockedExchange(&dbIndex, serverIndex);
// Update context's server index and time stamps
db->index = serverIndex;
GetSystemTimeAsFileTime(&db->created.fileTime);
db->used.value = db->created.value;
LOG_INFO("Connected to %s [%s], running MySQL Server v%s.",
mysql_get_host_info(db->handle), server->name,
mysql_get_server_info(db->handle));
*data = db;
return TRUE;
}
// Unsuccessful connection, continue to the next server
serverNextIndex = serverIndex + 1;
if (serverNextIndex >= (LONG)dbConfigServerCount) {
serverNextIndex = 0;
}
//
// Compare the current server index before swapping values in the
// event that another thread has already changed the index.
//
InterlockedCompareExchange(&dbIndex, serverNextIndex, serverIndex);
}
// Unable to connect to any servers
error = ERROR_CONNECTION_REFUSED;
failed:
if (db != NULL) {
ConnectionClose(NULL, db);
}
SetLastError(error);
return FALSE;
}
示例11: ShortPathToLongPath
DWORD ShortPathToLongPath(LPCTSTR lpszShortPath,LPTSTR lpszLongPath,DWORD
cchBuffer)
{
LONG i=0;
TCHAR path[_MAX_PATH]={0};
TCHAR ret[_MAX_PATH]={0};
LONG pos=0, prev_pos=0;
LONG len=_tcslen(lpszShortPath);
/* Is the string valid? */
if (!lpszShortPath) {
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
/* Is the path valid? */
if (GetFileAttributes(lpszShortPath)==INVALID_FILE_ATTRIBUTES)
return 0;
/* Convert "/" to "\" */
for (i=0;i<len;++i) {
if (lpszShortPath[i]==_T('/'))
path[i]=_T('\\');
else
path[i]=lpszShortPath[i];
}
/* UNC path? */
if (path[0]==_T('\\') && path[1]==_T('\\')) {
pos=2;
for (i=0;i<2;++i) {
while (path[pos]!=_T('\\') && path[pos]!=_T('\0'))
++pos;
++pos;
}
_tcsncpy(ret,path,pos-1);
} /* Drive letter? */
else if (path[1]==_T(':')) {
if (path[2]==_T('\\'))
pos=3;
if (len==3) {
if (cchBuffer>3)
_tcscpy(lpszLongPath,lpszShortPath);
return len;
}
_tcsncpy(ret,path,2);
ret[0] = toupper(ret[0]);
}
/* Expand the path for each subpath, and strip trailing backslashes */
for (prev_pos = pos-1;pos<=len;++pos) {
if (path[pos]==_T('\\') || (path[pos]==_T('\0') &&
path[pos-1]!=_T('\\'))) {
WIN32_FIND_DATA fd;
HANDLE hf=0;
TCHAR c=path[pos];
char* new_element;
path[pos]=_T('\0');
/* the path[prev_pos+1]... path[pos] range is the part of
path we're handling right now. We need to find long
name for that element and add it. */
new_element = path + prev_pos + 1;
/* First add separator, but only if there's something in result already. */
if (ret[0] != _T('\0'))
{
_tcscat(ret,_T("\\"));
}
/* If it's ".." element, we need to append it, not
the name in parent that FindFirstFile will return.
Same goes for "." */
if (new_element[0] == _T('.') && new_element[1] == _T('\0') ||
new_element[0] == _T('.') && new_element[1] == _T('.')
&& new_element[2] == _T('\0'))
{
_tcscat(ret, new_element);
}
else
{
hf=FindFirstFile(path, &fd);
if (hf==INVALID_HANDLE_VALUE)
return 0;
_tcscat(ret,fd.cFileName);
FindClose(hf);
}
path[pos]=c;
prev_pos = pos;
}
}
len=_tcslen(ret)+1;
if (cchBuffer>=len)
_tcscpy(lpszLongPath,ret);
//.........这里部分代码省略.........
示例12: CONTEXT_SetThreadContext
/*++
Function:
SetThreadContext
See MSDN doc.
--*/
BOOL
CONTEXT_SetThreadContext(
DWORD dwProcessId,
pthread_t self,
CONST CONTEXT *lpContext)
{
BOOL ret = FALSE;
#if HAVE_PT_REGS
struct pt_regs ptrace_registers;
#elif HAVE_BSD_REGS_T
struct reg ptrace_registers;
#endif
if (lpContext == NULL)
{
ERROR("Invalid lpContext parameter value\n");
SetLastError(ERROR_NOACCESS);
goto EXIT;
}
/* How to consider the case when self is different from the current
thread of its owner process. Machine registers values could be retreived
by a ptrace(pid, ...) call or from the "/proc/%pid/reg" file content.
Unfortunately, these two methods only depend on process ID, not on
thread ID. */
if (dwProcessId == GetCurrentProcessId())
{
#ifdef FEATURE_PAL_SXS
// Need to implement SetThreadContext(current thread) for the IX architecture; look at common_signal_handler.
_ASSERT(FALSE);
#endif // FEATURE_PAL_SXS
ASSERT("SetThreadContext should be called for cross-process only.\n");
SetLastError(ERROR_INVALID_PARAMETER);
goto EXIT;
}
if (lpContext->ContextFlags &
(CONTEXT_CONTROL | CONTEXT_INTEGER))
{
#if HAVE_PT_REGS
if (ptrace((__ptrace_request)PT_GETREGS, dwProcessId, (caddr_t)&ptrace_registers, 0) == -1)
#elif HAVE_BSD_REGS_T
if (PAL_PTRACE(PT_GETREGS, dwProcessId, &ptrace_registers, 0) == -1)
#endif
{
ASSERT("Failed ptrace(PT_GETREGS, processId:%d) errno:%d (%s)\n",
dwProcessId, errno, strerror(errno));
SetLastError(ERROR_INTERNAL_ERROR);
goto EXIT;
}
#if HAVE_PT_REGS
#define ASSIGN_REG(reg) PTREG_##reg(ptrace_registers) = lpContext->reg;
#elif HAVE_BSD_REGS_T
#define ASSIGN_REG(reg) BSDREG_##reg(ptrace_registers) = lpContext->reg;
#else
#define ASSIGN_REG(reg)
ASSERT("Don't know how to set the context of another process on this platform!");
return FALSE;
#endif
if (lpContext->ContextFlags & CONTEXT_CONTROL)
{
ASSIGN_CONTROL_REGS
}
if (lpContext->ContextFlags & CONTEXT_INTEGER)
{
ASSIGN_INTEGER_REGS
}
#undef ASSIGN_REG
#if HAVE_PT_REGS
if (ptrace((__ptrace_request)PT_SETREGS, dwProcessId, (caddr_t)&ptrace_registers, 0) == -1)
#elif HAVE_BSD_REGS_T
if (PAL_PTRACE(PT_SETREGS, dwProcessId, &ptrace_registers, 0) == -1)
#endif
{
ASSERT("Failed ptrace(PT_SETREGS, processId:%d) errno:%d (%s)\n",
dwProcessId, errno, strerror(errno));
SetLastError(ERROR_INTERNAL_ERROR);
goto EXIT;
}
}
ret = TRUE;
EXIT:
return ret;
}
示例13: SFileOpenArchiveEx
//.........这里部分代码省略.........
// Note that this may change in next MPQ versions
if(pBlock->dwFlags & 0x000000FF)
{
bBlockTableEncrypted = TRUE;
break;
}
// Move to the next block table entry
pBlock++;
}
if(bBlockTableEncrypted)
{
DecryptBlockTable((DWORD *)ha->pBlockTable,
(BYTE *)"(block table)",
(ha->pHeader->dwBlockTableSize * 4));
}
}
// Now, read the extended block table.
// For V1 archives, we still will maintain the extended block table
// (it will be filled with zeros)
// TODO: Test with >4GB
if(nError == ERROR_SUCCESS)
{
memset(ha->pExtBlockTable, 0, dwBlockTableSize * sizeof(TMPQBlockEx));
if(ha->pHeader->ExtBlockTablePos.QuadPart != 0)
{
dwBytes = ha->pHeader->dwBlockTableSize * sizeof(TMPQBlockEx);
SetFilePointer(ha->hFile,
ha->ExtBlockTablePos.LowPart,
&ha->ExtBlockTablePos.HighPart,
FILE_BEGIN);
ReadFile(ha->hFile, ha->pExtBlockTable, dwBytes, &dwTransferred, NULL);
// We have to convert every DWORD in ha->block from LittleEndian
BSWAP_ARRAY16_UNSIGNED((USHORT *)ha->pExtBlockTable, dwBytes / sizeof(USHORT));
// The extended block table is not encrypted (so far)
if(dwTransferred != dwBytes)
nError = ERROR_FILE_CORRUPT;
}
}
// Verify the both block tables (If the MPQ file is not protected)
if(nError == ERROR_SUCCESS && (ha->dwFlags & MPQ_FLAG_PROTECTED) == 0)
{
TMPQBlockEx * pBlockEx = ha->pExtBlockTable;
TMPQBlock * pBlockEnd = ha->pBlockTable + dwMaxBlockIndex + 1;
TMPQBlock * pBlock = ha->pBlockTable;
// If the MPQ file is not protected,
// we will check if all sizes in the block table is correct.
// Note that we will not relocate the block table (change from previous versions)
for(; pBlock < pBlockEnd; pBlock++, pBlockEx++)
{
if(pBlock->dwFlags & MPQ_FILE_EXISTS)
{
// Get the 64-bit file position
TempPos.HighPart = pBlockEx->wFilePosHigh;
TempPos.LowPart = pBlock->dwFilePos;
if(TempPos.QuadPart > ha->MpqSize.QuadPart || pBlock->dwCSize > ha->MpqSize.QuadPart)
{
nError = ERROR_BAD_FORMAT;
break;
}
}
}
}
// If the user didn't specified otherwise,
// include the internal listfile to the TMPQArchive structure
if((dwFlags & MPQ_OPEN_NO_LISTFILE) == 0)
{
if(nError == ERROR_SUCCESS)
SListFileCreateListFile(ha);
// Add the internal listfile
if(nError == ERROR_SUCCESS)
SFileAddListFile((HANDLE)ha, NULL);
}
// Cleanup and exit
if(nError != ERROR_SUCCESS)
{
FreeMPQArchive(ha);
if(hFile != INVALID_HANDLE_VALUE)
CloseHandle(hFile);
SetLastError(nError);
}
else
{
if(pFirstOpen == NULL)
pFirstOpen = ha;
}
*phMPQ = ha;
return (nError == ERROR_SUCCESS);
}
示例14: AeroAutoSubclass
BOOL AeroAutoSubclass(HWND hWnd, DWORD dwFlags, DWORD dwReserved)
{
if(!hWnd || !IsWindow(hWnd) || 0L!=dwReserved)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
UINT uiRedrawMsg = RegisterWindowMessage(REDRAWSTRING);
if(!uiRedrawMsg)
return FALSE; // use the RegisterWindowMessage last error
CDwmApiImpl *pDwm = NULL;
CUxThemeAeroImpl *pUxTheme = NULL;
PAERO_SUBCLASS_WND_DATA pWndData = NULL;
DWORD dwLastError = ERROR_SUCCESS;
MARGINS marGlassInset = {-1,-1,-1,-1};
HRESULT hRes = S_OK;
bool bBufferedPaintInitialized = false;
ERROR_PARENT_AERO_SUBCLASS_WND_DATA errParentAeroData;
ZeroMemory(&errParentAeroData, sizeof(errParentAeroData));
errParentAeroData.m_dwFlags = dwFlags;
errParentAeroData.m_hWndParent = hWnd;
try
{
pDwm = new CDwmApiImpl;
}
catch (...)
{
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
}
if(ERROR_SUCCESS!=dwLastError)
goto CLEANUP;
try
{
pUxTheme = new CUxThemeAeroImpl;
}
catch (...)
{
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
}
if(ERROR_SUCCESS!=dwLastError)
goto CLEANUP;
pWndData = (PAERO_SUBCLASS_WND_DATA)LocalAlloc(LPTR, sizeof(AERO_SUBCLASS_WND_DATA));
if(!pWndData)
{
dwLastError = GetLastError();
goto CLEANUP;
}
if(!pDwm->Initialize())
{
dwLastError = GetLastError();
goto CLEANUP;
}
if(!pUxTheme->Initialize())
{
dwLastError = GetLastError();
goto CLEANUP;
}
if(pDwm->IsDwmCompositionEnabled() && !(dwFlags&ASC_NO_FRAME_EXTENSION))
{
///
/// we do not evaluate the return value of pDwm->DwmExtendFrameIntoClientArea, because
/// if composition is turned off in the tiny little race condition after the previous call
/// to IsDwmCompositionEnabled and before the following call to DwmExtendFrameIntoClientArea,
/// we would see DwmExtendFrameIntoClientArea fail. However, if composition is turned on again
/// aterwards, the UI can display composition again without problems:
///
pDwm->DwmExtendFrameIntoClientArea(hWnd, &marGlassInset);
}
hRes = pUxTheme->BufferedPaintInit();
if(FAILED(hRes))
{
dwLastError = hRes;
goto CLEANUP;
}
bBufferedPaintInitialized = true;
if(!SetProp(hWnd, WINDOW_DATA_STRING, pWndData))
{
dwLastError = hRes;
goto CLEANUP;
}
errParentAeroData.m_pdwError = &dwLastError;
errParentAeroData.m_pWndParentAeroData = pWndData;
pWndData->m_pDwmApiImpl = pDwm;
pWndData->m_pUxTheme = pUxTheme;
pWndData->m_uiRedrawMsg = uiRedrawMsg;
if(dwFlags&ASC_NO_FRAME_EXTENSION)
//.........这里部分代码省略.........
示例15: RDCASSERT
HANDLE WrappedOpenGL::wglDXRegisterObjectNV(HANDLE hDevice, void *dxObject, GLuint name,
GLenum type, GLenum access)
{
RDCASSERT(IsCaptureMode(m_State));
ID3D11Resource *real = UnwrapDXResource(dxObject);
if(real == NULL)
{
SetLastError(ERROR_OPEN_FAILED);
return 0;
}
WrappedHANDLE *wrapped = new WrappedHANDLE();
if(type == eGL_RENDERBUFFER)
wrapped->res = RenderbufferRes(GetCtx(), name);
else if(type == eGL_NONE)
wrapped->res = BufferRes(GetCtx(), name);
else
wrapped->res = TextureRes(GetCtx(), name);
GLResourceRecord *record = GetResourceManager()->GetResourceRecord(wrapped->res);
if(!record)
{
RDCERR("Unrecognised object with type %x and name %u", type, name);
delete wrapped;
return NULL;
}
SERIALISE_TIME_CALL(wrapped->real =
m_Real.wglDXRegisterObjectNV(hDevice, real, name, type, access));
{
RDCASSERT(record);
USE_SCRATCH_SERIALISER();
SCOPED_SERIALISE_CHUNK(gl_CurChunk);
Serialise_wglDXRegisterObjectNV(ser, wrapped->res, type, dxObject);
record->AddChunk(scope.Get());
}
if(type != eGL_NONE)
{
ResourceFormat fmt;
uint32_t width = 0, height = 0, depth = 0, mips = 0, layers = 0, samples = 0;
GetDXTextureProperties(dxObject, fmt, width, height, depth, mips, layers, samples);
// defined as arrays mostly for Coverity code analysis to stay calm about passing
// them to the *TexParameter* functions
GLint maxlevel[4] = {GLint(mips - 1), 0, 0, 0};
m_Real.glTextureParameteriEXT(wrapped->res.name, type, eGL_TEXTURE_MAX_LEVEL, GLint(mips - 1));
ResourceId texId = record->GetResourceID();
m_Textures[texId].resource = wrapped->res;
m_Textures[texId].curType = type;
m_Textures[texId].width = width;
m_Textures[texId].height = height;
m_Textures[texId].depth = RDCMAX(depth, samples);
m_Textures[texId].samples = samples;
m_Textures[texId].dimension = 2;
if(type == eGL_TEXTURE_1D || type == eGL_TEXTURE_1D_ARRAY)
m_Textures[texId].dimension = 1;
else if(type == eGL_TEXTURE_3D)
m_Textures[texId].dimension = 3;
m_Textures[texId].internalFormat = MakeGLFormat(fmt);
}
return wrapped;
}