building zlib 1.2.7 (64bit) with Visual Studio 2012

1. Open a command line window

2. C:>\ "(visual studio install directory)\Microsoft Visual Studio 10.0\VC\bin\amd64\vsvars32.bat"

3. C:>\ set path="(visual studio install directory)\Microsoft Visual Studio 10.0\VC\bin\amd64\";%path%
This is to enable the system to find "ml64.exe" when we execute the next command

4. C:>\ cd "(zlib directory)\contrib\masmx64"

5. D:\zlib\> bld_ml64.bat
This batch file will compile two assembly files into corresponding object files: inffasx64.obj and gvmat64.obj. If you want to compile into 32bit library, just replace masmx64 with masmx32, and bld_ml64.bat with bld_ml32.bat.

6. Open "(zlib directory)\contrib\vstudio\vc10\zlibvc.sln" with VS2012, and choose to update the solution. Of course you can also use VS2010, but it may pop up an error saying "error LNK1123. failure during conversion to COFF". It is said that installing SP1
of VS2010 may solve it. But I didn't try.

7. Open the project property of "zlibvc" -> Build Events -> Pre-Build Event -> Command Line. Clean the "Command Line" field. You can see that the they are trying to execute the bld_ml64.bat file. But somehow it does not work. If you don't clean the command line, you will get an error when compiling, saying "bld_ml64.bat is not recognized as command or executable".

8. Modify "zlibvc.def" line 4 from "VERSION 1.2.7" to "VERSION 1.2". Visual Studio seems to support only "Major.Minor" version number. If you don't do this, you get a "LNK1118: syntax error in 'VERSION' statement" message.

9. Compile the solution.

10. Now you should have dll and lib files generated in "(zlib directory)\contrib\vstudio\vc10\x64\ZlibDllRelease". Include "zlib.h" and link to dll or lib files in your project, and you should be able to use zlib.


MK802是一个U盘大小的,使用android 4.0的mini pc,提供一个HDMI接口输出和两个USB接口,并通过一个DC转换器供电。

我是打算买来当播放器接电视用的。原来家里有个HTPC,用的是amd fusion,大小大概是20*20,但声音有点大。我想把这htpc找个柜子放起来,作为下载机和文件服务器,然后用MK802来播放HTPC上的电影。



稳定性: 昨天晚上开了一晚上,很稳定,没有死机现象,不过机器非常烫,不知道用久了会不会出问题。


控制:控制上不太好控制,只能用无线鼠标和无线键盘,用着很费劲,因为得一直抬着头看。昨天试图装vnc server,发现droid vnc server不能用,在pc能能登录,但是完全无法控制。droidmote也不能用,于是很杯具的只能使用无线鼠标。

视频播放:据说能放1080P,但是我没试。mk802有内置的2G空间,另外还可以装32G的SD卡。但我想放samba服务器上的视频,于是装了个cifsmanager,结果cifsmanager在ICS下还不能用。于是装es file explorer,然后很杯具的发现es file explorer居然不能用系统自带的那个有硬件加速的播放器来放视频,而mx player只能放rmvb之类的,4G的mkv放不了。。。


2012/08/01更新:现在Rev 2.0的firmware可以下载了,刷完以后,VNC Server和cifs manager能用了,不过market上还是有好些应用找不到,过几天再折腾

setting process affinity in windows in command line

If you need to bind a process to some specific cores, you can use the "Set Affinity" function in taskmgr.exe. Open task manager->processes->right click a process->set affinity.

However, if you want to set affinity in command line, you will need some tools. Here is a program I wrote to deal with this:

#include <iostream>
#include <sstream>
using namespace std;

#include <Windows.h>

