D, windows developement, frustration and fish
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Sun Feb 1 01:42:49 PST 2015
today i was in need of a little utility that must download the file using
"wininet.dll". nothing fancy, just send a request and receive the
contents. no, curl was not a choice. and -- oh, well, wininet is a dll
which any windows box has, right? at least any windows box with XP and
higher, which is ok.
allright, i know that winapi bindings is a separate project, and it's ok
for me: i fired my git and cloned the repo. surely, "wininet.d" was there.
then i used my shiny fresh DMD build (i just did that to check my fix for
"read after free" patch) to compile a simple test program.
aaah! there is no "wininet.lib"! ok, installing msvc is a time and space
consuming thing, and i know that dmc has that cool "implib" utility,
which i can use to make the corresponding .lib file (ah, i love windows
developement!).
so i ran "implib.exe /s wininet.lib c:\windows\system32\wininet.dll",
copied the resulting "wininet.lib" to "lib" directory of dmd and tried to
compile my sample:
dmd.exe test.d ... /L+wininet.lib
no luck.
Error 42: Symbol Undefined _InternetReadFile at 16
Error 42: Symbol Undefined _InternetCloseHandle at 4
... and so on
wait, what?! i just successfully created that stupid import library!
ok, maybe i read digital mars site wrong and i shouldn't use "/s" switch
with "implib"? ah, fine, let's try...
no luck. the same errors. WTF?! what i did wrong here?! ok, let's think a
minute... yes! dmd wants mangled symbols, and wininet.dll has unmangled
symbols. so optlink searching for "_InternetReadFile at 16", while it should
search for "InternetReadFile". got that.
now, when i identified the problem, i see that i must fix it on D side.
let's try that nice `pragma(mangle, "xxx")` thingy, that's the exact
situation when i need that!
i tried several mangle variants, manually editing "wininet.d" file.
recreated "wininet.lib" several times. you know what? still no luck.
shit, that "simple utility" is not so simple after all. it already took
much more time than downloading and installing msvc can take. damn it!
after some experiments i found that DMD simply ignores `pragma(mangle)`
for `extern(Windows)` definitions. great news. so what i have to do now?
i took that error output and transformed it to "wininet.def" file with
simple regexp. then i generated "wininet.lib" once again. then i tried to
compile my sample once again. and this time i got working ".exe". great.
a simple utility which using one of standard windows dlls. i can write it
in no time, right?
that was current DMD git head, which is considered almost ready for
releasing. super. brilliant. it's really easy to use. now i see why DMD
doesn't need a windows debugger: you simply can't debug a program that
you can't compile.
years in developement. 2.067 release. still can't compile simple utility
without solving stupid puzzles. manual creating of .def files. my C
developement mates making fun of me, showing me how their mingw doesn't
need any ".lib" files at all: mingw linker can parse .dlls! my younger
mate reads this wonderful verse to me:
"You are old, father William," the young man said,
"And your hair has become very white;
And yet you incessantly stand on your head —
Do you think, at your age, it is right?"
what can i answer to it?
"In my youth," father William replied to his son,
"I feared it would injure the brain;
But now that I'm perfectly sure I have none,
Why, I do it again and again."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150201/c8b92416/attachment.sig>
More information about the Digitalmars-d
mailing list