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

COM Port Programming in Win32

Posted on

The control support for the COM port under Win32 can be used to operate the COM port, such as a monitoring and control program for a single-chip microcontroller. Below is an example code related to COM port control: // Open COM1 hCOM=CreateFile( “COM1″,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if (hCOM==INVALID_HANDLE_VALUE) { MessageBox( GetForegroundWindow(),”Can not open the COM port!”,”Operation Failed”,MB_ICONINFORMATION); return;
Read more

禁止对话框关闭按钮和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

Micosoft招聘部分算法题

Posted on

Micosoft招聘部分算法题 1.链表和数组的区别在哪里? 2.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法? 3.编写实现数组排序的一种算法。说明为什么你会选择用这样的方法? 4.请编写能直接实现strstr()函数功能的代码。 5.编写反转字符串的程序,要求优化速度、优化空间。 6.在链表里如何发现循环链接? 7.给出洗牌的一个算法,并将洗好的牌存储在一个整形数组里。 8.写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整形的函数?) 9.给出一个函数来输出一个字符串的所有排列。 10.请编写实现malloc()内存分配函数功能一样的代码。 11.给出一个函数来复制两个字符串A和B。字符串A的后几个字节和字符串B的前几个字节重叠。 12.怎样编写一个程序,把一个有序整数数组放到二叉树中? 13.怎样从顶部开始逐层打印二叉树结点数据?请编程。 14.怎样把一个链表掉个顺序(也就是反序,注意链表的边界条件并考虑空链表)? 来源:·日月光华 bbs.fudan.edu.cn

Inputting and Outputting Hexadecimal Integers with iostream in C++

Posted on

In C++, integer values can be represented in different formats, including decimal, binary, and hexadecimal. Hexadecimal is a base-16 numbering system that uses 16 digits, from 0 to 9 and from A to F. In this post, we will explore how to input and output hexadecimal integers using iostream in C++. Outputting Hexadecimal Integers To
Read more

4 Ways of Converting String to Int in C++

Posted on

It is common to convert a string (std::string) to integer (int) in C++ programs. Because of the long history of C++ which has several versions with extended libraries and supports almost all C standard library functions, there are many ways to convert a string to int in C++. This post introduces how to convert a
Read more

MFC程序使用系统风格界面

Posted on

VC6默认编译出来的程序在XP下Luma风格下运行也是Windows的经典界面, 有损界面的美观与统一. VC2008默认设置下如果不是使用的unicode也是如此. 本文给出使VC6和VC2008可以编译出使用系统界面风格的解决方案. 1. 使VC6编译出使用系统风格的程序 步骤如下: 1) 创建一个.manifest文件的资源. 在res/文件夹下创建一个跟以程序名加.manifest的文件, 如果程序为test.exe, 则创建test.exe.manifest 文件可由此下载: https://www.systutorials.com/t/g/programming/resultcollector.manifest/ 注意要使用utf-8编码保存。 2) 将新定义的资源加入到.rc2文件中, 类型设为24. 打开res/文件夹下的.rc2文件, 在其中加入如下定义: 1 24 MOVEABLE PURE “res/test.exe.manifest” 其中的文件地址按1)步中修改的设置即可. 之后编译即可, 为了使程序界面可能充分利用系统的界面特性, 可以将界面字体设置为TrueType类型的, 利用Windows XP等系统的屏幕字体平滑特性. 2. 使VC2008编译出使用系统风格的程序 在VC2008下就比较简单了, 如果程序字符集使用unicode则默认就是使用系统界面风格的, 如果选择其它的类型, 则编辑下stdafx.h即可. 最后面部分找到这么一段: #ifdef _UNICODE #if defined _M_IX86 #pragma comment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′ processorArchitecture=’x86′ publicKeyToken=’6595b64144ccf1df’ language=’*'””) #elif defined _M_IA64 #pragma comment(linker,”/manifestdependency:”type=’win32′
Read more

Java Calling Native Functions in .DLL on Windows

Posted on

How to call a function in .dll from Java on Windows is introduced in this post with an example. Platforms used: OS: Microsoft Windows XP [5.1.2600] C to .dll compiler: MS Visual Studio 2008 JDK: java -version java version “1.6.0_05” Java(TM) SE Runtime Environment (build 1.6.0_05-b13) Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
Read more

How to Connect to MySQL in JSP

Posted on

We use tomcat as the container used for instructions in the post. 1) Download the driver mysql-connector-java-*.*.*-bin.jar and put it into WEB-INF/lib/, and remember to restart tomcat. 2) The example code as follows. String driverName=”com.mysql.jdbc.Driver”; String userName=”username”; String userPasswd=”password”; String dbName=”dbname”; String tableName=”tablename”; String url=”jdbc:mysql://localhost/”+dbName+”?user=”+userName+”&password=”+userPasswd; Class.forName(“com.mysql.jdbc.Driver”).newInstance(); Connection conn=DriverManager.getConnection(url); Statement statement = conn.createStatement(); String sql=”SELECT *
Read more

An Online JPG to EPS Converter

Posted on

Converting the JPG images to EPS is frequently need especially when write documents in LaTeX. I introduced how to Convert JPG Images to EPS on Linux. However, not everyone have a Linux box available at any time. We set up an Online JPG to EPS Converter to help people convert JPG to EPS. Convert JPG
Read more

How to Generate and Apply Patches using diff and patch on Linux

Posted on

`diff` and `patch` are tools to create patches and apply patches to source code, which is widely used in the open-source world, such as Linux kernel and application. patch: applying patches To apply a patch to a single file: $ patch < foo.patch If the foo.patch does not identify the file the patch should be
Read more

Online Tutorials for Linux Beginners

Posted on

This post compiles a list of tutorials on the Internet for Linux beginners. Linux beginners usually get headache from the “seemed” complexity of the Linux operation system. But once they get into the gate and get familiar with Linux, they will love it. UNIX Tutorial for Beginners “A beginners guide to the Unix and Linux
Read more