IT 취미생활.  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
'It'에 해당하는 글(34)
2009.09.10   Hex String to integer 1
2009.09.10   ini 설정 파일에 특정 value 얻어오기
2009.08.19   USB Booting + XP Password 제거하기
2009.07.21   warning: dereferencing type-punned pointer will break strict-aliasing rules
2009.07.17   Iimage 를 이용하여 jpeg 출력 2
2009.07.01   [warning]suggest parentheses around assignment used as truth value
2009.01.09   [보습학습] UTF-8
2009.01.06   신입 OT에서 감명 받은 것!!! "altigenome"
2008.12.12   파일명, 라인정보를 보여주는 에러 메세지 박스 만들기 1
2008.12.12   error C2787: 'IContextMenu' : no GUID has been associated with this object
2008.12.12   [링크]지적 호기심 없는 20대 노인들


Hex String to integer

이전에 포스팅한 GetProfileToString을 통해서, 특정 값을 읽어왔는데 제기럴 Hex 값이었다.
Int 값이었으면 atoi를 이용해서 int로 쓰겠는데 왠걸 hex string... 열심히 구글링 해보니 CodeProject에 Sample이 있어 업어왔다.


linux에서 왜 string.h에 strupr이 없는걸까???????
보안에 문제가 있는 API라서? 쩝....

Set로 움직이는 함수입니다.
꼭 필요한 분들이 있을 것 같습니다.

수정사항이 있으시면 언제든지!!!  피드백 부탁 드립니다.

고운하루 되세요


char* StrUpr( char *str )
{
    int loop = 0;
    while( str[loop] != '\0' )
    {
        str[loop] = (char) toupper( str[loop] );
        loop++;
    }
    return str;
}


/*
 * hex string to int
*/

int xtoi(char *value)
{
    struct CHexMap
    {
        char chr;
        int value;
    };

    const int HexMapL = 16;
    CHexMap HexMap[HexMapL] =
    {
        {'0', 0}, {'1', 1},
        {'2', 2}, {'3', 3},
        {'4', 4}, {'5', 5},
        {'6', 6}, {'7', 7},
        {'8', 8}, {'9', 9},
        {'A', 10}, {'B', 11},
        {'C', 12}, {'D', 13},
        {'E', 14}, {'F', 15}
    };

    /* remove space */
    int len = strlen(value);
    for(int i = 0; i < len; i++) {
        if( *(value+i) == ' ') {
            value++;
        } else {
            break;
        }
    }

    /* alloc buffer and change upper */
    char *mstr = StrUpr(strdup(value));
    char *s = mstr;
    int result = 0;
    if (*s == '0' && *(s + 1) == 'X')
        s += 2;
    bool firsttime = true;
    while (*s != '\0')
    {
        bool found = false;
        for (int i = 0; i < HexMapL; i++)
        {
            if (*s == HexMap[i].chr)
            {
                if (!firsttime) result <<= 4;
                result |= HexMap[i].value;
                found = true;
                break;
            }
        }
        if (!found) break;
        s++;
        firsttime = false;
    }
    free(mstr);
    return result;
}



ini 설정 파일에 특정 value 얻어오기

linux에서도 이런 API가 있는지 모르겠어서
하나 간단하게 함수로 만들어 보았습니다.

머리가 나쁜면 손발이 고생한다고 하는데 -0-;
필요하신 분들이 있으면 잘 활용하셔요!

예외 처리등이 부실하니, 좀더 낳은 버전으로 수정 하시면
피드백 부탁 드리겠습니다.

그럼 고운하루 되세요.

/*
 * ex) test.ini
 *     [Data]
 *     value= 30
 *     .....
 *
 * ex) GetProfileToString("[Data]", "value=", buffer, "/tmp/test.ini");
 * 텍스트로 작성된 ini 등 에서 특정 섹션의 값을 읽어 온다.
 */
