Notes on software development (Windows) and computer system administration.

2005-11-28

Visual C++ Project continually out-of-date (winwlm.h macwin32.h rpcerr.h macname1.h missing)

Problem:
In Visual C++ .Net 2003, one of my projects always claimed to be out of date, even though nothing had changed and no errors had been reported in the last build.

Opening the BuildLog.htm file for the corresponding project showed a list of PRJ0041 errors for these files, none of which appear on my system anywhere:
winwlm.h macwin32.h rpcerr.h macname1.h

Each error looks something lik ethis:
MyApplication : warning PRJ0041 : Cannot find missing dependency 'macwin32.h' for file 'MyApplication.rc'. Your project may still build, but may continue to appear out of date until this file is found.

Solution:
Include afxres.h instead of resource.h inside the project's .rc file.

The project's .rc file contained "#include resource.h". Since the resource compiler does not honor preprocessor #ifdef blocks, it will tear through and try to find include files it should be ignoring. Windows.h contains many such blocks. Including afxres.h instead fixed the PRJ0041 warnings and eliminated the "Project is out-of-date" error dialog.

2005-09-08

tasklist

Examples:

Show task information on the Cygwin SSH daemon:
C:\>tasklist /FI "IMAGENAME eq sshd.exe"

Image Name PID Session Name Session# Mem Usage
========================= ====== ================ ======== ============
sshd.exe 2248 Console 0 3,508 K

Show services for each process:
C:\>tasklist /SVC

Image Name PID Services
========================= ====== =============================================
System Idle Process 0 N/A
System 4 N/A
smss.exe 952 N/A
csrss.exe 1068 N/A
winlogon.exe 1092 N/A
services.exe 1136 Eventlog, PlugPlay
lsass.exe 1148 Netlogon, PolicyAgent, ProtectedStorage,
SamSs

2005-08-30

Overuse of std::transform

Using std::transform on a simple, NULL-terminated string. This is a horrible perversion of what was simple -- if unattractive -- code:

template <typename t=""> T* ToLower (T* psz)
{
if (!psz)
return 0;

size_t size;

if (sizeof(T) == 1)
size = strlen((char *)psz);
else
size = wcslen((wchar_t *)psz);

std::transform(psz, psz + size, psz, tolower);

return psz;
}

2005-08-29

Visual Studio Macros - Header/Source switcher

This code grabs the active file's name, lops off the extension (e.g. '.cpp'), replaces it with the corresponding extension (e.g. '.h'), and attempts to load the new filename.

This should work with .c, .cpp, .cc, .h, .hh, and .hpp files.

Option Strict Off
Option Explicit Off

Public Module HeaderSourceSwitcher
'--------------------------------------------------------------------------
' Jeff Fitzsimons -- Minimal header/source switcher.
'--------------------------------------------------------------------------
Sub DoSwitch()
Try
' Make sure there's an active document...
If (DTE.ActiveDocument Is Nothing) Then
MsgBox("No active document.", MsgBoxStyle.Exclamation, "HeaderSourceSwitcher")
Return
End If

' Get the name of the active document...
Dim name As String
name = DTE.ActiveDocument.FullName()

' Substitute file extensions...
If name.EndsWith(".cpp") Then
name = name.Replace(".cpp", ".h")
' No matching .h file, try with .hpp...
If Not System.IO.File.Exists(name) Then
name = name.Replace(".h", ".hpp")
End If
ElseIf name.EndsWith(".c") Then
name = name.Replace(".c", ".h")
ElseIf name.EndsWith(".hpp") Then
name = name.Replace(".hpp", ".cpp")
ElseIf name.EndsWith(".h") Then
name = name.Replace(".h", ".cpp")
' No matching .cpp file, try with .c...
If Not System.IO.File.Exists(name) Then
name = name.Replace(".cpp", ".c")
End If
ElseIf name.EndsWith(".cc") Then
name = name.Replace(".cc", ".hh")
ElseIf name.EndsWith(".hh") Then
name = name.Replace(".hh", ".cc")
End If

' If the file exists, open it. Otherwise show an error.
If (System.IO.File.Exists(name)) Then
DTE.ItemOperations.OpenFile(name)
Else
MsgBox("Unable to find a matching file.", MsgBoxStyle.Exclamation, "HeaderSourceSwitcher")
End If
Catch
MsgBox("Unknown exception thrown!")
End Try

End Sub

End Module