Archive for the ‘C/C++/C#’ Category

QTAudioFrequencyLevels and variable length array in a structure

QuickTime API내에서 사용되는 structure 중 AuidoFrequencyLevels라는 것이 있다. 이것은 다음과 같이 생겼다.

struct QTAudioFrequencyLevels {
UInt32 numChannels;
UInt32 numFrequencyBands;
[...]

Continue reading »

OpenSSL : Decryption

어제 올린 포스트에서 언급했듯이, 오늘은 Decryption 쪽을 포스팅해본다. 오늘 올릴 소스코드는 완전한 것이 아니라, 어떤 method의 한 부분을 보여주는데, 적어도 OpenSSL의 함수를 사용하는 부분에 대해서만은 완전한 소스의 형태를 갖추고 있다.

const char *validationRawData = [validataionData bytes];
if( validataionData )
{
int validationLength = [validataionData length];
int totalLength = 0; // For decrypted length

int result = 0;
unsigned char inputBuffer[8], outputBuffer[8];
int inputLength [...]

Continue reading »

How to use DES in OpenSSL library?

Well, I would like to use DES or BASE64 which are symmetric, i.e. encryption of a plain text produces a cypher text, and description of the cypher text produce the original plain text.
However, only by reading its MAN page, it turned out to be very very very difficult to understand and use it.
Even at the [...]

Continue reading »

Back to basic : overriding vs. overloading

OK. My original “back to basic” post turned out to be very popular. Not a few people have visited this blog due to the “Pointer to Array vs. Array of Pointer, and the most dynamic array” post.
So, :) I would like to write one more thing about “basic”.
How many Korean visitors to my blog can [...]

Continue reading »

Why MFC is bad

Well, MFC has lots of weird aspects. Basically MFC is a framework. What is a framework? Framework is a wrapper of API to make the API easier to use.
However, when MFC is compared to ToolBox which was most popular during similar period of time, MFC is not as easy to use as ToolBox. ToolBox is, [...]

Continue reading »

About BOOL, BOOLEAN and bool on Windows

Well, this was what I wondered when I used MFC/Win32 a lot when I was a sophormore. Why are there so many boolean type on Windows? And why did people at MS made such many boolean type? Well, actually they are not new. They are just alias of int and char, or BYTE.
In C, there [...]

Continue reading »

TerminateThread() and its consequence (Windows)

Usually when it is required to quit a thread from outside of its thread function, you declare a variable like shouldQuit, and it checks if the shouldQuit is set inside of the thread function. From outside of the thread function, you set the shouldQuit to tell the thread to quit.
However, if a function in a [...]

Continue reading »

Setting a name to a thread (MSDN)

It is pretty hard to identify threads when you debug codes.
So, for the Visual C++, MSDN says there is a way to set a name to a thread.
Here is the codes from MSDN.

//
// Usage: SetThreadName (-1, "MainThread");
//
#include <windows.h>
#define MS_VC_EXCEPTION 0×406D1388

#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0×1000.
LPCSTR szName; [...]

Continue reading »

#define, const global variable and enum

There are 3 ways to define integer values for certain setting.
We are going back to freshman class. :)
For example, let’s assume this case.

switch( videoFormat )
{
….
}

How to define values which are set to videoFormat variable?
There are 3 ways to do so.

#define
enum
const global variable

I found out that people use #define a lot. I [...]

Continue reading »

C++ coding style: Convenience vs. Understandability

You know a coding pattern for writing a smart pointer. Because it is easy to forget to free some memory space which is created in a function, Creating a dynamic memory space with help of static typing is the basic idea.
For synchronization, the same pattern can be used.

class C_CRITICAL_SECTION : public CRITICAL_SECTION
{
public:
[...]

Continue reading »