Pinyo's Programming and Software Notes

Friday, June 30, 2006

Linking problem for inline function
(June 30, 2006)

Sometimes, we find a linking problem with inline functions. The problem happens because code generator do not expand the inline functions in descendant classes. To solve the problem, we have to make the inline function virtual. Then, there will be an implicit declaration and expansion for the virtual inline functions in every descedant class. It is worth noting that this compiler behavior may belong to Visual C++ only. Other compilers, such as gcc, may not have this problem.

Wednesday, June 28, 2006

Java "cross platform" new-line character:
(June 28, 2006)

Since "\n" may not be accepted as a new-line character in some Windows applications, such as Notepad, we should find an easy way to get the corresponding new-line character for each platform. Java provides us a function for this. We can obtain the corresponding new-line character as follows:
final String newline = System.getProperty("line.separator");

Message Box in MFC application
(June 28, 2006)

It is easy to invoke a message box in an MFC application.
The following code snippet is for error message:
MessageBox("Help, Something went wrong.", "Error",
MB_ICONERROR | MB_OK);

The message box is an instance of CWnd::MessageBox .
For more informateion: http://msdn2.microsoft.com/en-us/library/0eebkf6f.aspx

Play sound in Windows C++
(June 28, 2006)

To play a wav file, we can use PlaySound function. This function is provided as a part of Windows Platform SDK: Windows Multimedia (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/multimed/mmfunc_9uxw.htm).

To play sound asynchronously, we may code
PlaySound( "D:/begin.wav", NULL, SND_FILENAME | SND_ASYNC );.
It is important to note that the declaration of the function is in #include "Mmsystem.h", and the library we need is
Winmm.lib. To include the library in Visual Studio .Net 2003, we can go to Configuration Properties::Linker::Command Line. Then, specify the library name by typing the name in "Addition Options" (say winmm.lib in the box, that's it).

Saturday, June 17, 2006

Good Free/Open-source Software
(June 16, 2006)

This blog is intended to keep a link to good free/open-source software that may not be very famous.

1. Open Workbench: MS Project Alternative.
This tool looks really polished. It can be a good project management software.
http://www.openworkbench.org/

2. FreeMind: mind-mapping software
This software makes a graphical presentation of concepts and their relationship. Sometimes, the presentation is referred to as a knowledge map. A knowledge map can show elaboration of types. For example, if we want to talk about differential equations, we will find that there are many types of differential equation. Starting from ordinary and partial differential equations, we can further elaborate that ordinary differential equations consists of the first-order and the higher-order differential equations. They can also be classified as linear and non-linear. They can also be discussed by methods for solving differential equations. A knowledge map can give us a big and quick overview of a complex concept to make it easy to organize our idea for a certain concept.
It is also used for brainstorming as discussed here.
http://freemind.sourceforge.net/wiki/index.php/Main_Page

Sunday, June 04, 2006

Resource file linking problem in Visual C++
(June 4, 2006)

Today, I build a static libary that make use of another static library. If we do it directly, there will be a linking problem. This linking problem is something as follows:
fatal error LNK1241: resource file NVKernelMp.res (NVKernelMp) already specified
This problem can be fixed easily if we just do not produce additional resource file in the dependent static library. In Visual Studio 2003, we can go to 'Project Properties'. Then, go to Configuration Properties::Resources::General. In Resource File Name, we delete it and set Culture to 'Inherit from project default'.

Saturday, June 03, 2006

Static variable in VC++
(June 3, 2006)

Static constant variables and static variables have different initialization. For static constants, we do not initialize it again in source code outside header, but, for static n0n-constants, we need to initialize it in global area. If we try to initialize static constants in the global area, we will have a linking problem. The compiler will consider another initialization as a duplicate.

Friday, June 02, 2006

Embeded Movie via pdflatex
(June 2, 2006)

I found a way to make my PDF file movie capable via pdflatex. This information is available at http://darkwing.uoregon.edu/~noeckel/PDFmovie.html. The output will embed a movie into a PDF output automatically, making it very convinient to distribute the PDF file and movie.

In the above webpage, it's actually rely on a public package called movie15 (I have no idea why it must be 15 though). The package is available at CTAN website: http://www.ctan.org/tex-archive/macros/latex/contrib/movie15/.

To make it easy for future reference, I send important files into my gmail account. The mail header is Embeded Movie in pdflatex.

Thursday, June 01, 2006

Optimization in VC++ .Net
(June 1, 2006)

Visual C++ .Net has options for SSE, SSE2 optimization.
To squeeze the best performance from our code, we should
  1. Compile for Pentium 4 and above (Go to C/C++ :: Optimize for Processors :: Pentium 4 and above / G7).
  2. Use enhanced instruction set (Go to C/C++ :: Code Generation :: Enable Enhanced Instruction Set :: Streaming SIMD Extension 2 (/arch:SSE2) ).
To check if our computer can make use of SSE2 or not, we can use CPU-Z.
See more info at http://pinyotech.blogspot.com/2006/06/cpu-z-june-1-2006-cpu-z-is-software.html.

CPU-Z
(June 1, 2006)

CPU-Z is a software that can show us hardware details, especially CPU, mainboard, and memory.
It is freeware available for download at http://www.cpuid.com/cpuz.php.

The great side is that we do not need to install this software before we can use it.