int main(int argc, char ** argv)
        cout<<"usage: "<< argv[0] << " pid mask" <<endl;
        return 1;

    int pid = 0;
    istringstream sspid(argv[1]);
        cout<<"bad pid"<<endl;
        return 1;

    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
        cout<<"cannot open the process"<<endl;
        return 1;

    string mask_str = argv[2];
	DWORD_PTR mask = 0;
        cout<<"mask is too long: mask_size="<<mask_str.size()<<", sizeof(mask)="<<sizeof(mask)*8<<endl;
        return 1;

    for(int i=mask_str.size()-1; i>=0;i--)
        mask = mask<<1;
            mask |= 1;

    if( !SetProcessAffinityMask(hProcess, mask) )
        cout<<"error setting affinity mask: "<<mask<<endl;
        cout<<"error num: "<<GetLastError()<<endl;
        return 1;
    return 0;

Compile the code with Visual C++, and use it like this:
C:>\ setaffinity.exe [pid] [mask]

The mask is a binary number string. e.g. "1011" will bind the process to cores #0, #2 and #3.
For more information, check out my github project:

MIUI download icon won't go away issue [solved]

I flashed a MIUI rom on my HD2. One day I tried to use the browser on the phone to download an APK, but it failed. The download icon on the top left corner of the screen then sticks. I tried reboot, downloading the APK again, and clearing the browser data cache, none worked. Finally, I found a software called "Download Manager" in the applications. I cleared the data and cache of that software, and the download icon disappears.

simple command line timer for windows

I have just switched to working on Windows. And I found that there is no such thing as the time command line tool in Linux. So I decided to write one myself. I don't need many features. Counting the number of seconds a command takes is enough. I used the QueryPerformanceCounter() function to get the accurate time. So it is not portable to Linux or other platforms.

Anyone who is interested can modify the code at its own will. But I would appreciate it if you can give me your improved version of the code. I have also attached a compiled version. It works on Windows Server 2008 R2 and Windows 7. Other Windows versions are not tested.

Use it like this:
C:\> timer command [arguments]

It gives:
[command outputs]...
time elapsed: 0.123s


Source code:

#define NOMINMAX
#include <windows.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

double gettime(){
	return (double)nTime.QuadPart*1000/nFreq.QuadPart;

int main(int argc, char ** argv){
	if(argc<2 || argc>=2 && string(argv[1])=="--help"){
		cout<<"This is a very very simple timing tool by hjk41."<<endl;
		cout<<"Use it this way: "<<endl;
		cout<<"\tC:\\>"<<argv[0]<<" command [arguments]"<<endl;
		return 0;

	double start=gettime();

	string cmd=argv[1];
	for(int i=2;i<argc; i++){
		cmd= cmd+" "+argv[i];

	double end=gettime();
	double exe_time=(end-start)/1000;

	cout<<"time elapsed: "<<exe_time<<"s"<<endl;

	return 0;

Chinese Edition, ignore this if you cannot read Chinese. :-)

C:\> timer 命令 [参数]

time elapsed: 0.123s


上面有源码。你可以随便改,但是如果有什么改进,希望你能告诉我,我好更新一下。 :-)

android market force close on Typhoon CM7 firmware v3.4.2

After a clean install of Typhoon CM7 v3.4.2 on HD2, I found that android market always force closes. A brief search on the Internet indicates that market works well with v3.4.1, but force closes on v3.4.2. Then I found the following solution on xda-developers:

With a rooted rom:
1) open a terminal emulator
2) su
3) chmod 777 /cache

Then everything works well.

starting / stopping service in windows using command line

In Linux, you typically use "service stop xxx" or "/etc/init.d/xxx stop" for this purpose.

Here is the equivalent on windows:
net stop xxx

You can also start a service using:
net start xxx

However, there is no such thing as "net restart". So you have to do it manually by stopping and then starting the service.

list logged-on users in windows

In Linux, we do that with "w" or "who". In windows, we can use "query session".

杯具,在M8上装上了M9 ROM,然后屏幕失灵了


今天给M8装了个M9 ROM,跟HD2装android原理一样,估计就是拿HD2那个loader弄的。开机发现界面挺漂亮,是我见过的android界面中最漂亮的一个。杯具的是,屏幕在这个时候失灵了。



贴个非常牛x,非常快的HD2 android



不管怎么样,强力推荐这个版本:darkstone SuperRAM FroYo



似乎要翻墙 ;-(