Thread overview | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 23, 2006 What is wrong with this boilerplate mixin? | ||||
---|---|---|---|---|
| ||||
Hello, To make Win programming simpler, I divided sample application (winsample.d) in a standard module (modwin.d) containing the boilerplate code, and a application (appwin.d) file. Both files resides in the same directory. However, it does not link: D:\temp\dlang5>dmd appwin.d c:\dmd\bin\..\..\dm\bin\link.exe appwin,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved c:\dm\bin\..\lib\SNN.lib(winstart) Error 42: Symbol Undefined _WinMain@16 So, what to do? And, 2nd, could things be made simpler? Attached are modwin.d and appwin.d. |
October 23, 2006 Re: What is wrong with this boilerplate mixin? | ||||
---|---|---|---|---|
| ||||
Posted in reply to AF | On Mon, 23 Oct 2006 05:56:08 +0000 (UTC), AF <noemail@noemail.com> wrote: >Hello, > > To make Win programming simpler, I divided sample application >(winsample.d) in a standard module (modwin.d) containing the >boilerplate code, and a application (appwin.d) file. > Both files resides in the same directory. > However, it does not link: > > D:\temp\dlang5>dmd appwin.d >c:\dmd\bin\..\..\dm\bin\link.exe appwin,,,user32+kernel32/noi; >OPTLINK (R) for Win32 Release 7.50B1 >Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved > >c:\dm\bin\..\lib\SNN.lib(winstart) > Error 42: Symbol Undefined _WinMain@16 > > So, what to do? And, 2nd, could things be made simpler? Attached >are modwin.d and appwin.d. The mixed-in WinMain is mangled like __D6appwin11__T6WinAppZ7WinMainWT3std1c7windows7windows6HANDLET3std1c7windows7windows6HANDLEPaiZi@16 instead of _WinMain@16. This might be because the compiler doesn't handle extern(Windows) properly in the template. You could declare a global delegate in modwin which will be called in WinMain (instead of directly calling your myWinMain) and attach myWinMain to it in the static constructor of appwin. Or you could use DFL or other application framework. |
October 23, 2006 Re: What is wrong with this boilerplate mixin? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Samuha | Thank you very much. But, at the moment, I would like to stay in vanilla win32api framework. Second, I do not really need an workaround: it is the intended behaviour of dmd to mangle functions that way, or it is improper use of syntax (i.e. my fault)?. I simply find ugly to bear all that gc boilerplate code with any application when things could be simpler. Any reason why not all gc code should be directly integrated in phobos (or dmd) WinMain function? (actually, why have WinMain() at all and not just main()?) As for delegates, could you (or someone else) be so kind to provide my an example based on the code and ideea I submitted? Thanks in advance. AF |
October 23, 2006 Re: What is wrong with this boilerplate mixin? | ||||
---|---|---|---|---|
| ||||
Posted in reply to AF | AF wrote:
> Hello,
>
> To make Win programming simpler, I divided sample application
> (winsample.d) in a standard module (modwin.d) containing the
> boilerplate code, and a application (appwin.d) file.
> Both files resides in the same directory.
> However, it does not link:
>
> D:\temp\dlang5>dmd appwin.d
> c:\dmd\bin\..\..\dm\bin\link.exe appwin,,,user32+kernel32/noi;
> OPTLINK (R) for Win32 Release 7.50B1
> Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
>
> c:\dm\bin\..\lib\SNN.lib(winstart)
> Error 42: Symbol Undefined _WinMain@16
If this is exactly what you typed, the reason is simple -- dmd doesn't automatically link the modwin.d file.
Try:
dmd appwin.d modwin.d
or download build from dsource, and type
build appwin.d
|
October 23, 2006 Re: What is wrong with this boilerplate mixin? | ||||
---|---|---|---|---|
| ||||
Posted in reply to AF | AF escribió: > Hello, > > To make Win programming simpler, I divided sample application > (winsample.d) in a standard module (modwin.d) containing the > boilerplate code, and a application (appwin.d) file. > Both files resides in the same directory. > However, it does not link: > > D:\temp\dlang5>dmd appwin.d > c:\dmd\bin\..\..\dm\bin\link.exe appwin,,,user32+kernel32/noi; > OPTLINK (R) for Win32 Release 7.50B1 > Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved > > c:\dm\bin\..\lib\SNN.lib(winstart) > Error 42: Symbol Undefined _WinMain@16 > > So, what to do? And, 2nd, could things be made simpler? Attached > are modwin.d and appwin.d. D:\temp\dlang5>dmd appwin.d modwin.d -- Carlos Santander Bernal |
October 23, 2006 Re: What is wrong with this boilerplate mixin? (0/1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander | On Mon, 23 Oct 2006 07:54:30 -0500, Carlos Santander <csantander619@gmail.com> wrote:
>AF escribio:
>> Hello,
>>
>> To make Win programming simpler, I divided sample application
>> (winsample.d) in a standard module (modwin.d) containing the
>> boilerplate code, and a application (appwin.d) file.
>> Both files resides in the same directory.
>> However, it does not link:
>>
>> D:\temp\dlang5>dmd appwin.d
>> c:\dmd\bin\..\..\dm\bin\link.exe appwin,,,user32+kernel32/noi;
>> OPTLINK (R) for Win32 Release 7.50B1
>> Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
>>
>> c:\dm\bin\..\lib\SNN.lib(winstart)
>> Error 42: Symbol Undefined _WinMain@16
>>
>> So, what to do? And, 2nd, could things be made simpler? Attached
>> are modwin.d and appwin.d.
>
>D:\temp\dlang5>dmd appwin.d modwin.d
Oops. I didn't notice that the second file was not included.
Anyway, even if you include the file, the definition of WinMain will not be found because of mangling. I attached the code that uses a function pointer (i called it delegate mistakingly).
|
October 23, 2006 Re: What is wrong with this boilerplate mixin? (1/1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander |
October 23, 2006 Re: What is wrong with this boilerplate mixin? (0/1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Samuha | Max Samuha escribió: > On Mon, 23 Oct 2006 07:54:30 -0500, Carlos Santander > <csantander619@gmail.com> wrote: > >> AF escribio: >>> Hello, >>> >>> To make Win programming simpler, I divided sample application >>> (winsample.d) in a standard module (modwin.d) containing the >>> boilerplate code, and a application (appwin.d) file. >>> Both files resides in the same directory. >>> However, it does not link: >>> >>> D:\temp\dlang5>dmd appwin.d >>> c:\dmd\bin\..\..\dm\bin\link.exe appwin,,,user32+kernel32/noi; >>> OPTLINK (R) for Win32 Release 7.50B1 >>> Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved >>> >>> c:\dm\bin\..\lib\SNN.lib(winstart) >>> Error 42: Symbol Undefined _WinMain@16 >>> >>> So, what to do? And, 2nd, could things be made simpler? Attached >>> are modwin.d and appwin.d. >> D:\temp\dlang5>dmd appwin.d modwin.d > > Oops. I didn't notice that the second file was not included. > > Anyway, even if you include the file, the definition of WinMain will > not be found because of mangling. I attached the code that uses a > function pointer (i called it delegate mistakingly). I don't use Windows, so I can't test your code, but I think it should work. Why don't you try going from the beginning? Just a simple module with a WinMain, see if it works. Then try to use the function pointer from within the same module, see if it works. And then split it. Good luck. -- Carlos Santander Bernal |
October 23, 2006 Re: What is wrong with this boilerplate mixin? (0/1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Samuha | Max Samuha wrote:
>
> Anyway, even if you include the file, the definition of WinMain will
> not be found because of mangling. I attached the code that uses a
> function pointer (i called it delegate mistakingly).
you might try:
extern(C) WinMain
But that's just a wild guess
|
October 24, 2006 Re: What is wrong with this boilerplate mixin? | ||||
---|---|---|---|---|
| ||||
Posted in reply to AF | AF wrote:
> Thank you very much. But, at the moment, I would like to stay in
> vanilla win32api framework.
> Second, I do not really need an workaround: it is the intended
> behaviour of dmd to mangle functions that way, or it is improper
> use of syntax (i.e. my fault)?.
> I simply find ugly to bear all that gc boilerplate code with any
> application when things could be simpler. Any reason why not all gc
> code should be directly integrated in phobos (or dmd) WinMain
> function? (actually, why have WinMain() at all and not just main()?)
> As for delegates, could you (or someone else) be so kind to
> provide my an example based on the code and ideea I submitted?
>
> Thanks in advance.
>
> AF
Actually, you /can/ use just main(), which is my personal preferance. Just a couple of things to consider. First, in order to ensure you get an exe which doesn't pop up a console window, pass '-L/exet:nt/su:windows:4.0' to the compiler. (Or whatever would be most appropriate). Second, to get your hInstance you will need to call GetModuleHandle(NULL) and store its return.
-- Chris Nicholson-Sauls
|
Copyright © 1999-2021 by the D Language Foundation