아. 왜 이렇게 간단한 걸 진작에 생각 못했지.

const static short s_sh = 0x00ff;
const static char *s_pch = (char*)&s_sh;

#define IsOrderingBigEndian (s_pch[0]==0?TRUE:FALSE)



Simpler: 

const static short s_sh = 0x0100;
const static char *s_pch = (char*)&s_sh;

#define IsOrderingBigEndian (s_pch[0])

 
Posted by 배트
,
1. 커널 소스를 써야 한다. (최소한 드라이버 모듈)
2. 아래와 같이 File operation만 치환하려고 했는데,
    i_fop가 const로 정의되어 있어서 (linux/fs.h ln642) 에러만 난다.
    code) filp->f_dentry->d_inode->i_fop->llseek = my_llseek;
3. 결국 Block device driver 형태로 만드는 수 밖에 없는데,
    시간을 더 쓸 수가 없어서 이쯤에서 pending. 다음 기회에.
Posted by 배트
,
// function for adding two big number in big endian
static void add(const unsigned char *a, int la, const unsigned char *b, int lb, unsigned char *mul, int *lmul)
{
int ltemp = ((la>lb)?la:lb)+1;
int lmin = ((la>lb)?lb:la);
unsigned char *temp = (unsigned char*)malloc(ltemp);
int xa = la-1, xb = lb-1, y = ltemp-1, u = 0;
int k = 0, z = 0;

memset(temp, 0, ltemp);

while(xa>=0 && xb>=0)
{
temp[y] = a[xa] + b[xb] + u;

if( temp[y] < a[xa] )
u = 1;
else
u = 0;

y--;
xa--;
xb--;
}

while(temp[++k]==0);

for(z=k ; z<ltemp ; z++)
mul[z-k] = temp[z];
*lmul = z-k;

free(temp); 
}
Posted by 배트
,
// function for multiplying two big number in big endian
// big endian means, the number in a first index is the most significant byte.
static void multiply(const unsigned char *a, int la, const unsigned char *b, int lb, unsigned char *mul, int *lmul)
{
unsigned char *c = NULL;
unsigned char *temp = NULL;
int i,j,k=0,x=0,y;
long int r=0;
long sum = 0;

c = (unsigned char*)malloc(la+lb);
temp = (unsigned char*)malloc(la*lb*2);
la--;
lb--;

for(i=lb;i>=0;i--){
r=0;
for(j=la;j>=0;j--){
temp[k++] = (b[i]*a[j] + r)%256;
r = (b[i]*a[j]+r)/256;
}
temp[k++] = r;
x++;
for(y = 0;y<x;y++){
temp[k++] = 0;
}
}

k=0;
r=0;
for(i=0;i<la+lb+2;i++){
sum =0;
y=0;
for(j=1;j<=lb+1;j++){
if(i <= la+j){
sum = sum + temp[y+i];
}
y += j + la + 1;
}
c[k++] = (sum+r) %256;
r = (sum+r)/256;
}
c[k] = r;
j=0;
while(c[k-1]==0)
k--;
for(i=k-1;i>=0;i--){
mul[j++]=c[i];
}
*lmul = j;

free(c);
free(temp);
}
Posted by 배트
,
// to do: build the code and execute the binary twice at the same time!

int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE hMutex;
    DWORD dwWaitResult;

    for( int i=0 ; i<3 ; i++ )
    {
        // if the mutex with the same name exists, it opens the mutex with MUTEX_ALL_ACCESS right.
        hMutex = CreateMutex(NULL, FALSE, _T("XXXXXXX_uid:0a0b6203-cd11-4b50-877b-3965da7275cc"));

        // waiting for other thread release the mutex
        // then this thread will get the mutex
        _tprintf( _T("Waiting for the mutex... ") );
        dwWaitResult = WaitForSingleObject(hMutex, INFINITE);
        switch(dwWaitResult)
        {
        case WAIT_OBJECT_0:
            // This thread got a mutex!
            _tprintf(_T ("thread got mutex ! \n") );
            break;
        case WAIT_TIMEOUT:
            // A time out occurs...
            _tprintf(_T ("timer expired ! \n") );
            break;
        case WAIT_ABANDONED:
            // Another thread may not release the mutex before it terminated.
            // The mutex has been abandoned.... how poor....
            _tprintf(_T ("abandoned ! \n") );
            break;
        }

        _tprintf( _T("Thread Running (%d) ! \n"), i+1 );
        for( int j=0 ; j<10 ; j++)
        {
            _puttch(_T('.'));
            Sleep(100);
        }
        _puttch(_T('\n'));

        // should release the mutex
        _tprintf( _T("One loop ended, the mutex will be released! \n\n") );
        ReleaseMutex(hMutex);
    }

    _tprintf( _T("Test has terminated.\nPress any key to continue... \n") );
    _gettch();

    return 0;
}
Posted by 배트
,
내가 이딴건 왜 만들었을까...

class SafeData {
public:
    SafeData();
    virtual ~SafeData();
    void SetByCopy( Data inData );
    void SetByCopy( uint8 *d, int l );
    void SetByRef( Data inData );
    void SetByRef( uint8 *d, int l );
    uint8 *GetData();
    int GetLength();
    void Clear();
    
protected:
    uint8 *pBuffer;
    int length;
};

SafeData::SafeData()
{
    pBuffer = NULL;
    length = 0;
};

SafeData::~SafeData()
{
    Clear();
};

void SafeData::SetByCopy( Data inData )
{
    Clear();
    pBuffer = new uint8[inData.len];
    if( pBuffer==NULL )
        return;
    length = inData.len;
    memcpy( pBuffer, inData.d, length );
}

void SafeData::SetByCopy( uint8 *d, int l )
{
    Clear();
    pBuffer = new uint8[l];
    if( pBuffer==NULL )
        return;
    length = l;
    memcpy( pBuffer, d, length );
}

void SafeData::SetByRef( Data inData )
{
    Clear();
    pBuffer = inData.d;
    length = inData.len;
}

void SafeData::SetByRef( uint8 *d, int l )
{
    Clear();
    pBuffer = d;
    length = l;
}

uint8 *SafeData::GetData() {return pBuffer;}

int SafeData::GetLength() {return length;}

void SafeData::Clear()
{
    if( pBuffer )
    {
        delete [] pBuffer;
        pBuffer = NULL;
    }
    length = 0;
}

Posted by 배트
,
으...폰트 이름과 헤더 수정 못했음.
두 폰트 모두 편집과 배포가 자유로운 폰트지만,
헤더의 저작권를 적절히 수정하지 못해서 문제가 생길 수는 있음.
Posted by 배트
,
언젠가 유용하게 쓰겠지...
The temporary file handling class for Win32.

class TempFileUtility {
public:
    TempFileUtility()
    {
        ResetData();
    }

    virtual ~TempFileUtility()
    {
        CloseTempFile();
    }

    int OpenTempFile( BOOL bCloseAfterCreated )
    {
        if( m_bInitialized==TRUE )
            return ERROR_ALREADY_INITIALIZED;

        const int cMaxTempDir = MAX_PATH-14;        
        TCHAR szTempDir[cMaxTempDir];
        
        int nResult = 0;
        
        nResult = GetTempPath( cMaxTempDir, szTempDir );
        if( nResult==0 || nResult>cMaxTempDir )
        {
            nResult = SHGetSpecialFolderPath( NULL, szTempDir, CSIDL_MYDOCUMENTS, TRUE );
            
            if( nResult==FALSE )
                return ERROR_CANNOT_MAKE;
        }
        
        nResult = GetTempFileName( szTempDir, _T(""), 0, m_szTempFile );
        if( nResult==FALSE )
        {
            ResetData();
            return ERROR_CANNOT_MAKE;
        }

        if( bCloseAfterCreated==TRUE )
        {    
            m_hFile = CreateFile( m_szTempFile, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL );
            if( m_hFile==INVALID_HANDLE_VALUE )
            {
                DeleteFile( m_szTempFile );
                ResetData();
                return ERROR_OPEN_FAILED;
            }
        }

        m_bInitialized = TRUE;
        return ERROR_SUCCESS;
    }

    int WriteTempFile(
        LPCVOID lpBuffer,
        DWORD nNumberOfBytesToWrite
        )
    {
        if( m_bInitialized==FALSE )
            return ERROR_NOT_READY;

        if( m_hFile==INVALID_HANDLE_VALUE )        
            return ERROR_NOT_READY;

        BOOL bSuccess;
        DWORD dwWritten = 0;

        bSuccess = WriteFile( m_hFile, lpBuffer, nNumberOfBytesToWrite, &dwWritten, NULL );

        if( bSuccess==FALSE )
            return GetLastError();

        return ERROR_SUCCESS;
    }


    int CloseTempFile()
    {
        if( m_bInitialized==FALSE )
            return ERROR_NOT_READY;

        if( m_hFile!=INVALID_HANDLE_VALUE )
            CloseHandle( m_hFile );

        DeleteFile( m_szTempFile );
        ResetData();
        return ERROR_SUCCESS;
    }

    LPCTSTR GetTempFilePath() {return m_szTempFile;}
    HANDLE GetTempFileHandle() {return m_hFile;}

protected:
    BOOL m_bInitialized;
    TCHAR m_szTempFile[MAX_PATH];
    HANDLE m_hFile;

    void ResetData()
    {
        m_bInitialized = FALSE;
        memset( m_szTempFile, 0, MAX_PATH );
        m_hFile = INVALID_HANDLE_VALUE;
    }
};

Posted by 배트
,
IE ActiveX는 버리고 CEF로 가자!
아..쥰내 아름답네. 한두가지 모자라긴 하지만.
특히 Attribute 세팅이 자동으로 UI에 적용되어야 하는데...그건 당장 구현하기가 귀찮아서 일단은 이렇게 하자.

Posted by 배트
,
CEF는 크로미움의 웹 브라우저 기능을 Win32 Windows 기반의 컨트롤로써 사용할 수 있게 해준다.
기존 IE ActiveX를 애플리케이션에 Embedding하는 방식을 써왔다면, CEF가 좋은 대안이 될 수 있다.

CEF를 사용하면 IE의 불안정과 속도 문제, 불편한 인터페이스를 해결할 수 있다.
CEF는 라이브러리로 제공되기 때문에 IE 또는 인터넷 설정과의 종속성을 해결할 수 있다.
IE가 제공하는 것보다 기능이 적다고 여겨지나,
개발자에게 필요한 기능은 거의 다 있고 사용법이 간단하다.
웹 표준은 말할 것도 없고.

앞으로 웹을 Embedding하는 Windows 애플리케이션은 모두 CEF를 사용할 생각이다.
여기서 소스와 라이브러리를 받을 수 있다. http://code.google.com/p/chromiumembedded/
Posted by 배트
,