www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Linking in advapi32.lib and netlib32.lib

reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Hi, me again.

I was having a poke around phobos to see if there was anything that
needed filling out, and found that expandTilde was missing a Windows
implementation.

After a little trawling through MSDN, I've worked out what to do, but I
can't for the life of me get the damn code to link.

I know I need to link to advapi32.lib and netlib32.lib.  If I link to
advapi32.lib, I then get "Error: A dynamic link library (DLL)
initialization routine failed.".  Oddly enough, it compiled without
specifying netlib32.lib; when I do specify it, it can't find it.

Now, I'm assuming that the problem with advapi32.lib is that it's on
COFF and not OMF (I can't actually remember where that copy of
advapi32.lib came from >_<).  I've seen lots of references to
coff2omf.exe, but the only one I can find costs $15 from DM.

So:

1.  Is there a free tool to get dmd-compatible versions of advapi32.lib,
netlib32.lib, (insert other win32 system libraries), or am I going to
have to use std.loader?

2.  Is there anywhere I can download OMF versions of those libraries?

P.S.  I just checked the Win32 api project, and they don't have lm.h
converted (for stuff in netlib32), and no .lib files :(

If I can get this working, I'll donate the windows implementation of
expandTilde (if Walter wants it, of course :).

	-- Daniel "why you no linky, damnit?"

-- 

v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D
a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP    http://hackerkey.com/
Apr 16 2006
parent reply John C <johnch_atms hotmail.com> writes:
Daniel Keep wrote:
 Hi, me again.
 
 I was having a poke around phobos to see if there was anything that
 needed filling out, and found that expandTilde was missing a Windows
 implementation.
 
 After a little trawling through MSDN, I've worked out what to do, but I
 can't for the life of me get the damn code to link.
 
 I know I need to link to advapi32.lib and netlib32.lib.  If I link to
 advapi32.lib, I then get "Error: A dynamic link library (DLL)
 initialization routine failed.".  Oddly enough, it compiled without
 specifying netlib32.lib; when I do specify it, it can't find it.
 
 Now, I'm assuming that the problem with advapi32.lib is that it's on
 COFF and not OMF (I can't actually remember where that copy of
 advapi32.lib came from >_<).  I've seen lots of references to
 coff2omf.exe, but the only one I can find costs $15 from DM.
 
 So:
 
 1.  Is there a free tool to get dmd-compatible versions of advapi32.lib,
 netlib32.lib, (insert other win32 system libraries), or am I going to
 have to use std.loader?
coffimplib will convert Microsoft COFF libraries to OMF format. http://www.digitalmars.com/ctg/coffimplib.html ftp://ftp.digitalmars.com/coffimplib.zip
 
 2.  Is there anywhere I can download OMF versions of those libraries?
 
 P.S.  I just checked the Win32 api project, and they don't have lm.h
 converted (for stuff in netlib32), and no .lib files :(
 
 If I can get this working, I'll donate the windows implementation of
 expandTilde (if Walter wants it, of course :).
 
 	-- Daniel "why you no linky, damnit?"
 
Apr 17 2006
next sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Thanks :)  I actually found the same program five minutes ago... whilst
bumming around Wiki4D's comments on the official documentation whilst
waiting for dsource.org to come back up.

If the vast majority of .libs out there are in COFF, why isn't
coffimplib shipped with dmd?

	-- Daniel

John C wrote:
 Daniel Keep wrote:
 Hi, me again.

 I was having a poke around phobos to see if there was anything that
 needed filling out, and found that expandTilde was missing a Windows
 implementation.

 After a little trawling through MSDN, I've worked out what to do, but I
 can't for the life of me get the damn code to link.

 I know I need to link to advapi32.lib and netlib32.lib.  If I link to
 advapi32.lib, I then get "Error: A dynamic link library (DLL)
 initialization routine failed.".  Oddly enough, it compiled without
 specifying netlib32.lib; when I do specify it, it can't find it.

 Now, I'm assuming that the problem with advapi32.lib is that it's on
 COFF and not OMF (I can't actually remember where that copy of
 advapi32.lib came from >_<).  I've seen lots of references to
 coff2omf.exe, but the only one I can find costs $15 from DM.

 So:

 1.  Is there a free tool to get dmd-compatible versions of advapi32.lib,
 netlib32.lib, (insert other win32 system libraries), or am I going to
 have to use std.loader?
coffimplib will convert Microsoft COFF libraries to OMF format. http://www.digitalmars.com/ctg/coffimplib.html ftp://ftp.digitalmars.com/coffimplib.zip
 2.  Is there anywhere I can download OMF versions of those libraries?

 P.S.  I just checked the Win32 api project, and they don't have lm.h
 converted (for stuff in netlib32), and no .lib files :(

 If I can get this working, I'll donate the windows implementation of
 expandTilde (if Walter wants it, of course :).

     -- Daniel "why you no linky, damnit?"
-- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Apr 17 2006
parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
<sigh> Oh never mind.  This code just *doesn't* want to work...  Every
time I try to call a function in advapi32, it returns the Win32 error
code for "A dynamic link library (DLL) initialization routine failed.".

And then, even if I hardcode the user name to my own current user name,
it refuses to let me see my own home directory :(

Stupid Windows...

Thanks for the help anyway, John.  Think I'll play with embedding Python
for a while instead.  So far I've got it in a simple read-eval loop :P

	-- Daniel "hates win32"


Daniel Keep wrote:
 Thanks :)  I actually found the same program five minutes ago... whilst
 bumming around Wiki4D's comments on the official documentation whilst
 waiting for dsource.org to come back up.
 
 If the vast majority of .libs out there are in COFF, why isn't
 coffimplib shipped with dmd?
 
 	-- Daniel
 
 John C wrote:
 Daniel Keep wrote:
 Hi, me again.

 I was having a poke around phobos to see if there was anything that
 needed filling out, and found that expandTilde was missing a Windows
 implementation.

 After a little trawling through MSDN, I've worked out what to do, but I
 can't for the life of me get the damn code to link.

 I know I need to link to advapi32.lib and netlib32.lib.  If I link to
 advapi32.lib, I then get "Error: A dynamic link library (DLL)
 initialization routine failed.".  Oddly enough, it compiled without
 specifying netlib32.lib; when I do specify it, it can't find it.

 Now, I'm assuming that the problem with advapi32.lib is that it's on
 COFF and not OMF (I can't actually remember where that copy of
 advapi32.lib came from >_<).  I've seen lots of references to
 coff2omf.exe, but the only one I can find costs $15 from DM.

 So:

 1.  Is there a free tool to get dmd-compatible versions of advapi32.lib,
 netlib32.lib, (insert other win32 system libraries), or am I going to
 have to use std.loader?
coffimplib will convert Microsoft COFF libraries to OMF format. http://www.digitalmars.com/ctg/coffimplib.html ftp://ftp.digitalmars.com/coffimplib.zip
 2.  Is there anywhere I can download OMF versions of those libraries?

 P.S.  I just checked the Win32 api project, and they don't have lm.h
 converted (for stuff in netlib32), and no .lib files :(

 If I can get this working, I'll donate the windows implementation of
 expandTilde (if Walter wants it, of course :).

     -- Daniel "why you no linky, damnit?"
-- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Apr 18 2006
parent reply John C <johnch_atms hotmail.com> writes:
Daniel Keep wrote:
 <sigh> Oh never mind.  This code just *doesn't* want to work...  Every
 time I try to call a function in advapi32, it returns the Win32 error
 code for "A dynamic link library (DLL) initialization routine failed.".
 
 And then, even if I hardcode the user name to my own current user name,
 it refuses to let me see my own home directory :(
 
 Stupid Windows...
What's the function you're trying to call? And what does your function definition look like? I just tried GetUserName and it worked.
 
 Thanks for the help anyway, John.  Think I'll play with embedding Python
 for a while instead.  So far I've got it in a simple read-eval loop :P
 
 	-- Daniel "hates win32"
Apr 18 2006
next sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:







I'm using XP, so I'm fairly sure GetUserNameW should be there (well,
it's there in advapi32.dll -- dependancy walker says so).

John C wrote:
 Daniel Keep wrote:
 <sigh> Oh never mind.  This code just *doesn't* want to work...  Every
 time I try to call a function in advapi32, it returns the Win32 error
 code for "A dynamic link library (DLL) initialization routine failed.".

 And then, even if I hardcode the user name to my own current user name,
 it refuses to let me see my own home directory :(

 Stupid Windows...
What's the function you're trying to call? And what does your function definition look like? I just tried GetUserName and it worked.
 Thanks for the help anyway, John.  Think I'll play with embedding Python
 for a while instead.  So far I've got it in a simple read-eval loop :P

     -- Daniel "hates win32"
-- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Apr 18 2006
prev sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:







I'm using XP, so I'm fairly sure GetUserNameW should be there (well,
it's there in advapi32.dll -- dependency walker says so).

John C wrote:
 Daniel Keep wrote:
 <sigh> Oh never mind.  This code just *doesn't* want to work...  Every
 time I try to call a function in advapi32, it returns the Win32 error
 code for "A dynamic link library (DLL) initialization routine failed.".

 And then, even if I hardcode the user name to my own current user name,
 it refuses to let me see my own home directory :(

 Stupid Windows...
What's the function you're trying to call? And what does your function definition look like? I just tried GetUserName and it worked.
 Thanks for the help anyway, John.  Think I'll play with embedding Python
 for a while instead.  So far I've got it in a simple read-eval loop :P

     -- Daniel "hates win32"
-- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Apr 18 2006
parent reply John C <johnch_atms hotmail.com> writes:
Daniel Keep wrote:






 
 I'm using XP, so I'm fairly sure GetUserNameW should be there (well,
 it's there in advapi32.dll -- dependency walker says so).
Yes, GetUserNameW is from advapi32. The error message you're getting usually means Windows can't find the DLL. What error code do you get if you call LoadLibrary("advapi32.dll")? If it returns 0, then there's something else wrong. Is the original lib file from the Platform SDK? Or did you get it by other means? I think coffimplib only works on the Microsoft lib files.
 
 John C wrote:
 
Daniel Keep wrote:

<sigh> Oh never mind.  This code just *doesn't* want to work...  Every
time I try to call a function in advapi32, it returns the Win32 error
code for "A dynamic link library (DLL) initialization routine failed.".

And then, even if I hardcode the user name to my own current user name,
it refuses to let me see my own home directory :(

Stupid Windows...
What's the function you're trying to call? And what does your function definition look like? I just tried GetUserName and it worked.
Thanks for the help anyway, John.  Think I'll play with embedding Python
for a while instead.  So far I've got it in a simple read-eval loop :P

    -- Daniel "hates win32"
Apr 18 2006
parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Sorry for the tardy reply... been busy.

John C wrote:
 Daniel Keep wrote:







 I'm using XP, so I'm fairly sure GetUserNameW should be there (well,
 it's there in advapi32.dll -- dependency walker says so).
Yes, GetUserNameW is from advapi32. The error message you're getting usually means Windows can't find the DLL. What error code do you get if you call LoadLibrary("advapi32.dll")? If it returns 0, then there's something else wrong. Is the original lib file from the Platform SDK? Or did you get it by other means? I think coffimplib only works on the Microsoft lib files.
The original .LIB files are from the MS Platform SDK installed with Visual Studio .NET 2003. Ran them through using "coffimplib IN.lib OUT.lib". As for LoadLibrary, now I can't get THAT to link properly (sob). MSDN says that it's in Kernel32.lib, but it still can't resolve it if I link that in. Honestly, I have better things to do with my time than fight with dmd over this. I think I'll just wait until the win32 bindings cover what I need, and then try again. Many thanks for your help.
 
 John C wrote:

 Daniel Keep wrote:

 <sigh> Oh never mind.  This code just *doesn't* want to work...  Every
 time I try to call a function in advapi32, it returns the Win32 error
 code for "A dynamic link library (DLL) initialization routine failed.".

 And then, even if I hardcode the user name to my own current user name,
 it refuses to let me see my own home directory :(

 Stupid Windows...
What's the function you're trying to call? And what does your function definition look like? I just tried GetUserName and it worked.
 Thanks for the help anyway, John.  Think I'll play with embedding
 Python
 for a while instead.  So far I've got it in a simple read-eval loop :P

    -- Daniel "hates win32"
-- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Apr 20 2006
parent Don Clugston <dac nospam.com.au> writes:
Daniel Keep wrote:
 Sorry for the tardy reply... been busy.
 
 John C wrote:
 Daniel Keep wrote:







 I'm using XP, so I'm fairly sure GetUserNameW should be there (well,
 it's there in advapi32.dll -- dependency walker says so).
Yes, GetUserNameW is from advapi32. The error message you're getting usually means Windows can't find the DLL. What error code do you get if you call LoadLibrary("advapi32.dll")? If it returns 0, then there's something else wrong. Is the original lib file from the Platform SDK? Or did you get it by other means? I think coffimplib only works on the Microsoft lib files.
The original .LIB files are from the MS Platform SDK installed with Visual Studio .NET 2003. Ran them through using "coffimplib IN.lib OUT.lib". As for LoadLibrary, now I can't get THAT to link properly (sob). MSDN says that it's in Kernel32.lib, but it still can't resolve it if I link that in.
You will need to link to LoadLibraryA() or LoadLibraryW(). There's no function called LoadLibrary(), it's an alias. (Unless you use winbase from the win32 bindings library, which aliases them to LoadLibrary for you -- although note that the win32 bindings are in an alpha state, and not very well tested).
 Honestly, I have better things to do with my time than fight with dmd
 over this.  I think I'll just wait until the win32 bindings cover what I
 need, and then try again.
 
 Many thanks for your help.
 
 John C wrote:

 Daniel Keep wrote:

 <sigh> Oh never mind.  This code just *doesn't* want to work...  Every
 time I try to call a function in advapi32, it returns the Win32 error
 code for "A dynamic link library (DLL) initialization routine failed.".

 And then, even if I hardcode the user name to my own current user name,
 it refuses to let me see my own home directory :(

 Stupid Windows...
What's the function you're trying to call? And what does your function definition look like? I just tried GetUserName and it worked.
 Thanks for the help anyway, John.  Think I'll play with embedding
 Python
 for a while instead.  So far I've got it in a simple read-eval loop :P

    -- Daniel "hates win32"
Apr 20 2006
prev sibling parent reply Don Clugston <dac nospam.com.au> writes:
John C wrote:
 Daniel Keep wrote:
 Hi, me again.

 I was having a poke around phobos to see if there was anything that
 needed filling out, and found that expandTilde was missing a Windows
 implementation.

 After a little trawling through MSDN, I've worked out what to do, but I
 can't for the life of me get the damn code to link.

 I know I need to link to advapi32.lib and netlib32.lib.  If I link to
 advapi32.lib, I then get "Error: A dynamic link library (DLL)
 initialization routine failed.".  Oddly enough, it compiled without
 specifying netlib32.lib; when I do specify it, it can't find it.

 Now, I'm assuming that the problem with advapi32.lib is that it's on
 COFF and not OMF (I can't actually remember where that copy of
 advapi32.lib came from >_<).  I've seen lots of references to
 coff2omf.exe, but the only one I can find costs $15 from DM.

 So:

 1.  Is there a free tool to get dmd-compatible versions of advapi32.lib,
 netlib32.lib, (insert other win32 system libraries), or am I going to
 have to use std.loader?
coffimplib will convert Microsoft COFF libraries to OMF format. http://www.digitalmars.com/ctg/coffimplib.html ftp://ftp.digitalmars.com/coffimplib.zip
 2.  Is there anywhere I can download OMF versions of those libraries?

 P.S.  I just checked the Win32 api project, and they don't have lm.h
 converted (for stuff in netlib32), and no .lib files :(
Come on, give us a bit of time... that project only started less than three weeks ago! :-). The lmXXX stuff will come before too long.
 If I can get this working, I'll donate the windows implementation of
 expandTilde (if Walter wants it, of course :).

     -- Daniel "why you no linky, damnit?"
Apr 18 2006
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Don Clugston wrote:
 John C wrote:
 Daniel Keep wrote:
 Hi, me again.

 I was having a poke around phobos to see if there was anything that
 needed filling out, and found that expandTilde was missing a Windows
 implementation.

 After a little trawling through MSDN, I've worked out what to do, but I
 can't for the life of me get the damn code to link.

 I know I need to link to advapi32.lib and netlib32.lib.  If I link to
 advapi32.lib, I then get "Error: A dynamic link library (DLL)
 initialization routine failed.".  Oddly enough, it compiled without
 specifying netlib32.lib; when I do specify it, it can't find it.

 Now, I'm assuming that the problem with advapi32.lib is that it's on
 COFF and not OMF (I can't actually remember where that copy of
 advapi32.lib came from >_<).  I've seen lots of references to
 coff2omf.exe, but the only one I can find costs $15 from DM.

 So:

 1.  Is there a free tool to get dmd-compatible versions of advapi32.lib,
 netlib32.lib, (insert other win32 system libraries), or am I going to
 have to use std.loader?
coffimplib will convert Microsoft COFF libraries to OMF format. http://www.digitalmars.com/ctg/coffimplib.html ftp://ftp.digitalmars.com/coffimplib.zip
 2.  Is there anywhere I can download OMF versions of those libraries?

 P.S.  I just checked the Win32 api project, and they don't have lm.h
 converted (for stuff in netlib32), and no .lib files :(
Come on, give us a bit of time... that project only started less than three weeks ago! :-). The lmXXX stuff will come before too long.
No! Not fast enough! :P After having a poke around some of those MinGW headers... yikes. If I ever work out what I'm doing wrong, I might try my hand at converting a few.
 If I can get this working, I'll donate the windows implementation of
 expandTilde (if Walter wants it, of course :).

     -- Daniel "why you no linky, damnit?"
-- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Apr 18 2006