www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - now I didn't have RegisterClassExW, how to import that ?

reply "rsk82" <rsk82 live.com> writes:
the error is :

Error: undefined identifier RegisterClassExW, did you mean 
function RegisterClassExA?

No I didn't mean that.

So how to import winapi functions ?
Jan 27 2013
next sibling parent reply Benjamin Thaut <code benjamin-thaut.de> writes:
Am 27.01.2013 18:45, schrieb rsk82:
 the error is :

 Error: undefined identifier RegisterClassExW, did you mean function
 RegisterClassExA?

 No I didn't mean that.

 So how to import winapi functions ?

extern(Windows) <insert function definition here>
Jan 27 2013
parent Benjamin Thaut <code benjamin-thaut.de> writes:
Am 27.01.2013 19:01, schrieb rsk82:
 On Sunday, 27 January 2013 at 17:51:40 UTC, Benjamin Thaut wrote:
 extern(Windows) <insert function definition here>

I am not sure what I was supposed to do, so I did this: extern(Windows) ATOM RegisterClassExW(const WNDCLASSEXW *lpwcx); ATOM class_atom = RegisterClassExW(&wc); and got linker error: OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html test.obj(test) Error 42: Symbol Undefined __D4test8doWindow6__ctorMFZC4test8doWindow16RegisterClassExWWxPS4test8doWindow6__ctorMFZC4test8doWindow11WNDCLASSEXWZt 4 --- errorlevel 1

Did you link against User32.lib? I also recommend that you use VisualD it will give you "pretty" linker error messages. Kind Regards Ingrater
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 17:51:40 UTC, Benjamin Thaut wrote:
 extern(Windows) <insert function definition here>

I am not sure what I was supposed to do, so I did this: extern(Windows) ATOM RegisterClassExW(const WNDCLASSEXW *lpwcx); ATOM class_atom = RegisterClassExW(&wc); and got linker error: OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html test.obj(test) Error 42: Symbol Undefined __D4test8doWindow6__ctorMFZC4test8doWindow16RegisterClassExWWxPS4test8doWindow6__ctorMFZC4test8doWindow11WNDCLASSEXWZt 4 --- errorlevel 1
Jan 27 2013
prev sibling next sibling parent "John Chapman" <johnch_atms hotmail.com> writes:
On Sunday, 27 January 2013 at 18:01:38 UTC, rsk82 wrote:
 On Sunday, 27 January 2013 at 17:51:40 UTC, Benjamin Thaut 
 wrote:
 extern(Windows) <insert function definition here>

I am not sure what I was supposed to do, so I did this: extern(Windows) ATOM RegisterClassExW(const WNDCLASSEXW *lpwcx);

This must be declared at module level (not inside a function).
 ATOM class_atom = RegisterClassExW(&wc);

 and got linker error:

 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 test.obj(test)
  Error 42: Symbol Undefined 
 __D4test8doWindow6__ctorMFZC4test8doWindow16RegisterClassExWWxPS4test8doWindow6__ctorMFZC4test8doWindow11WNDCLASSEXWZt 4
 --- errorlevel 1

Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 18:26:04 UTC, John Chapman wrote:
 This must be declared at module level (not inside a function).

Ok, I've put it into module, linked in the module pragma(lib, "user32.lib"); and pragma(lib, "gdi32.lib"); all this works until I put extern(Windows) ATOM RegisterClassExW(const WNDCLASSEXW *lpwcx); on line 30, then I get as if this was a code not a new function import: .\mod\myModule.d(30): Error: undefined identifier WNDCLASSEXW, did you mean struct WNDCLASSEXA?
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 17:51:40 UTC, Benjamin Thaut wrote:
 extern(Windows) <insert function definition here>

I don't know If that what you meant but this works *inside* the code: extern(Windows) ATOM class_atom = RegisterClassExW(&wc);
Jan 27 2013
prev sibling next sibling parent "John Chapman" <johnch_atms hotmail.com> writes:
On Sunday, 27 January 2013 at 18:58:59 UTC, rsk82 wrote:
 On Sunday, 27 January 2013 at 18:26:04 UTC, John Chapman wrote:
 This must be declared at module level (not inside a function).

Ok, I've put it into module, linked in the module pragma(lib, "user32.lib"); and pragma(lib, "gdi32.lib"); all this works until I put extern(Windows) ATOM RegisterClassExW(const WNDCLASSEXW *lpwcx); on line 30, then I get as if this was a code not a new function import: .\mod\myModule.d(30): Error: undefined identifier WNDCLASSEXW, did you mean struct WNDCLASSEXA?

Because WNDCLASSEXW is not defined. So define it above RegisterClassExW. struct WNDCLASSEXW { UINT cbSize = WNDCLASSEXW.sizeof; UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HINSTANCE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; HICON hIconSm; }
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 19:25:28 UTC, rsk82 wrote:
 extern(Windows)
 ATOM class_atom = RegisterClassExW(&wc);

No, I'm wrong, now the compiler ignores the class that I put in my module, I can write every nonsense that comes to my mind and it compiles. But if I put extern outside of the class then it shows error.
Jan 27 2013
prev sibling next sibling parent "John Chapman" <johnch_atms hotmail.com> writes:
On Sunday, 27 January 2013 at 19:29:03 UTC, John Chapman wrote:
 On Sunday, 27 January 2013 at 18:58:59 UTC, rsk82 wrote:
 On Sunday, 27 January 2013 at 18:26:04 UTC, John Chapman wrote:
 This must be declared at module level (not inside a function).

Ok, I've put it into module, linked in the module pragma(lib, "user32.lib"); and pragma(lib, "gdi32.lib"); all this works until I put extern(Windows) ATOM RegisterClassExW(const WNDCLASSEXW *lpwcx); on line 30, then I get as if this was a code not a new function import: .\mod\myModule.d(30): Error: undefined identifier WNDCLASSEXW, did you mean struct WNDCLASSEXA?

Because WNDCLASSEXW is not defined. So define it above RegisterClassExW. struct WNDCLASSEXW { UINT cbSize = WNDCLASSEXW.sizeof; UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HINSTANCE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; HICON hIconSm; }

Actually, replace "LPCTSTR" above with "LPCWSTR".
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 19:31:59 UTC, John Chapman wrote:
 Actually, replace "LPCTSTR" above with "LPCWSTR".

Ok, fine, now the linker *again*. I have some lenghty code, if is strip it down I post it here.
Jan 27 2013
prev sibling next sibling parent "Phil Lavoie" <maidenphil hotmail.com> writes:
In case you had not seen in the other thread:

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 A for ascii and W for 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 ... 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 29 2013
prev sibling parent "Phil Lavoie" <maidenphil hotmail.com> writes:
On Tuesday, 29 January 2013 at 19:04:04 UTC, Phil Lavoie wrote:
 In case you had not seen in the other thread:

 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 A for ascii and W for 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 ... 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.

Pragmas are included inside the modules (so you dont have to explicitly link against libraries). There is a 1 to 1 mapping with the genuine win32 headers. Example: winuser.h becomes win32.winuser; wingdi.h becomes win32.wingdi; etc...
Jan 29 2013