📄 wxutil.h
字号:
public:
CQueue(int n) {
Initialize(n);
}
CQueue() {
Initialize(DEFAULT_QUEUESIZE);
}
~CQueue() {
delete [] QueueObjects;
DeleteCriticalSection(&CritSect);
CloseHandle(hSemPut);
CloseHandle(hSemGet);
}
T GetQueueObject() {
int iSlot;
T Object;
LONG lPrevious;
// Wait for someone to put something on our queue, returns straight
// away is there is already an object on the queue.
//
WaitForSingleObject(hSemGet, INFINITE);
EnterCriticalSection(&CritSect);
iSlot = iNextGet++ % nMax;
Object = QueueObjects[iSlot];
LeaveCriticalSection(&CritSect);
// Release anyone waiting to put an object onto our queue as there
// is now space available in the queue.
//
ReleaseSemaphore(hSemPut, 1L, &lPrevious);
return Object;
}
void PutQueueObject(T Object) {
int iSlot;
LONG lPrevious;
// Wait for someone to get something from our queue, returns straight
// away is there is already an empty slot on the queue.
//
WaitForSingleObject(hSemPut, INFINITE);
EnterCriticalSection(&CritSect);
iSlot = iNextPut++ % nMax;
QueueObjects[iSlot] = Object;
LeaveCriticalSection(&CritSect);
// Release anyone waiting to remove an object from our queue as there
// is now an object available to be removed.
//
ReleaseSemaphore(hSemGet, 1L, &lPrevious);
}
};
// miscellaneous string conversion functions
// NOTE: as we need to use the same binaries on Win95 as on NT this code should
// be compiled WITHOUT unicode being defined. Otherwise we will not pick up
// these internal routines and the binary will not run on Win95.
int WINAPIV wsprintfWInternal(LPWSTR, LPCWSTR, ...);
LPWSTR
WINAPI
lstrcpyWInternal(
LPWSTR lpString1,
LPCWSTR lpString2
);
LPWSTR
WINAPI
lstrcpynWInternal(
LPWSTR lpString1,
LPCWSTR lpString2,
int iMaxLength
);
int
WINAPI
lstrcmpWInternal(
LPCWSTR lpString1,
LPCWSTR lpString2
);
int
WINAPI
lstrcmpiWInternal(
LPCWSTR lpString1,
LPCWSTR lpString2
);
int
WINAPI
lstrlenWInternal(
LPCWSTR lpString
);
#ifndef UNICODE
#define wsprintfW wsprintfWInternal
#define lstrcpyW lstrcpyWInternal
#define lstrcpynW lstrcpynWInternal
#define lstrcmpW lstrcmpWInternal
#define lstrcmpiW lstrcmpiWInternal
#define lstrlenW lstrlenWInternal
#endif
extern "C"
void * __stdcall memmoveInternal(void *, const void *, size_t);
inline void * __cdecl memchrInternal(const void *buf, int chr, size_t cnt)
{
#ifdef _X86_
void *pRet = NULL;
_asm {
cld // make sure we get the direction right
mov ecx, cnt // num of bytes to scan
mov edi, buf // pointer byte stream
mov eax, chr // byte to scan for
repne scasb // look for the byte in the byte stream
jnz exit_memchr // Z flag set if byte found
dec edi // scasb always increments edi even when it
// finds the required byte
mov pRet, edi
exit_memchr:
}
return pRet;
#else
while ( cnt && (*(unsigned char *)buf != (unsigned char)chr) ) {
buf = (unsigned char *)buf + 1;
cnt--;
}
return(cnt ? (void *)buf : NULL);
#endif
}
void WINAPI IntToWstr(int i, LPWSTR wstr);
#define WstrToInt(sz) _wtoi(sz)
#define atoiW(sz) _wtoi(sz)
#define atoiA(sz) atoi(sz)
// These are available to help managing bitmap VIDEOINFOHEADER media structures
extern const DWORD bits555[3];
extern const DWORD bits565[3];
extern const DWORD bits888[3];
// These help convert between VIDEOINFOHEADER and BITMAPINFO structures
STDAPI_(const GUID) GetTrueColorType(const BITMAPINFOHEADER *pbmiHeader);
STDAPI_(const GUID) GetBitmapSubtype(const BITMAPINFOHEADER *pbmiHeader);
STDAPI_(WORD) GetBitCount(const GUID *pSubtype);
// strmbase.lib implements this for compatibility with people who
// managed to link to this directly. we don't want to advertise it.
//
// STDAPI_(/* T */ CHAR *) GetSubtypeName(const GUID *pSubtype);
STDAPI_(CHAR *) GetSubtypeNameA(const GUID *pSubtype);
STDAPI_(WCHAR *) GetSubtypeNameW(const GUID *pSubtype);
#ifdef UNICODE
#define GetSubtypeName GetSubtypeNameW
#else
#define GetSubtypeName GetSubtypeNameA
#endif
STDAPI_(LONG) GetBitmapFormatSize(const BITMAPINFOHEADER *pHeader);
STDAPI_(DWORD) GetBitmapSize(const BITMAPINFOHEADER *pHeader);
STDAPI_(BOOL) ContainsPalette(const VIDEOINFOHEADER *pVideoInfo);
STDAPI_(const RGBQUAD *) GetBitmapPalette(const VIDEOINFOHEADER *pVideoInfo);
// Compares two interfaces and returns TRUE if they are on the same object
BOOL WINAPI IsEqualObject(IUnknown *pFirst, IUnknown *pSecond);
// This is for comparing pins
#define EqualPins(pPin1, pPin2) IsEqualObject(pPin1, pPin2)
// Arithmetic helper functions
// Compute (a * b + rnd) / c
LONGLONG WINAPI llMulDiv(LONGLONG a, LONGLONG b, LONGLONG c, LONGLONG rnd);
LONGLONG WINAPI Int64x32Div32(LONGLONG a, LONG b, LONG c, LONG rnd);
// Avoids us dyna-linking to SysAllocString to copy BSTR strings
STDAPI WriteBSTR(BSTR * pstrDest, LPCWSTR szSrc);
STDAPI FreeBSTR(BSTR* pstr);
// Return a wide string - allocating memory for it
// Returns:
// S_OK - no error
// E_POINTER - ppszReturn == NULL
// E_OUTOFMEMORY - can't allocate memory for returned string
STDAPI AMGetWideString(LPCWSTR pszString, LPWSTR *ppszReturn);
// Special wait for objects owning windows
DWORD WINAPI WaitDispatchingMessages(
HANDLE hObject,
DWORD dwWait,
HWND hwnd = NULL,
UINT uMsg = 0,
HANDLE hEvent = NULL);
// HRESULT_FROM_WIN32 converts ERROR_SUCCESS to a success code, but in
// our use of HRESULT_FROM_WIN32, it typically means a function failed
// to call SetLastError(), and we still want a failure code.
//
#define AmHresultFromWin32(x) (MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, x))
// call GetLastError and return an HRESULT value that will fail the
// SUCCEEDED() macro.
HRESULT AmGetLastErrorToHResult(void);
// duplicate of ATL's CComPtr to avoid linker conflicts.
IUnknown* QzAtlComPtrAssign(IUnknown** pp, IUnknown* lp);
template <class T>
class QzCComPtr
{
public:
typedef T _PtrClass;
QzCComPtr() {p=NULL;}
QzCComPtr(T* lp)
{
if ((p = lp) != NULL)
p->AddRef();
}
QzCComPtr(const QzCComPtr<T>& lp)
{
if ((p = lp.p) != NULL)
p->AddRef();
}
~QzCComPtr() {if (p) p->Release();}
void Release() {if (p) p->Release(); p=NULL;}
operator T*() {return (T*)p;}
T& operator*() {ASSERT(p!=NULL); return *p; }
//The assert on operator& usually indicates a bug. If this is really
//what is needed, however, take the address of the p member explicitly.
T** operator&() { ASSERT(p==NULL); return &p; }
T* operator->() { ASSERT(p!=NULL); return p; }
T* operator=(T* lp){return (T*)QzAtlComPtrAssign((IUnknown**)&p, lp);}
T* operator=(const QzCComPtr<T>& lp)
{
return (T*)QzAtlComPtrAssign((IUnknown**)&p, lp.p);
}
#if _MSC_VER>1020
bool operator!(){return (p == NULL);}
#else
BOOL operator!(){return (p == NULL) ? TRUE : FALSE;}
#endif
T* p;
};
MMRESULT CompatibleTimeSetEvent( UINT uDelay, UINT uResolution, LPTIMECALLBACK lpTimeProc, DWORD_PTR dwUser, UINT fuEvent );
bool TimeKillSynchronousFlagAvailable( void );
#endif /* __WXUTIL__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -