Makefile Tutorials

Posted on

Make is a utility that automatically builds executable programs and libraries from source code by reading files called makefiles which specify how to derive the target program. Make is widely used, especially in Unix/Linux world. More introductions to Make and it’s history can be found on Wikipedia. In this post, I list articles for Makefile
Read more

Hashing Library for C

Posted on

I try to find some Hashing libraries for C and find several good ones. The hsearch function in the GNU C library. There are other methods to organize information which later should be searched. The costs of insert, delete and search differ. One possible implementation is using hashing tables. The following functions are declared in
Read more

x86-64 ISA / Assembly Programming References

Posted on

This post collect the reference resource for x86-64 (also know as Intel 64, AMD 64) ISA / assembly language programming. x86-64 is a 64-bit extension of the Intel x86 instruction set. ==x86-64 Assembly Programming== Introduction to Computer Systems Resources (15-213 Introduction to Computer Systems Resources from CMU) Lots materials for learning machine-level programming on the
Read more

Inline Assembly with GCC on Linux

Posted on

One cool feature of gcc is that it can inline assembly into C code. With inline assembly, the programmer can precisely control the execution of the processor, such as forcing variables to use registers, getting special processor state efficiently, and writing critical efficient code in assembly by hand. I compile a list of tutorials from
Read more

GNU C Reference Manual

Posted on

When we program in C, a C reference by hand is usually useful. The GNU C Reference Manual provides us a good reference for the C programming language implemented by the GNU C Compiler. “This manual is strictly a reference, not a tutorial. Its aim is to cover every linguistic construct in GNU C.” GNU
Read more

fclose – Close a Stream

Posted on

fclose is a frequently used C standard library which closes the file associated with the stream and disassociates it. NAME fclose – close a stream SYNOPSIS #include <stdio.h> int fclose(FILE *fp); DESCRIPTION The fclose() function will flushes the stream pointed to by fp (writing any buffered output data using fflush()) and closes the underlying file
Read more

GNU glibc Manual

Posted on

“The C language provides no built-in facilities for performing such common operations as input/output, memory management, string manipulation, and the like. Instead, these facilities are defined in a standard library, which you compile and link with your programs. The GNU C library, described in this document, defines all of the library functions that are specified
Read more

Win32下COM口通信控制

Posted on

这段时间做兼职帮做了一个COM口单片机监控控制程序, 学习了些Win32下COM口的控制. 下面是与COM口控制有关的部分示例代码. //打开COM1 hCOM=CreateFile( “COM1″,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if (hCOM==INVALID_HANDLE_VALUE) { MessageBox( GetForegroundWindow(),”无法打开串口!”,”操作失败”,MB_ICONINFORMATION); return; } //设置DCB DCB dcb; if (!GetCommState(hCOM,&dcb)) { MessageBox( GetForegroundWindow(),”无法获取串口状态!”,”操作失败”,MB_ICONINFORMATION); hCOM=INVALID_HANDLE_VALUE; return; } dcb.BaudRate=9600; dcb.ByteSize=8; dcb.Parity=NOPARITY; dcb.StopBits=ONESTOPBIT; if (!SetCommState(hCOM,&dcb)) { MessageBox( GetForegroundWindow(),”无法设置串口状态!”,”操作失败”,MB_ICONINFORMATION); hCOM=INVALID_HANDLE_VALUE; return; } //设置COMMTIMEOUTS COMMTIMEOUTS communication_timeout; communication_timeout.ReadIntervalTimeout=MAXDWORD; communication_timeout.ReadTotalTimeoutMultiplier=0; communication_timeout.ReadTotalTimeoutConstant=0; communication_timeout.WriteTotalTimeoutMultiplier=0; communication_timeout.WriteTotalTimeoutConstant=0; if (!SetCommTimeouts(hCOM,&communication_timeout)) { MessageBox( GetForegroundWindow(),”无法设置串口超时!”,”操作失败”,MB_ICONINFORMATION); hCOM=INVALID_HANDLE_VALUE; return; } //向串口写入ABC三个字符 ULONG nBytesWritten;
Read more

How to Generate Mixed Source and Assembly List from Source Code using GCC

Posted on

When debugging and optimizing programs, developers sometimes need to generate and investigate into the assembly generated by the compiler. Generating a mixed source and assembly list will help a lot for debugging and optimization. gcc can achieve this by working with the assembler. Generate assembly list mixed with the source code Just add these gcc
Read more

使用选择文件夹对话框

Posted on

这是如何在VC下使用选择文件夹对话框,返回文件夹的地址的代码: CString BrowseDirectory( LPCTSTR title ) { char dir[MAX_PATH]; dir[0]=’0′; BROWSEINFO bi; bi.hwndOwner=NULL; bi.pidlRoot=NULL; bi.pszDisplayName=dir; bi.lpszTitle=title; bi.ulFlags=0; bi.lpfn=NULL; bi.lParam=NULL; bi.iImage=NULL; SHGetPathFromIDList(SHBrowseForFolder(&bi),dir); return dir; }

禁止对话框关闭按钮和Alt+F4

Posted on

在某些情况下我们需要防止用户单击窗口的标题栏中的关闭按钮关闭 MFC 应用程序。可以删除窗口的WS_SYSMENU 样式, 但是,这样最大化最小化和还原按钮也被删除,并且无法添加。 这是Windows的设计依据。 可以通过禁用关闭按钮来模拟没有关闭按钮的窗口。 在 WM_CREATE 消息处理程序中禁用关闭按钮。使用下面的代码: CMenu *pSysMenu = GetSystemMenu(FALSE); ASSERT(pSysMenu != NULL); VERIFY(pSysMenu->RemoveMenu(SC_CLOSE, MF_BYCOMMAND)); 这样删除之后关闭按钮变为灰色,用户无法点击。但是使用Alt+F4仍然可以关闭程序。要将此功能也禁用需要重载CDialog的OnSysCommand方法。代码如下: void MyDlg::OnSysCommand( UINT nID, LPARAM lParam ) { if ( ( nID & 0xFFF0 ) == IDM_ABOUTBOX ) { CAboutDlg dlgAbout; //if you have an about dialog dlgAbout.DoModal(); } //add the following code else if
Read more

使用MFC在一对话框中嵌入另一对话框

Posted on

全文介绍如何使用MFC在一对话框中嵌入另一对话框. 代码如下: static MyInDlg inDlg; // 需嵌入的对话框 inDlg.Create( IDD_DIALOG, AfxGetApp()->m_pMainWnd); CRect rc; // 嵌入对话框在原对话框中的位置 //GetClientRect(&rc); rc.left = 150; rc.top = 0; rc.bottom = 200; rc.right = 350; inDlg.MoveWindow( rc ); // 设置位置 inDlg.ShowWindow( SW_SHOW ); // 将对话框显示出来 对嵌入对话框设置如下: Style: Child Border: none

OCaml Learning Materials

Posted on

OCaml is an interesting functional language. There are lots learning materials on the Internet. I compile a list of resources for OCaml learning and reference. Recommended OCaml learning and reference material Online book of Real World OCaml by Yaron Minsky, Anil Madhavapeddy, Jason Hickey. A very good tutorial by Jason Hickey: http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf. The OCaml system
Read more