You are currently browsing the archives for the windows category


Visual Basic script – Applying a formula across a column

This VB script computes a formula accross a column and writes the formula on a range of cells in another column of an Excel file. It can be very useful to compute average / min / max of collection of numbers. Example is demonstrated:

RAW   Average
Index Value   Index Value (AVG)
1 21.95   1 22.73
1 21.21   2 21.82
1 25.02   3 20.91
2 23.66      
2 21.19      
2 20.63      
3 23.31      
3 19.59      
3 19.83      

To apply the script, first select the first cell where the formula should be written.

Sub ComputeAndWriteFormula(formulaName As String, sheetName As String, column As String, startRow As Integer, endRow As Integer, step As Integer)
' This function adds formula starting from starting from the current cell
' The formula will be build in the following way.
' =Formula(Sheet!Column<number>:Column<number+step>

    Dim sheet As String
    Dim formula As String
   
    If Len(sheetName) = 0 Then
        sheet = ""
    Else
        sheet = sheetName + "!"
    End If
   
    For ind = startRow To endRow Step step
        Dim startCell As String
        Dim endCell As String
        Dim endCellRow As Integer
        endCellRow = ind + step - 1
        startCell = column + Trim(Str(ind))
        endCell = column + Trim(Str(endCellRow))
        formula = "=" + formulaName + "(" + sheet + startCell + ":" + endCell + ")"
        ActiveCell.formula = formula
        ActiveCell.Offset(1, 0).Select
    Next
End Sub

Sub TestComputeAndWriteFormula()
    Call ComputeAndWriteFormula("AVERAGE", "raw", "E", 2, 313, 3)

End Sub

Hamachi Bug Is Causing DNS Problems

I have installed hamachi on my windows 7. When I change my network adapter, after a while my computer cannot resolve DNS addresses. For example, at home I use WiFi. I suspend my computer and go to the office. At work I connect to the wired Ethernet connection (i.e. change the network adapter) and after a while my system is unable to resolve DNS addresses.

Solution for this is either to reboot the computer or disable the hamachi adapter from Network Connections (Control Panel\Network and Internet\Network Connections).

Toolbars are unwanted software

I absolutely hate all toolbars and here I made a list of these impertinent toolbars which you should stay away of using. These toolbars are absolutely unnecessary and don't do anything but cluttering your browser space and probably showing you pages that you don't want to see. This is my campaign against these toolbars.

Name URL Comment
Productivity Toolbar 2.2 http://www.conduit.com/ I have downloaded this from a huge image ad with "Download" word. I thought that I am downloading some another software.
Bearshare http://www.bearshare.com/ My brother had this installed in his computer with the stupid intend to find free music. I don't know how he got it but I found it to not be useful because it was making forwards to their internal pages for search etc. 

C# application for IBM/Lenovo Thinkpad Temperature and Fan Sensors

I have soon implemented a C# application that reads and displays the temperature and fans sensors in IBM/Lenovo Thinkpad laptops. You can download it from http://www.feradz.com/resources/CpuTemperature-20110112.zip. It is free and open source (GPL v3.0).

Compatible with:

  • ThinkPad A31
  • ThinkPad R51
  • ThinkPad T40
  • ThinkPad T43, T43p
  • ThinkPad T60
  • ThinkPad T61
  • ThinkPad T61p
  • ThinkPad X31
  • ThinkPad T400
  • ThinkPad T400s
  • ThinkPad T500

  

WebCam A4Tech Drivers (PK-35N, PK-635, PK-935)

I am uploading my old webcam's drivers so that I can find them easily when I need them and also those who lost their drivers:)

WebCam A4Tech Drivers (PK-35N, PK-635, PK-935)

Hamachi Bug – DNS problem in windows

I have installed hamachi on my windows 7. When I change my network adapter, after a while my computer cannot resolve DNS addresses. For example, at home I use WiFi. I suspend my computer and go to the office. At work I connect to the wired Ethernet connection (i.e. change the network adapter) and after a while my system is unable to resolve DNS addresses.

Solution for this is either to reboot the computer or disable the hamachi adapter from Network Connections (Control Panel\Network and Internet\Network Connections).
 

Convert (Export) Excel Chart to EPS Using Adobe Postscript

You may need to export a nice chart from Excel to EPS so that you include it in your Latex project. Here is one way how you do it.

1. You need to install Adobe Universal PostScript Windows Driver Installer 1.0.6 (or newer). If you have Vista or Windows 7 or some newer version run the installer with compatibility for Windows XP SP3.

– To set the compatibility for the installer, right click the file and select "Properties". Then from the "Compatibility " tab select "Run this program in compatibility mode for:" and select "Windows XP (Service Pack 3)"

 Select Compatability Mode

2. Open your Excel File.

3. Select your chart.

4. Select from the (File) menu print

5. Select the Adobe printer in my case this is "Generic PostScript Printer"

6. Ensure that "Select Chart" is the selected option in "Print what" area. If you did not selected the chart then this will option will not be selected. Go to Step 3.

7. Select print to file check box.

8. Go to Properties

Print Dialogue Box

9. In the properties dialog window select "Layout" tab then press "Advanced" button

10. In the Advanced properties dialog window, under the node "Postcript options:" select "Encapsulated Postscript (EPS)"

