📄 osdwinbase.c
字号:
#include"osdwindows.h"
#include"prtime.h"
#include"prmem.h"
DWORD GetTickCount(VOID)
{
return PrTimeGetTicks()/PrTimeGetTicksPerSecond()*1000;
}
VOID ZeroMemory(PVOID Destination,DWORD Length)
{ // size, in bytes, of block to fill with zeros
memset(Destination,0,Length);
}
INT WINAPI MulDiv( INT nMultiplicand, INT nMultiplier, INT nDivisor)
{
LONG ret;
if (!nDivisor) return -1;
/* We want to deal with a positive divisor to simplify the logic. */
if (nDivisor < 0){
nMultiplicand = - nMultiplicand;
nDivisor = -nDivisor;
}
/* If the result is positive, we "add" to round. else, we subtract to round. */
if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
ret = (((LONG)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
else
ret = (((LONG)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
if ((ret > 2147483647) || (ret < -2147483647)) return -1;
return ret;
}
//=================================================================
typedef struct {
BOOL (*Open)(IStream*istream);
LONG (*Read)(IStream*istream,const void* lpBuf, UINT nCount );
LONG (*Write)(IStream*istream,const void* lpBuf, UINT nCount );
LONG (*Seek)(IStream*istream,LONG lOff, UINT nFrom );
void (*Close)(IStream*istream);
BOOL (*Eof)(IStream*istream);
UCHAR*Data;
ULONG position;
ULONG length;
}IMemStream;
static BOOL MS_Open(IStream*istream)
{
return TRUE;
}
static LONG MS_Read(IStream*istream,const void* lpBuf, UINT nCount )
{
IMemStream*m=(IMemStream*)istream;
memcpy(lpBuf,m->Data+m->position,nCount);
m->position+=nCount;
return nCount;
}
static LONG MS_Write(IStream*istream,const void* lpBuf, UINT nCount )
{
if(istream==NULL||lpBuf==NULL)
return -1;
if(nCount==0)
return 0;
return nCount;
}
static LONG MS_Seek(IStream*istream,LONG lOff, UINT nFrom )
{
IMemStream*m=(IMemStream*)istream;
switch(nFrom){
case SEEK_SET:
m->position=lOff;
break;
case SEEK_CUR:
m->position+=lOff;
break;
case SEEK_END:
m->position=m->length+lOff;
break;
}
return 0;
}
static void MS_Close(IStream*istream)
{
if(istream)
PrFree(istream);
}
static BOOL MS_Eof(IStream*istream)
{
IMemStream*m=(IMemStream*)istream;
return m->position>=m->length;
}
IStream*CreateMemStream(BYTE* lpBuffer,UINT nBufferSize, UINT nGrowBytes)
{
IMemStream*m=(IMemStream*)PrMalloc(sizeof(IMemStream));
m->Open=MS_Open;
m->Close=MS_Close;
m->Seek=MS_Seek;
m->Read=MS_Read;
m->Write=MS_Write;
m->Eof=MS_Eof;
m->Data=lpBuffer;
m->position=0;
m->length=nBufferSize;
return (IStream*)m;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -