www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - cannot initialize WNDCLASSW, WNDCLASSEX, WNDCLASSEXW window structs

reply "rsk82" <rsk82 live.com> writes:
WNDCLASS wc; - ok
WNDCLASSA wc; - ok
WNDCLASSW wc; - Error: undefined identifier WNDCLASSW, did you 
mean alias WNDCLASS?
WNDCLASSEX wc; - Error: undefined identifier WNDCLASSEX, did you 
mean struct WNDCLASSEXA?
WNDCLASSEXA wc; - ok
WNDCLASSEXW wc; Error: undefined identifier WNDCLASSEXW, did you 
mean struct WNDCLASSEXA?

code:

import core.runtime;
import core.sys.windows.windows;
extern(Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int iCmdShow) {
   WNDCLASSEXA wc;
   return 0;
}

I most concerned about WNDCLASSEXW, that is the version I intend 
to use.
Jan 27 2013
next sibling parent Benjamin Thaut <code benjamin-thaut.de> writes:
Am 27.01.2013 14:10, schrieb rsk82:
 WNDCLASS wc; - ok
 WNDCLASSA wc; - ok
 WNDCLASSW wc; - Error: undefined identifier WNDCLASSW, did you mean
 alias WNDCLASS?
 WNDCLASSEX wc; - Error: undefined identifier WNDCLASSEX, did you mean
 struct WNDCLASSEXA?
 WNDCLASSEXA wc; - ok
 WNDCLASSEXW wc; Error: undefined identifier WNDCLASSEXW, did you mean
 struct WNDCLASSEXA?

 code:

 import core.runtime;
 import core.sys.windows.windows;
 extern(Windows)
 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
 lpCmdLine, int iCmdShow) {
    WNDCLASSEXA wc;
    return 0;
 }

 I most concerned about WNDCLASSEXW, that is the version I intend to use.

Well WNDCLASSEXW is not defined inside core.sys.windows.windows. If you need it just look up the definition in MSDN and define it yourself. Kind Regards Benjamin Thaut
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 13:36:25 UTC, Benjamin Thaut wrote:
 Well WNDCLASSEXW is not defined inside core.sys.windows.windows.
 If you need it just look up the definition in MSDN and define 
 it yourself.

But how ? MSDN website shows only how to do it in C++, are there any examples how to define winapi structures ?
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
Ok, nevermind, found, it, it was so easy that it simply didn't 
have to had an example:

     struct WNDCLASSEXW {
       UINT      cbSize;
       UINT      style;
       WNDPROC   lpfnWndProc;
       int       cbClsExtra;
       int       cbWndExtra;
       HINSTANCE hInstance;
       HICON     hIcon;
       HCURSOR   hCursor;
       HBRUSH    hbrBackground;
       LPCWSTR   lpszMenuName;
       LPCWSTR   lpszClassName;
       HICON     hIconSm;
     }
Jan 27 2013
prev sibling next sibling parent "Phil Lavoie" <maidenphil hotmail.com> writes:
On Sunday, 27 January 2013 at 14:06:00 UTC, rsk82 wrote:
 Ok, nevermind, found, it, it was so easy that it simply didn't 
 have to had an example:

     struct WNDCLASSEXW {
       UINT      cbSize;
       UINT      style;
       WNDPROC   lpfnWndProc;
       int       cbClsExtra;
       int       cbWndExtra;
       HINSTANCE hInstance;
       HICON     hIcon;
       HCURSOR   hCursor;
       HBRUSH    hbrBackground;
       LPCWSTR   lpszMenuName;
       LPCWSTR   lpszClassName;
       HICON     hIconSm;
     }

If you find yourself desiring other bindings of the win32 api and don't want them to define them by hand, a project was started some time ago by Stewart Gordon that contains an almost complete set of bindings: http://dsource.org/projects/bindings/wiki/WindowsApi Set the import directory of your compiler appropriately and use it like that: import win32.winuser; //example, where you will probably find wndclassexw Additionnally, you should know that SOMETHINGA and SOMETHINGW means something like ascii and wide chars (UCS-2, so every char is two bytes instead of one). Normally, the api was intented to be used without the extra letter at the end: WNDCLASSEX wndclass; //No suffix: defaults to ascii. When people compile with the preprocessor Unicode defined, then all aliases are mapped to their W counterpart. What changes is how you pass and receive strings. Keep in mind they must be null terminated (as in C). The microsoft bunch also defined another macro that would help you make your code independant of the version used, it is called TCHAR. TCHAR * someString; //Will be char * without unicode or wchar with. someString = "My window class".toUTFz!( TCHAR * ); //This is how I use the std library to convert my strings. Try to keep a handle on strings that might be kept by the OS, to prevent them from being garbage collected. WNDCLASSEX wndclass; ... wndclass.lpszClassName = someString; Peace, Phil
Jan 27 2013
prev sibling parent "Phil Lavoie" <maidenphil hotmail.com> writes:
Just to clarify:
xxxA = Ascii;
xxxW = Wide chars (UCS-2);

And because I forgot to mention, to mimic the preprocessor 
directive, the bindings use a version conditional compilation. 
Therefore, you use it like that:
rdmd -I/where/you/put/the/bindings -version=Unicode yourmodule.d

You can double check in the code, but IIRC, only the first letter 
is capsed.
Jan 27 2013