8

I'm disassembling a 16-bit Windows program from the 1994-95 timeframe. The runtime library used seems to be from Microsoft C, so I'm guessing the program was compiled with Microsoft C++ 7.0 or Visual C++ 1.0.

It looks to me as if the program was written using a C++ framework for window management. Unlike MFC, which uses a dictionary to store the mapping between window handles (HWND) and C++ objects (CWnd) this framework stores a pointer to the C++ object in a property on the window called "w+":

SetProp(hWnd, "w+", this);

and similarly uses GetProp(hWnd, "w+") to find the C++ object associated with a particular window.

Is anyone aware of a framework (for C++ or some other OO language) that mapped windows to classes using this method?

1 Answer 1

8

This is most likely "Windows++", a C++ Application Framework for Windows by Paul DiLascia. The framework source code is still available for download from http://pauldilascia.com/wpp.htm

If you download wpp16.zip and examine the contents of EXPWPP20.EXE (it's a self-extracting executable, although 7Zip can open it without needing to run the code) then you'll find inside WPWIN.CPP the window property you have already seen:

//////////////////////////////////////////////////////////
// WINDOWS++ CLASS LIBRARY.  Copyright 1992 Paul DiLascia.
// FILE: WPWIN.CPP
//
// Implementation of base window class for all window objects.

#include "wpp.h"

// this property links a window to its object
char WP_WINPTR[] =  "w+";

This is used in code called immediately after CreateWindowEx returns:

//////////////////
// Link object to a real (Windows) window.
// 
void WPWin::linkHwnd(HWND newhwnd)
{
    assert(hwnd==NULL);                     // better not be already linked!
    assert(IsWindow(newhwnd));              // better have a real HWND!
    hwnd = newhwnd;                         // store Window handle
    setProp(WP_WINPTR, (HANDLE)this);   // store ourself in window prop

and then used whenever a message is processed and the this pointer needs to be recovered:

//////////////////
// Get window object from window handle (HWND)
// 
WPWin* WPWin::GetWin(HWND hwnd)
{ 
    if (hwnd==NULL) 
        return NULL;
    assert(IsWindow(hwnd));
    HANDLE winptr = GetProp(hwnd, WP_WINPTR);
    if (winptr==NULL)
        return NULL;

#ifdef __MEDIUM__
    return (WPWin*)winptr;  // in medium model, just cast to ptr
#else
    WORD appds;
    GETAPPDS(appds);                // get application's data segment
    return (WPWin*)MK_FP(appds, winptr);
#endif
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .