Category Archives: Programming

Solution to missing mkstemp when you are compiling under mingw

I googled around, doesn’t find a perfect solution. But I do come across 2 files on apple website, they actually implement the missing functions while dealing with the code ported to mingw.

For my scenario, I simply created a compiler based branch:
#if defined(__MINGW32__)

int mkstemp(char *template)
char *filename = mktemp(template);
if (filename == NULL)
return -1;
return open(filename, O_RDWR | O_CREAT, 0600);


I also downloaded and attached here in case could be useful later:

Datetime::Now is high precision time

You can get the high precision time with Datetime::Now, instead of with complicated: QueryPerformanceCounter
The test code is:

for (int i=0; i< 20; i++)

And this is the output:
datetime now ticks
It is precise to the 100 nanosecond as you can see from the above image.

Quick reference code to convert C# RectangleF to Rectangle

Quick code here for you to copy and paste in your work, so save you from some typing:

public static Rectangle ConvertToRectange(RectangleF rectanglef)
return new Rectangle(

a daily life issue with svn

First of all, I just want to describe the problem here, I don’t have an answer.
Svn is a great tool to keep the version of changes, despite of all the greatness, there is an inconvenient issue when you committed to put it into heavy daily use. It doesn’t do well in this specific scenario:
If you want to rename a file, move it to a different folder or delete a file, you can easily do it in your ide or file explorer, just 1 or 2 clicks of mouse away. But then the svn lost the track of these file name based changes.
On the other hand, even when you feel the need to do these file name based changes, you operate on the svn directly, then you will make the project specific solution file outdated, in the case of C#, it is csproj.

In both cases, you have to redo the work manually on the other one to get updated.

Hopefully, there could be a solution here.

Maybe, a way to go is to let tortoiseSVN monitor the changes relate to the file name, then it adds the commands of changes to the pending commit list, the same way as it deals with the content changes inside a file.

compile lame as dll from command line with nmake

here is the command line without nasm:
d:\source\lame-3.99.5>nmake libmp3lame.dll -f makefile.MSVC CPU=P3 asm=no

If you have the nasm installed: (good to have the asm optimization)
d:\source\lame-3.99.5>nmake libmp3lame.dll -f makefile.MSVC CPU=P3

and nasmw is now nasm in case you are looking for it but failed. Simply rename it if it is really needed.

lesson learned, mystery of bitmap file format

windows bitmap file format doesn’t come with line stride with it, but it requires a padding to make each scan line end at 4 boundary.

Here is the doc detailed the issue:
Uncompressed data is a series of values representing either color palette indices or actual RGB color values. Pixels are packed into bytes and arranged as scan lines. Each scan line must end on a 4-byte boundary, so one, two, or three bytes of padding may follow each scan line.

web resource of ascii art – an powerful editor&converter – Make big ascii art text based on ordinary text, it is font driven to map input to the result – ascii art lib – ascii art lib with the color – codeproject article on ascii art generator

convert between .net String^ to char *

String^ => char *
//using namespace msclr::interop;
String^ dotnetStr = "convert .net string to c++ string";
marshal_context ^ context = gcnew marshal_context();
const char* cppStr = context->marshal_as(dotnetStr);
delete context; // the native pointer of cppStr only valid until this line, memory will released after delete

char * => String^
char *cppStr = "convert c++ string to .net string";
String^ dotnetStr = gcnew String(cppStr );


//using namespace msclr::interop;
char *cppStr = "convert c++ string to .net string";
String^ dotnetStr = marshal_as( cppStr );