Trash Talk - Win-API: DialogBoxIndirect Function 50% Packetloss - Tue May 31, 2005 8:45 pm Post subject: Win-API: DialogBoxIndirect Function
I have 2 questions.
First is: what is a dword boundry? Or any boundry for that matter. The source code that I am refering to is found here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/usingdialogboxes.asp), at the very bottom of the page. The msdn documentation is great but the fucking thing is in another language or something, whoever wrote it seems incapable of explaining something without using a geek-dialect.
Second: I'm not sure if found a typo or not, this is the documentation for the DLGITEMTEMPLATE struct (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxstructures/dlgitemtemplate.asp) it specifies that "The creation data array begins at the next WORD boundary after the title array," however, the documentation of the DialogBoxIndirect function (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/dialogboxindirect.asp) specifies that "The creation data array that follows a DLGITEMTEMPLATE structure must ... be aligned on a DWORD boundary." The source code example backs up the DialogBoxIndirect() documenation.
50% Packetloss - Wed Jun 01, 2005 5:13 am Post subject:
Also another thing: Is it safe to have a global pointer to the HINSTANCE passed to winmain()? Many functions require the variable and all the example code that I have is using GetModuleHandle() to obtain the instance handle (which seems a little stupid if the handle's place in memory is fixed).
Mr Ekted - Wed Jun 01, 2005 1:52 pm Post subject:
Why use DialogBoxIndirect() unless you are creating dialog box controls on the fly? Normally you would make a dialog template visually, store it as a resource, then use DialogBox().
A DWORD boundary is a 4 byte boundary. That means the pointer & 3 must equal 0. Any pointer allocated with malloc/calloc is guaranteed to be suitably aligned for anything.
An HINSTANCE is just a form of HANDLE, meaning it is a pointer to something inside Windows (app, module, memory, pen, brush, font, etc) that is passed to the application as a void *. As you know, pointers can be passed around an application as data. The HINSTANCE passed to your WinMain is simply a pointer to the base of the your EXE's code. This is always equal to 0x00400000. Saving the pointer, or calling GetModuleHandle() for the app itself is the proper way to obtain it.
50% Packetloss - Wed Jun 01, 2005 4:58 pm Post subject:
Yah, I'm just going through a bunch of functions and figuring out how they work. I haven't planned on making a windows program yet.