11. In the printer dialogue window, when you press "Print" you will be asked for the file name to be saved. You are not asked ensure that you have selected "Print to file" Step 7. Write the path and the file name something like "c:\chart.ps". If you don't include the full path I don't know where the file will be saved by default.

12. Use ps2eps to convert the saved PS format file into EPS format.

Translating Instruction Address to Source Line

In this article I will describe how to programmatically translate an instruction address from a Win32 executable to a source line. The described approach uses the Microsoft debugger engine dbgeng.dll. Therefore you should have it installed. If you don’t have it, you can download and install the Windows debugger WinDbg which will install dbgeng.dll.

Requirements

To use this approach you will need to have installed windows debugger engine – dbgeng.dll. If you don’t have it, install WinDbg debugger. This will install dbgeng.dll

Approach

Many debuggers support debugging at source code level. The debugger is capable to provide debugging at the source level by translating instruction addresses to lines in source code files. In our approach we use the same mechanisms that debuggers use. This particular solution, to translate an instruction address to a source line, uses functionality provided by the windows debugger engine dbgeng.dll.

In overview, we create a process from the Win32 executable file from which we want to translate instruction addresses. Then we attach the debugger engine to the created process. To create a process and attach the debugger to it we use CreateProcessAndAttach function. When the debugger is attached, we call function GetLineByOffset to do the actual translation. After we finish with the translation task we terminate the process with the function TerminateCurrentProcess. Besides these procedures there are few more things that are necessary to do which I explain in the implementation.

Implementation

First we create objects that implement the following COM interfaces: IDebugControl , IDebugClient, IDebugSymbols. To create these objects we use function DebugCreate.

static IDebugClient5 *dbgClient5 = NULL;
static IDebugSymbols *dbgSymbols = NULL;
static IDebugControl *dbgControl = NULL;
...
DebugCreate(__uuidof(IDebugControl), (void**) & dbgControl);
DebugCreate(__uuidof(IDebugClient), (void **) & dbgClient5);
DebugCreate(__uuidof(IDebugSymbols), (void **) & dbgSymbols);

Before crating the process from the executable we set the debugger engine filters so that the target process breaks into the debugger immediately after it is created. To set the debugger filters we use function SetSpecificFilterParameters.

DEBUG_SPECIFIC_FILTER_PARAMETERS filter[10];
for (int i = 0; i < 10; i++) {
	filter[i].ExecutionOption = DEBUG_FILTER_BREAK;
	filter[i].ContinueOption = DEBUG_FILTER_GO_HANDLED;
	filter[i].TextSize = 0;
	filter[i].CommandSize = 0;
	filter[i].ArgumentSize = 0;
}

dbgControl->SetSpecificFilterParameters(0, 10, filter);

Using function CreateProcessAndAttach we create a windows debug process and attach the debugger to it.

ULONG64 server            = 0;
PSTR    commandLine       = executableName; 
ULONG   processId         = 0; 
ULONG   attachFlags       = 0; 

dbgClient5->CreateProcessAndAttach(
	server, 
	commandLine,
	DEBUG_PROCESS, 
	processId, 	
	attachFlags); 

To translate the instruction address to a source line we call function GetLineByOffset.

ULONG64 offset = instrAddress;
ULONG fileNameBufferSize = MAX_FILE_NAME_SIZE;
memset(sourceInfo->fileName, 0, fileNameBufferSize);	
sourceInfo->lineNo = 0;
sourceInfo->fileSize = 0;
sourceInfo->displacement = 0;
		
HRESULT isOk = dbgSymbols->GetLineByOffset(
	offset,
	&sourceInfo->lineNo,
	sourceInfo->fileName,
	fileNameBufferSize,
	&sourceInfo->fileSize,
	&sourceInfo->displacement);

If we want to translate multiple addresses, we have to call function GetLineByOffset multiple times without repeating the earlier operations. After we finish with the translation we detatch the debugger from the process by terminating the process with function TerminateCurrentProcess.

HRESULT isOk = dbgClient5->TerminateCurrentProcess();

Download

The code complete source code is available for download from InstructionToSourceLine.zip. Note that the instruction address provided as input should be a decimal number but not hexadecimal.

C# Version

There is also a C# implementation of this tool that you can download from InstructionToSourceLineCSharp.zip. This C# implementation consists of 2 parts – DbgEngManaged and InstructionToSourceLineCSharp. DbgEngManaged is a managed c++ library wrapper for the debugger engine DbgEng.dll. InstructionToSourceLineCSharp is a C# console application that references DbgEngManaged library. Note that the error handling here is not done properly so don't judge me for it :) The provided code here is something that I have quickly prototyped and decided to share for those who for some reason need to use the debugger engine. It can also serve as an example of using native and managed code together. 

A Short and Comprehensive Tutorial on Windows API

I needed to write a simple native Win32 windows application and after searching around I found very nice tutorial – easy to read and with rich examples. So here is the link "Windows API Tutorial". The tutorial includes examples of how to write native (win32) applications with forms, drawgraphics and threading. The tutorial follows a good practice of encapsulating the Win32 abstractions in C++ classes (something which is alredy done at MFC) and makes things to understand easier.

dumpbin – reading header files of windows binaries

Using dumpbin /headers you can read the header of windows files and check for example for what architecture and addressing mode the binary is compiled for.