Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


how to invoke class non-static member variables

ryan wryan w Member Posts: 3
Hi, all
I am writing a MDI application by using WIN32 API, and now i have a problem with the child window.
I want to invoke class non-static member function in the child window procedure function. let me tell you how i did it.
Right after creating the handle of MDI child window, I use SetWindowLong() function to pass the class pointer to the window. then, in the static window procedure function, I use GetWindowLong() function to take the class pointer. after that, i invoke the non-static class member variables. I compile it, no error, but when I execute it, it get errors. part of codings are shown below:

void Connection::createDisplay()
hwndChild = CreateMDIWindow(...);
SetWindowLong(hwndChild, GWL_USERDATA, (LONG) this);

LRESULT CALLBACK Connection::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
Connection *pConn = (Connection * ) GetWindowLong(hwnd, GWL_USERDATA);
switch (iMsg)
case WM_SIZE:
RECT rect;
GetClientRect(hwnd, &rect);
pConn->clientwidth = min( rect.right - rect.left, pConn->m_si.bufferwidth);
pConn->clientheight = min( rect.bottom -, pConn->m_si.bufferheight);
return DefMDIChildProc(hwnd, iMsg, wParam, lParam);

So when it is executed, the error points to the line pConn->clientwidth = min(...);
I suspect that the pointer pConn is invalid. But when I use this WndProc function as normal window procedure function (I mean non-MDI window), it doesn't have any errors, can work properly.
Does anybody tell me the reason about that? Is it the problem with MDI? so generally, my question is asked: "how to invoke the class non-static member variables in the static wndproc function?"
Thanks in advance!


  • Andre YoungAndre Young USAMember Posts: 0

    _____ \ \ free video tutorials and ebooks about // JavaScript Perl Scratch Go C# R PL/SQL Delphi Ruby MATLAB Swift Python Visual Basic Assembly Java PHP C Visual Basic .NET C++ Objective-C Ada COBOL Crystal LabVIEW Erlang Kotlin SAS Dart F# D Apex ML Lisp Julia ABAP Alice FoxPro Prolog Fortran Scheme Transact-SQL Rust Awk Logo VBScript Clojure Bash Hack Scala Lua // ______________

Sign In or Register to comment.