www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Undefined Windows function

reply Kramer <Kramer_member pathlink.com> writes:
I'm trying to use a Windows function that I don't think is defined with the DMD
distribution.  The code below seems to compile just fine, but I'm getting linker
errors.  I know that means the linker can't find the function in the object
files, but I'm not sure how to proceed.  I've given my best effort to provide
the windows data structure and function definitions and am also linking to
user32.lib which is what Microsoft says is the library that contains the
function I'm looking for, but still to no avail.  Any ideas would be greatly
appreciated.

** I hope this code posts ok.  The web interface doesn't always preserve spacing
that great. :(





























This is what I compile with: dmd test.d user32.lib

And this is the output:
c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32.lib+user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

test.obj(test)
Error 42: Symbol Undefined _GetWindowInfo 8
--- errorlevel 1

Thanks in advance.

-Kramer
Sep 17 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer  
<Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with  
 the DMD
 distribution.  The code below seems to compile just fine, but I'm  
 getting linker
 errors.  I know that means the linker can't find the function in the  
 object
 files, but I'm not sure how to proceed.  I've given my best effort to  
 provide
 the windows data structure and function definitions and am also linking  
 to
 user32.lib which is what Microsoft says is the library that contains the
 function I'm looking for, but still to no avail.  Any ideas would be  
 greatly
 appreciated.

 ** I hope this code posts ok.  The web interface doesn't always preserve  
 spacing
 that great. :(





























 This is what I compile with: dmd test.d user32.lib

 And this is the output:
 c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32.lib+user32+kernel32/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 test.obj(test)
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1

 Thanks in advance.
The DMC libraries and include files do not seem to contain this function. I suspect that is because it is reasonably new. (MSDN for MSVS6 does not have it, MSDN for VS.NET Beta 2 does). I am not sure how to solve it. I wonder if you can link with the MS libraries, you probably have to convert the library file format first. I would be interested to know the answer too. Regan
Sep 17 2005
parent reply "John C" <johnch_atms hotmail.com> writes:
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer 
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with 
 the DMD
 distribution.  The code below seems to compile just fine, but I'm 
 getting linker
 errors.  I know that means the linker can't find the function in the 
 object
 files, but I'm not sure how to proceed.  I've given my best effort to 
 provide
 the windows data structure and function definitions and am also linking 
 to
 user32.lib which is what Microsoft says is the library that contains the
 function I'm looking for, but still to no avail.  Any ideas would be 
 greatly
 appreciated.

 ** I hope this code posts ok.  The web interface doesn't always preserve 
 spacing
 that great. :(





























 This is what I compile with: dmd test.d user32.lib

 And this is the output:
 c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32.lib+user32+kernel32/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 test.obj(test)
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1

 Thanks in advance.
The DMC libraries and include files do not seem to contain this function. I suspect that is because it is reasonably new. (MSDN for MSVS6 does not have it, MSDN for VS.NET Beta 2 does). I am not sure how to solve it. I wonder if you can link with the MS libraries, you probably have to convert the library file format first. I would be interested to know the answer too. Regan
The Win32 libraries distributed with D are very old, from 1995-1996, so anything introduced in Windows 98 and upwards won't be available. You can either call functions at runtime with GetProcAddress, or link them in at compile time. To do the latter, you need to create a new library file defining the function you wish to import, like so: 1) Create a new text file, called "user32ex.def", with the following content: LIBRARY user32 IMPORTS 2) Now list all the functions the linker says are undefined, eg _GetWindowInfo 8 = GetWindowInfo 3) Go to http://www.digitalmars.com/download/freecompiler.html and download the free "Basic Utilities" package, and unzip to c:\dm\bin or wherever your dm\bin directory is located. Then at the command line, cd to the directory you created the user32ex.def file (usually c:\dm\lib) and enter this: c:\dm\bin\implib user32ex.lib user32ex.def 4) Add user32ex.lib to your dmd command line when compiling John.
Sep 17 2005
next sibling parent Kramer <Kramer_member pathlink.com> writes:
In article <dggt4s$19u$1 digitaldaemon.com>, John C says...
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer 
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with 
 the DMD
 distribution.  The code below seems to compile just fine, but I'm 
 getting linker
 errors.  I know that means the linker can't find the function in the 
 object
 files, but I'm not sure how to proceed.  I've given my best effort to 
 provide
 the windows data structure and function definitions and am also linking 
 to
 user32.lib which is what Microsoft says is the library that contains the
 function I'm looking for, but still to no avail.  Any ideas would be 
 greatly
 appreciated.

 ** I hope this code posts ok.  The web interface doesn't always preserve 
 spacing
 that great. :(





























 This is what I compile with: dmd test.d user32.lib

 And this is the output:
 c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32.lib+user32+kernel32/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 test.obj(test)
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1

 Thanks in advance.
The DMC libraries and include files do not seem to contain this function. I suspect that is because it is reasonably new. (MSDN for MSVS6 does not have it, MSDN for VS.NET Beta 2 does). I am not sure how to solve it. I wonder if you can link with the MS libraries, you probably have to convert the library file format first. I would be interested to know the answer too. Regan
The Win32 libraries distributed with D are very old, from 1995-1996, so anything introduced in Windows 98 and upwards won't be available. You can either call functions at runtime with GetProcAddress, or link them in at compile time. To do the latter, you need to create a new library file defining the function you wish to import, like so: 1) Create a new text file, called "user32ex.def", with the following content: LIBRARY user32 IMPORTS 2) Now list all the functions the linker says are undefined, eg _GetWindowInfo 8 = GetWindowInfo 3) Go to http://www.digitalmars.com/download/freecompiler.html and download the free "Basic Utilities" package, and unzip to c:\dm\bin or wherever your dm\bin directory is located. Then at the command line, cd to the directory you created the user32ex.def file (usually c:\dm\lib) and enter this: c:\dm\bin\implib user32ex.lib user32ex.def 4) Add user32ex.lib to your dmd command line when compiling John.
Great. Thanks a lot for both responses. I will definitely be trying this. Out of curiosity though, what is the " 8" at the end of the function name. I don't know how to decipher the managled names. Thanks again. -Kramer
Sep 17 2005
prev sibling next sibling parent reply Kramer <Kramer_member pathlink.com> writes:
In article <dggt4s$19u$1 digitaldaemon.com>, John C says...
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer 
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with 
 the DMD
 distribution.  The code below seems to compile just fine, but I'm 
 getting linker
 errors.  I know that means the linker can't find the function in the 
 object
 files, but I'm not sure how to proceed.  I've given my best effort to 
 provide
 the windows data structure and function definitions and am also linking 
 to
 user32.lib which is what Microsoft says is the library that contains the
 function I'm looking for, but still to no avail.  Any ideas would be 
 greatly
 appreciated.

 ** I hope this code posts ok.  The web interface doesn't always preserve 
 spacing
 that great. :(





























 This is what I compile with: dmd test.d user32.lib

 And this is the output:
 c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32.lib+user32+kernel32/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 test.obj(test)
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1

 Thanks in advance.
The DMC libraries and include files do not seem to contain this function. I suspect that is because it is reasonably new. (MSDN for MSVS6 does not have it, MSDN for VS.NET Beta 2 does). I am not sure how to solve it. I wonder if you can link with the MS libraries, you probably have to convert the library file format first. I would be interested to know the answer too. Regan
The Win32 libraries distributed with D are very old, from 1995-1996, so anything introduced in Windows 98 and upwards won't be available. You can either call functions at runtime with GetProcAddress, or link them in at compile time. To do the latter, you need to create a new library file defining the function you wish to import, like so: 1) Create a new text file, called "user32ex.def", with the following content: LIBRARY user32 IMPORTS 2) Now list all the functions the linker says are undefined, eg _GetWindowInfo 8 = GetWindowInfo 3) Go to http://www.digitalmars.com/download/freecompiler.html and download the free "Basic Utilities" package, and unzip to c:\dm\bin or wherever your dm\bin directory is located. Then at the command line, cd to the directory you created the user32ex.def file (usually c:\dm\lib) and enter this: c:\dm\bin\implib user32ex.lib user32ex.def 4) Add user32ex.lib to your dmd command line when compiling John.
Great. Thanks a lot for both responses. I will definitely be trying this. Out of curiosity though, what is the " 8" at the end of the function name. I don't know how to decipher the managled names. Thanks again. -Kramer
Sep 17 2005
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Kramer" <Kramer_member pathlink.com> wrote in message 
news:dghiki$jf2$1 digitaldaemon.com...
 Great.  Thanks a lot for both responses.  I will definitely be trying 
 this.  Out
 of curiosity though, what is the " 8" at the end of the function name.  I 
 don't
 know how to decipher the managled names.
The number after the is the number of bytes that are passed into the function as parameters. So a function that takes two int params (as this function does) will take 2 * 4 = 8 bytes. The _ at the beginning is also part of the mangling.
Sep 17 2005
prev sibling next sibling parent reply Kramer <Kramer_member pathlink.com> writes:
In article <dggt4s$19u$1 digitaldaemon.com>, John C says...
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer 
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with 
 the DMD
 distribution.  The code below seems to compile just fine, but I'm 
 getting linker
 errors.  I know that means the linker can't find the function in the 
 object
 files, but I'm not sure how to proceed.  I've given my best effort to 
 provide
 the windows data structure and function definitions and am also linking 
 to
 user32.lib which is what Microsoft says is the library that contains the
 function I'm looking for, but still to no avail.  Any ideas would be 
 greatly
 appreciated.

 ** I hope this code posts ok.  The web interface doesn't always preserve 
 spacing
 that great. :(





























 This is what I compile with: dmd test.d user32.lib

 And this is the output:
 c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32.lib+user32+kernel32/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 test.obj(test)
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1

 Thanks in advance.
The DMC libraries and include files do not seem to contain this function. I suspect that is because it is reasonably new. (MSDN for MSVS6 does not have it, MSDN for VS.NET Beta 2 does). I am not sure how to solve it. I wonder if you can link with the MS libraries, you probably have to convert the library file format first. I would be interested to know the answer too. Regan
The Win32 libraries distributed with D are very old, from 1995-1996, so anything introduced in Windows 98 and upwards won't be available. You can either call functions at runtime with GetProcAddress, or link them in at compile time. To do the latter, you need to create a new library file defining the function you wish to import, like so: 1) Create a new text file, called "user32ex.def", with the following content: LIBRARY user32 IMPORTS 2) Now list all the functions the linker says are undefined, eg _GetWindowInfo 8 = GetWindowInfo 3) Go to http://www.digitalmars.com/download/freecompiler.html and download the free "Basic Utilities" package, and unzip to c:\dm\bin or wherever your dm\bin directory is located. Then at the command line, cd to the directory you created the user32ex.def file (usually c:\dm\lib) and enter this: c:\dm\bin\implib user32ex.lib user32ex.def 4) Add user32ex.lib to your dmd command line when compiling John.
Well, I was able to create the library. Just wanted to post what I did (John thanks for the starting point; I used the user32_swt.def file from the DWT project as a working example). Here's my user32ex.def file: LIBRARY 'USER32.DLL' EXPORTS _GetWindowInfo 8 = GetWindowInfo _GetWindowModuleFileNameW 12 = GetWindowModuleFileNameW 12 And there here's the command line: c:\> implib user32ex.lib user32ex.def I'm trying to get the name of the program for whatever window has current focus. I hope this works! Thanks for the help! -Kramer
Sep 17 2005
parent J C Calvarese <technocrat7 gmail.com> writes:
In article <dghq20$qp0$1 digitaldaemon.com>, Kramer says...
In article <dggt4s$19u$1 digitaldaemon.com>, John C says...
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer 
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with 
 the DMD
 distribution.  The code below seems to compile just fine, but I'm 
 getting linker
 errors.  I know that means the linker can't find the function in the 
 object
 files, but I'm not sure how to proceed.  I've given my best effort to 
 provide
 the windows data structure and function definitions and am also linking 
 to
 user32.lib which is what Microsoft says is the library that contains the
 function I'm looking for, but still to no avail.  Any ideas would be 
 greatly
 appreciated.
..
Well, I was able to create the library.  Just wanted to post what I did (John
thanks for the starting point; I used the user32_swt.def file from the DWT
project as a working example).

Here's my user32ex.def file:
LIBRARY 'USER32.DLL'

EXPORTS

_GetWindowInfo 8 = GetWindowInfo
_GetWindowModuleFileNameW 12 = GetWindowModuleFileNameW 12

And there here's the command line:
c:\> implib user32ex.lib user32ex.def

I'm trying to get the name of the program for whatever window has current focus.
I hope this works!

Thanks for the help!

-Kramer
By the way, these aren't the only definition missing in DM's .lib files. Some expanded .def files can be found here: http://svn.dsource.org/projects/bindings/trunk/def/ They include more definitions that the DM files do, so I use them instead of using the DM versions. They're kind of hacked together, so YMMV. Also, it seems there's not one for USER32.DLL yet, but I guess there should be. jcc7
Sep 17 2005
prev sibling parent reply J C Calvarese <technocrat7 gmail.com> writes:
In article <dggt4s$19u$1 digitaldaemon.com>, John C says...
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer 
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with 
 the DMD
 distribution.  The code below seems to compile just fine, but I'm 
 getting linker
 errors.  I know that means the linker can't find the function in the 
 object
 files, but I'm not sure how to proceed.  I've given my best effort to 
 provide
 the windows data structure and function definitions and am also linking 
 to
 user32.lib which is what Microsoft says is the library that contains the
 function I'm looking for, but still to no avail.  Any ideas would be 
 greatly
 appreciated.
..
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1

 Thanks in advance.
The DMC libraries and include files do not seem to contain this function. I suspect that is because it is reasonably new. (MSDN for MSVS6 does not have it, MSDN for VS.NET Beta 2 does). I am not sure how to solve it. I wonder if you can link with the MS libraries, you probably have to convert the library file format first. I would be interested to know the answer too. Regan
The Win32 libraries distributed with D are very old, from 1995-1996, so anything introduced in Windows 98 and upwards won't be available. You can either call functions at runtime with GetProcAddress, or link them in at compile time. To do the latter, you need to create a new library file defining the function you wish to import, like so: 1) Create a new text file, called "user32ex.def", with the following content: LIBRARY user32 IMPORTS 2) Now list all the functions the linker says are undefined, eg _GetWindowInfo 8 = GetWindowInfo 3) Go to http://www.digitalmars.com/download/freecompiler.html and download the free "Basic Utilities" package, and unzip to c:\dm\bin or wherever your dm\bin directory is located. Then at the command line, cd to the directory you created the user32ex.def file (usually c:\dm\lib) and enter this: c:\dm\bin\implib user32ex.lib user32ex.def 4) Add user32ex.lib to your dmd command line when compiling John.
I think you explained the problem and solution very well, so I added your explanation to the wiki at the "error messages" page at: http://www.prowiki.org/wiki4d/wiki.cgi?ErrorMessages#Youneglectedtoprovidethelinkerwithaneededbinaryfile jcc7
Sep 17 2005
parent reply "John C" <johnch_atms hotmail.com> writes:
"J C Calvarese" <technocrat7 gmail.com> wrote in message 
news:dgi1da$10mn$1 digitaldaemon.com...
 In article <dggt4s$19u$1 digitaldaemon.com>, John C says...
"Regan Heath" <regan netwin.co.nz> wrote in message
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with
 the DMD
 distribution.  The code below seems to compile just fine, but I'm
 getting linker
 errors.  I know that means the linker can't find the function in the
 object
 files, but I'm not sure how to proceed.  I've given my best effort to
 provide
 the windows data structure and function definitions and am also linking
 to
 user32.lib which is what Microsoft says is the library that contains 
 the
 function I'm looking for, but still to no avail.  Any ideas would be
 greatly
 appreciated.
..
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1

 Thanks in advance.
The DMC libraries and include files do not seem to contain this function. I suspect that is because it is reasonably new. (MSDN for MSVS6 does not have it, MSDN for VS.NET Beta 2 does). I am not sure how to solve it. I wonder if you can link with the MS libraries, you probably have to convert the library file format first. I would be interested to know the answer too. Regan
The Win32 libraries distributed with D are very old, from 1995-1996, so anything introduced in Windows 98 and upwards won't be available. You can either call functions at runtime with GetProcAddress, or link them in at compile time. To do the latter, you need to create a new library file defining the function you wish to import, like so: 1) Create a new text file, called "user32ex.def", with the following content: LIBRARY user32 IMPORTS 2) Now list all the functions the linker says are undefined, eg _GetWindowInfo 8 = GetWindowInfo 3) Go to http://www.digitalmars.com/download/freecompiler.html and download the free "Basic Utilities" package, and unzip to c:\dm\bin or wherever your dm\bin directory is located. Then at the command line, cd to the directory you created the user32ex.def file (usually c:\dm\lib) and enter this: c:\dm\bin\implib user32ex.lib user32ex.def 4) Add user32ex.lib to your dmd command line when compiling John.
I think you explained the problem and solution very well, so I added your explanation to the wiki at the "error messages" page at: http://www.prowiki.org/wiki4d/wiki.cgi?ErrorMessages#Youneglectedtoprovidethelinkerwithaneededbinaryfile jcc7
Cool. Of course, I made a slight error. "IMPORTS" should be "EXPORTS".
Sep 17 2005
parent J C Calvarese <technocrat7 gmail.com> writes:
In article <dgi423$12v5$1 digitaldaemon.com>, John C says...
"J C Calvarese" <technocrat7 gmail.com> wrote in message 
news:dgi1da$10mn$1 digitaldaemon.com...
 In article <dggt4s$19u$1 digitaldaemon.com>, John C says...
"Regan Heath" <regan netwin.co.nz> wrote in message
news:opsw8pdwk423k2f5 nrage.netwin.co.nz...
 On Sat, 17 Sep 2005 09:05:40 +0000 (UTC), Kramer
 <Kramer_member pathlink.com> wrote:
 I'm trying to use a Windows function that I don't think is defined with
 the DMD
 distribution.  The code below seems to compile just fine, but I'm
 getting linker
 errors.  I know that means the linker can't find the function in the
 object
 files, but I'm not sure how to proceed.  I've given my best effort to
 provide
 the windows data structure and function definitions and am also linking
 to
 user32.lib which is what Microsoft says is the library that contains 
 the
 function I'm looking for, but still to no avail.  Any ideas would be
 greatly
 appreciated.
..
 Error 42: Symbol Undefined _GetWindowInfo 8
 --- errorlevel 1
..
    IMPORTS

2) Now list all the functions the linker says are undefined, eg

    _GetWindowInfo 8 = GetWindowInfo

3) Go to http://www.digitalmars.com/download/freecompiler.html and 
download
the free "Basic Utilities" package, and unzip to c:\dm\bin or wherever 
your
dm\bin directory is located. Then at the command line, cd to the directory
you created the user32ex.def file (usually c:\dm\lib) and enter this:

    c:\dm\bin\implib user32ex.lib user32ex.def

4) Add user32ex.lib to your dmd command line when compiling

John.
I think you explained the problem and solution very well, so I added your explanation to the wiki at the "error messages" page at: http://www.prowiki.org/wiki4d/wiki.cgi?ErrorMessages#Youneglectedtoprovidethelinkerwithaneededbinaryfile jcc7
Cool. Of course, I made a slight error. "IMPORTS" should be "EXPORTS".
Ah, that's right. I fixed it at the wiki. Thanks again. jcc7
Sep 17 2005