I'm so embarrased. I must have read those links a hundred times and not understood it.. It has now fallen into place.
Thanks so much. I can go on living now!
Thanks for the patience and time. You have no idea how much I appreciate it!
FB
I'm so embarrased. I must have read those links a hundred times and not understood it.. It has now fallen into place.
Thanks so much. I can go on living now!
Thanks for the patience and time. You have no idea how much I appreciate it!
FB
Visual C++ .net
Windows XP profesional
Hi, I've been trying to figure this out as well, in the book I've got you have to use windowclass.cbWndExtra in the windowclass to store a pointer, also (as you guys said), you have to use a this pointer as well. Is the bit about storing a pointer in windowclass.cbWndExtra right?
Actually I'll keep this short by just asking about the bit I most don't understand , I'll read up about the other links as well.
[code]
//declare your window
CMYWINDOW myWindow;
myWindow.create("Title");//create
myWindow.show();//show
LRESULT CALLBACK//included in the class as a freind
WindowProc(HWND myWindow,UINT message,
WPARAM wparam,LPARAM lparam)
{
if (message== WM_CREATE)
{
CREATESTRUCT* createstruct;//this is a pointer to a
//CREATESTRUCT type.
//what does this mean?
createstruct = (CREATESTRUCT*)lparam;
SetWindowLong (myWindow, 0, (LONG) (createstruct->
lpcreateparams)) ;
return 0;
CMYWINDOW* object = (CMYWINDOW)GetWindowLong
(myWindow,0);
if (object)//I think the rest is just the normal message processing.
{
if (message == WM_DESTROY)
return object-> Destroy(myWindow,message,wparam,lparam);
//Destroy is the destroy method from the class
//...
return DefWindowProc(... )
}
[code]
Thanks anyone.
No. That's just for specifying extra bytes you want to store with windows of that registered class. Use SetWindowLongPtr/GetWindowLongPtr to set and get those extra bytes; GWL_USERDATA is 'free' in this regard ie you don't have to do anything extra to use it.Originally posted by Stevo
Is the bit about storing a pointer in windowclass.cbWndExtra right?
Take a look at the relevant descriptions on msdn for clarification:
WNDCLASSEX
GetWindowLongPtr
SetWindowLongPtr
That's type-casting - casting, in this case, the value of lParam to a CREATESTRUCT pointer so you can use it and access the members of the CREATESTRUCT struct.Originally posted by Stevo
//what does this mean?
createstruct = (CREATESTRUCT*)lparam;
Last edited by Ken Fitlike; 03-09-2004 at 04:46 PM.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
Thanks Ken, I'll look up the answers you already gave to filter as well.
Thanks
You ain't cool, less'n you is thunk'n!
gg
Well, thankee kindly.
That's a very interesting read but the technique seems to carry its own subset of problems.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
True.
It's compiler and architecture dependant. I use this technique on ARM, SH3, MIPS, and x86 processors (and so does ATL).
All the architecture #define's come from the project/makefile. Shouldn't be too hard to port the code in that article using g++ compiler directives.
If you own VisualStudio and have ATL installed, take a look at your ...\ATL\Include\atlwin.h header file to see how Microsoft does it
gg
If anyone sends me such I'll add it to the article as an appendix, giving due credit of course.Originally posted by Codeplug
Shouldn't be too hard to port the code in that article using g++ compiler directives.
>>Shouldn't be too hard to port the code in that article using g++ compiler directives. <<
Haha! Famous last words.
>>If you own VisualStudio and have ATL installed, take a look at your ...\ATL\Include\atlwin.h header file to see how Microsoft does it<<
Ok.
Thanks again.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
That article just simply blew my mind.You ain't cool, less'n you is thunk'n!
Gosh, thanks (assuming you meant it in a good way).Originally posted by Dante Shamest
That article just simply blew my mind.
I was bored.....
I've attached full source that compiles and runs under both MinGW and VC++ 6.0Code:/*---------------------------------------------------------------------------*/ #if defined (_MSC_VER) // VC++ compiler #if !defined (_M_IX86) // x86 architecture #error Only X86 supported #endif #elif defined (__GNUC__) // GNU compiler #if !defined (_X86_) // x86 architecture #error Only X86 supported #endif #endif /*---------------------------------------------------------------------------*/ #if defined (_MSC_VER) // VC++ compiler #pragma warning(push) #pragma warning(disable:4355) //'this' used in base member initializer list #pragma pack(push,1) #endif /*---------------------------------------------------------------------------*/ class WndProcThunk { const DWORD m_mov; // mov ecx, pThis const DWORD m_this; // pThis const BYTE m_jmp; // jmp WndProc const DWORD m_relproc; // relative jmp WndProcThunk(); // private default constructor (no implementation) public: explicit WndProcThunk(WNDPROC proc, void *pThis) : m_mov(0x042444C7), m_this((DWORD)pThis), m_jmp(0xE9), m_relproc((int)proc - ((int)this + sizeof(WndProcThunk))) { ::FlushInstructionCache(GetCurrentProcess(), this, sizeof(WndProcThunk)); }//constructor }//<-- no semicolon yet... /*---------------------------------------------------------------------------*/ #if defined (__GNUC__) // GNU compiler __attribute__ ((packed)) #endif ; //<-- semicolon to close WndProcThunk #if defined (_MSC_VER) // VC++ compiler #pragma warning(pop) #pragma pack(pop) #endif /*---------------------------------------------------------------------------*/
gg
Cool. You mind if I append it to the article on HackCraft?Originally posted by Codeplug
I was bored.....
If so how you you like to be referred to as, "Codeplug?" or another name, or what?
Codeplug on Cprogramming.com (or something like that) is fine
Feel free to use your original "winThunk" implementation as well.
gg