void GetProfileToString(char *section, char *keyName, char *string, char *fileFullPath)
{
    char tempBuffer[MAX_PATH] = { 0 };
    char *result = NULL;
    FILE *fp = fopen(fileFullPath, "rt");
    if (fp == NULL) {
        goto FINALLY;
    }
    while (fgets((char *)tempBuffer, MAX_PATH, fp)) {
        if (0 == strncmp(section, tempBuffer, strlen(section))) {
            memset(tempBuffer, 0, MAX_PATH);
            while (fgets((char *)tempBuffer, MAX_PATH, fp)) {
                if(tempBuffer[0] == '[') {
                    goto FINALLY;
                }
               
                if(0 == strncmp(keyName, tempBuffer, strlen(keyName))) {
                    char *p = (char*)tempBuffer;
                    p += strlen(keyName);
                    memcpy(string, p, strlen(keyName));
                    fclose(fp);
                    return;
                }
            }
        }
        memset(tempBuffer, 0, MAX_PATH);
    }
FINALLY:
    if (fp) {
        fclose(fp);
    }
    string = result;
}


USB Booting + XP Password 제거하기

NTFS가 인식되는 부팅 이미지 + USB Format Util 
Windows에 SAM 파일 찾아 주는 파일





warning: dereferencing type-punned pointer will break strict-aliasing rules

Wall로 Build 를 하는데 아래와 같은 워닝이 발생해서

warning: dereferencing type-punned pointer will break strict-aliasing rules

구글링좀 하고, 고치기 귀찮아서  MakeFile만 수정해서 올림
연구원 씨가 관심 있으면 고치겠지.....



The following short examples demonstrate my problem:

----Exhibit A
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int foo;
    int bar;
} item_t;

int return_item (void **item);

int return_item (void **item)
{
    void *mem;

    mem = malloc (1);
    if (mem) {
        *item = mem;
        return 0;
    }
    else
        return 1;
}

int main (int argc, char *argv[])
{
    item_t *item;

    if (return_item ((void **)&item) == 0) {
        printf ("%p\n", item);
        free (item);
    }

    return 0;
}

----Exhibit B
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int foo;
    int bar;
} item_t;

int return_item (void **item);

int return_item (void **item)
{
    void *mem;

    mem = malloc (1);
    if (mem) {
        *item = mem;
        return 0;
    }
    else
        return 1;
}

int main (int argc, char *argv[])
{
    item_t *item;
    void *item_temp;

    if (return_item (&item_temp) == 0) {
        item = item_temp;
        printf ("%p\n", item);
        free (item);
    }

    return 0;
}
----

The code is a generic example of the problem.  The real code that is
producing the problem is a hashing API which hashes (void *) and hence
uses (void **) as an out parameter type. 

Exhibit A produces a warning as follows:

[nodbug:mato]$ gcc -O2 -Wall -o aliasing-test aliasing-test.c
aliasing-test.c: In function `main':
aliasing-test.c:28: warning: dereferencing type-punned pointer will break strict-aliasing rules

I'm using gcc version 3.3.5 (Debian 1:3.3.5-13) but the problem persists
even when tested with GCC 4.x on newer systems.

Exhibit B is my proposed "fix".  Can anyone advise if the code in
Exhibit A is legitimate, i.e. whether or not it's really violating the
strict aliasing rules as defined by the C standard?  If not, then I
guess the warning is spurious and I can safely use the fix.

If the code is in fact violating the standard then feel free to
enlighten me how to fix it, since it seems like a legitimate thing to do
:-)

Thanks very much for any help,
귀차나서 그대로 긁어 왔습니다.

참고 : http://gcc.gnu.org/ml/gcc-help/2006-08/msg00236.html


음 문제가 되면 삭제 하겠습니다 훗..



Iimage 를 이용하여 jpeg 출력

참 쉽죠이잉 ~
wince5.0에서 10분이면 되는걸... !!
일 할때는 다른 사람의 경험을 존중하며 가장 손쉬운 방법을 찾는걸 우선 해야 할 것입니다.
고민 할껀 고민 해야겠죠

Windows CE 5.0이상에서 지원, Imaging관련 컴포넌트가 포함된 경우에만 동작
확인은 dll이 있는지 확인 해봐야함

기본적으로 지원하는 포맷은 jpg, png, gif, bmp 등이 있고 multiframe image(ani-gif)도 가능하며, 유저 코덱을 추가하면 다른 포맷도 사용 가능합니다.인코딩, 디코딩 가능하며, contrast, brightness, flip, clone, resize, rotate 등도 가능

일전 이미지 편집 프로그램을 windows mobile 5.0에서 간단한 이미지 편집 프로그램
작성시 해당 컴포넌트 이용, Thumnail 엔진도 이용함.

자세한 사항은 MSDN에서  http://msdn.microsoft.com/en-gb/library/ms932606.aspx 확인



1. 헤더, 라이브러리 추가

#include <initguid.h>
#include <imaging.h>
#pragma comment (lib, "Ole32.lib")


2. ImagingAPI를 사용하기 전후로 다음 함수 호출합니다.
   이유는 COM을 사용하기 때문이죠. 프로그램 시작/종료시에 한번만 호출 합니다.
  
 
    // 프로그램 시작부분에서 호출.
    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);   


    // 프로그램 종료부분에서 호출..
    CoUninitialize();   


3. 이미지파일을 읽어와서, hdc의 rcDest 영역에 display sample function


void DrawImageFile(HDC hdc, TCHAR* szFileName, RECT* prcDest)

{

    HRESULT hr;

    IImage *pImage = NULL;

    IImagingFactory *pImagingFactory = NULL;


    hr = CoCreateInstance(CLSID_ImagingFactory,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_IImagingFactory,
                          (void**) &pImagingFactory);

    if( FAILED(hr) ) {
 goto finish;
    }
 

    hr = pImagingFactory->CreateImageFromFile( szFileName, &pImage );

    if (FAILED(hr) || NULL == pImage) {
 goto finish;
    }

    pImage->Draw( hdc, prcDest, NULL );

finish:
    if (pImage) {                
 pImage->Release();
 pImage = NULL;
    }

    if (pImagingFactory) {
 pImagingFactory->Release();
        pImagingFactory = NULL;
    }
}


4. draw....

win32 api를 이용시...

    HDC hdc;
    PAINTSTRUCT ps;
    hdc = BeginPaint(hWnd, &ps);

    // 이미지가 보일 좌표
    RECT rectDest= {0,0,200,200};
    DrawImageFile(hdc, L"\\test.jpg", &rectDest);

    EndPaint(hWnd, &ps);



iimage도 잘 이용하면 더블버퍼링 처리가 가능 합니다.

hdc에 바로 그리지 말고, mem dc에 그린 후 hdc로 옮겨 그리면,
깜빡임 현상들을 제거 할 수 있습니다.

일단 샘플이니 간단하게 사용 해보셔요.



[warning]suggest parentheses around assignment used as truth value

워닝 발생

if ( x = getSomethingValue())
{
 ........
}

해결방법
if ( (x = getSomethingValue()) )
{
 ........
}

KIN.....



[보습학습] UTF-8

UTF-8유니코드를 위한 가변 길이 문자 인코딩 방식 중 하나로, 켄 톰프슨롭 파이크가 만들었다. 본래는 FSS-UTF(File System Safe UCS/Unicode Transformation Format)라는 이름으로 제안되었다.

UTF-8 인코딩은 유니코드 한 문자를 나타내기 위해 1바이트에서 4바이트까지를 사용한다. 예를 들어서, U+0000부터 U+007F 범위에 있는 ASCII 문자들은 UTF-8에서 1바이트만으로 표시된다. 4바이트로 표현되는 문자는 모두 기본 다국어 평면(BMP) 바깥의 유니코드 문자이며, 거의 사용되지 않는다. UTF-16과 UTF-8 중 어느 인코딩이 더 적은 바이트를 사용하는 지는 문자열에서 사용된 코드 포인트에 따라 달라지며, 실제로 DEFLATE와 같은 일반적인 압축 알고리즘을 사용할 경우 이 차이는 무시할 수 있을 정도이다. 이러한 압축 알고리즘을 사용하기 힘들고 크기가 중요할 경우 유니코드 표준 압축 방식을 대신 사용할 수 있다.

좀더 자세한 내용은 아래  wiki백과 사전에서.......

출처 :
http://ko.wikipedia.org/wiki/UTF-8



신입 OT에서 감명 받은 것!!! "altigenome"

사용자 삽입 이미지




오늘 신입 OT를 오전동안 가졌습니다.
회사에 대해서 여러가지를 소개 해주는 동안 그중에서 가장
눈길을 끄는 PT한장이 있었는데,  내용은 회사의 구성 요소를 영단어로 표현한 것이었습니다.

3. altigenome
경영이념 중 회사에 구성요소를 아래와 같이 3가지로
제품(Product),
사람(People),
프로세스(Process)를 중심 축으로 하여 우수한 유전자를 발굴하여 키우고 발전시켜 구성원 모두가 부유하고, 건강함, 재미 있고, 행복해하는 회사를 만들자는 의미임.
참으로 이상적인 문구였습니다. 그런 회사가 있을까요?

위에 박스 처럼 부유하고 건강하고 재미 있고, 행복한 회사를 만들어가기 위해서
분명 많은 사람들이 노력을 하고 있습니다. 저희 회사뿐만이 아니구요.

예전 ONOFF Mix 개발자 모임에서의 주제와 너무나도 흡사하습니다.
그 컨퍼런스의 가장 주된 테마는 Project, Process, Product, People였습니다.

OST라는 개념으로  각 테이블별 주제를 정하고, 사람들은 자신이 좋아하는 주제에 따라 마음데로 이동하여, 자신의 경험이나 지식을 공유하는 그런 열린 토론을 하고, 여러가지를 발표하던 개발자 모임이었습니다. 이러한 토론을 통해서 좀더 업무를 개선하고 삶의 질을 높이고자 하는 노력입니다.

요즘 처럼 IT인력이 부품화 되어가 가는 것은 비단 회사만의 문제는 아닐 것이라 생각합니다.
이런 환경을 바꾸지 않고 그저 묻어가려는 IT업을 하고있는 게으른 개발자가 더 큰 문제라고 생각합니다.

항상 학습을 통해 발전하려는 자세가 IT에서는 가장 중요한 것 같습니다. -0-


파일명, 라인정보를 보여주는 에러 메세지 박스 만들기
에러가 생겼을때 보통 메세지 박스로 어떤 에러인지 내용을 뿌려주죠..
근데 소스파일이 많아지면, 이게 어느 소스 파일의 어느 부분인지 금방
찾기가 힘들잖아요...

그런데 #define 스크립트를 이용하면 쉽게 파일명과 줄번호가 출력되는 메세제 박스를
만들 수 있습니다..
복사해다가 컴파일 해보시면 금방 어떤건지 알 수 있습니다..
설명없음 ^^;;
아마 윈도우용 컴파일러에서는 다 될거예여.


코드:
#include <stdio.h>
#include <windows.h>
#include <stdarg.h>
void ShowMessage(const char* strFormat, ...)
{
static char strBuff[512];
va_list args;
va_start(args, strFormat);
vsprintf(strBuff, strFormat, args);
va_end(args);
MessageBox(0, strBuff, "메세지", MB_ICONERROR);
}
#define SHOW_ERROR(Msg) {

ShowMessage("%s(%d) %s \n", __FILE__, __LINE__, Msg );
}




#define CHEAK_ERROR(Flg)
{
if (!Flg)
ShowMessage("%s(%d) %d \n", __FILE__, __LINE__, Flg );
}



int main()
{
char* s = NULL;
CHEAK_ERROR(s);
if (s == NULL)
{
SHOW_ERROR("에러!!! NULL이야~");
}
return 0;
}


* Ronie.Kang : 개인적으로는 Debug Level에 따라서 출력이 되도록 수정하는 것도 좋을 것 같습니다
                      또한 가변인자를 활용하여 여러가지의 값을 가지도록 만들어 보아요~!


error C2787: 'IContextMenu' : no GUID has been associated with this object
아래와 같은 문제로 인해서 문제가 발생 됩니다.
문제 해결 방법은 2가지가 있습니다.


1. 원론적 문제 해결 방법

------------------------------------------------------------------------------
>I am building a shell extn. project in .net ide which is
>converted from vC++ 6.00.
>
>During buid i am getting the following error
>"error C2787: 'IContextMenu' : no GUID has been associated
>with this object", The same project works fine in VC++6.0.
>
>I have included the following files also
>#include <shlguid.h>
>#include <shobjidl.h>
>#include <shlobj.h>
>
>any help will be appreciated

This is interesting. There are two <comdef.h> header files in VC.NET, one in
Vc7/include and the other in Vc7/PlatformSDK/include. The former splits off
the smart pointer typedefs into comdefsp.h, and it doesn't include
IContextMenu. The latter does. You can try to #include the PlatformSDK
header directly, change your INCLUDE path order, or supply the missing
typedef yourself, e.g.

struct __declspec(uuid("000214e4-0000-0000-c000-000000000046"))
IContextMenu;

_COM_SMARTPTR_TYPEDEF(IContextMenu, __uuidof(IContextMenu));

--
Doug Harrison
Microsoft MVP - Visual C++
------------------------------------------------------------------------------


2. 더 간단한 방법은...

------------------------------------------------------------------------------
The response is for people that find this thread by searching for the same error.

Just define at the top of the stdafx.h file above your includes:
#define _ATL_NO_UUIDOF
------------------------------------------------------------------------------


[링크]지적 호기심 없는 20대 노인들
점점 지적 호기심이 없어지는 개발자들....
놀랍게도 많은 분들이 ~ 보수적인 생각으로 새로운것을 받아 드리는데 거부감을 가지고
있다는 기사 내용이다.

한번쯤은 읽어 볼만한 글이 아닐까 생각 됩니다.




http://www.zdnet.co.kr/itbiz/column/anchor/hsryu/0,39030308,10061549,00.htm





P.s 독일 프랑크프르트에서,.....


BLOG main image
취미생활
 Notice
 Category
분류 전체보기 (191)
매일매일갱생 (83)
서버개발 (1)
임베디드개발 (12)
Programming (80)
Personal Projects (6)
유용한 프로그램 (0)
 TAGS
Error Case project spam mail isdbt Wince5.0 DirectShow VC++ Debug Windows Mobile6.0 영어 이메일 DVB MP3 출장 warning English debugging M480 Dshow DVB-T 미라지폰 서태지 퇴사 C++ Algorithm 티스토리 초대장 군대 It Linux 티스토리초대 english email 알고리즘 음식 C 벨소리 변경 개발자 ISDB-T Java 1seg Brazil
 Calendar
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 Recent Entries
 Recent Comments
 Recent Trackbacks
 Archive
 Link Site
zextor
괴짜 프로그래머의 일상사~@@
Gag & Peace, and more..
Kazakhstan Almaty.......
Min-A
Sadgarret
Steve Yoon's log
가슴 뛰는 삶을 살아라
오스틴 파워
GUI sin
melanie parker_Lady
제레미의 TV 2.0 이야기..
 Visitor Statistics
Total :
Today :
Yesterday :
rss