www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Declaring Win32 functions

reply "Garett Bass" <gtbass studiotekne.com> writes:
I'm extending the "winsamp.d" sample, and I'm trying to call some GDI
functions that are not included in std.c.windows.  I'm hesitant to modify
std.c.windows, since my modifications will then need to be manually
perpetuated through future versions of dmd.  How can I declare an external
Win32 GDI function within "winsamp.d" itself?

Specifically I'm trying to call the GDI function "GetTextExtentPoint32",
which appears in MSDN as follows:

    BOOL GetTextExtentPoint32(
        HDC hdc,           // handle to DC
        LPCTSTR lpString,  // text string
        int cbString,      // characters in string
        LPSIZE lpSize      // string size
    );

Following the example set out in std.c.windows, I declared the following in
"winsamp.d":

    extern(Windows)
    {
        struct SIZE
        {
            LONG cx;
            LONG cy;
        }
        alias SIZE* PSIZE, LPSIZE;
        export BOOL GetTextExtentPoint32(HDC, LPCSTR, int, LPSIZE);
    }

However, when I compile the application, I get the following error message:

    winsamp.obj(winsamp)
     Error 42: Symbol Undefined _GetTextExtentPoint32 16
    --- errorlevel 1

Any help would be greatly appreciated.

Regards,
Garett
Aug 03 2004
next sibling parent reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
Are you linking in user32.lib?

"Garett Bass" <gtbass studiotekne.com> wrote in message
news:ceptge$1vho$1 digitaldaemon.com...
 I'm extending the "winsamp.d" sample, and I'm trying to call some GDI
 functions that are not included in std.c.windows.  I'm hesitant to modify
 std.c.windows, since my modifications will then need to be manually
 perpetuated through future versions of dmd.  How can I declare an external
 Win32 GDI function within "winsamp.d" itself?

 Specifically I'm trying to call the GDI function "GetTextExtentPoint32",
 which appears in MSDN as follows:

     BOOL GetTextExtentPoint32(
         HDC hdc,           // handle to DC
         LPCTSTR lpString,  // text string
         int cbString,      // characters in string
         LPSIZE lpSize      // string size
     );

 Following the example set out in std.c.windows, I declared the following in
 "winsamp.d":

     extern(Windows)
     {
         struct SIZE
         {
             LONG cx;
             LONG cy;
         }
         alias SIZE* PSIZE, LPSIZE;
         export BOOL GetTextExtentPoint32(HDC, LPCSTR, int, LPSIZE);
     }

 However, when I compile the application, I get the following error message:

     winsamp.obj(winsamp)
      Error 42: Symbol Undefined _GetTextExtentPoint32 16
     --- errorlevel 1

 Any help would be greatly appreciated.

 Regards,
 Garett
Aug 03 2004
parent reply "Garett Bass" <gtbass studiotekne.com> writes:
Matthew wrote:
 Are you linking in user32.lib?
Thanks for your swift response. MSDN states that GetTextExtentPoint32 is defined accessed through gdi32.lib, so I'm not sure how user32.lib is indicated in this situation. I was not explicity linking to user32.lib. However, I get the impression that user32.lib was being linked automatically by dmd: D:\Code\Compilers\D\dmd\samples\d\winsamp>dmd winsamp.d gdi32.lib winsamp.def D:\Code\Compilers\D\dmd\bin\..\..\dm\bin\link.exe winsamp,,,gdi32.lib+user32+ker nel32,winsamp.def/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved winsamp.obj(winsamp) Error 42: Symbol Undefined _GetTextExtentPoint32 16 --- errorlevel 1 Unfortunately, adding user32.lib to the dmd command line, as follows, produces the same error: D:\Code\Compilers\D\dmd\samples\d\winsamp>dmd winsamp.d gdi32.lib user32.lib win samp.def D:\Code\Compilers\D\dmd\bin\..\..\dm\bin\link.exe winsamp,,,gdi32.lib+user32.lib +user32+kernel32,winsamp.def/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved winsamp.obj(winsamp) Error 42: Symbol Undefined _GetTextExtentPoint32 16 --- errorlevel 1
Aug 03 2004
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Garett Bass" <gtbass studiotekne.com> wrote in message
news:cepuck$1vs1$1 digitaldaemon.com...
 Matthew wrote:
 Are you linking in user32.lib?
Thanks for your swift response. MSDN states that GetTextExtentPoint32 is defined accessed through gdi32.lib, so I'm not sure how user32.lib is indicated in this situation. I was not explicity linking to user32.lib. However, I get the impression that user32.lib was being linked
automatically
 by dmd:

     D:\Code\Compilers\D\dmd\samples\d\winsamp>dmd winsamp.d gdi32.lib
 winsamp.def
As in the example, you need to explicitly specify gdi32.lib on the command line.
Aug 03 2004
parent reply "Garett Bass" <gtbass studiotekne.com> writes:
 Garett Bass wrote:
 D:\Code\Compilers\D\dmd\samples\d\winsamp>dmd winsamp.d
 gdi32.lib winsamp.def
 Matthew wrote:
 Are you linking in user32.lib?
 Walter wrote:
 As in the example, you need to explicitly specify gdi32.lib
 on the command line.
Gentlemen, please excuse me if I've not been clear about my problem, but none of your responses have directly addressed the issue of my original question. Please look closely at my command line, and you will see that I am explicitly linking to gdi32.lib. The problem, in my case, is how to *declare* Win32 functions that are not exposed by std.c.windows so that I may use them in my extensions to the sample. Specifically I'm trying to call the GDI function "GetTextExtentPoint32", which appears in MSDN as follows: BOOL GetTextExtentPoint32( HDC hdc, // handle to DC LPCTSTR lpString, // text string int cbString, // characters in string LPSIZE lpSize // string size ); Following the example set out in std.c.windows, I declared the following directly within "winsamp.d": extern(Windows) { struct SIZE { LONG cx; LONG cy; } alias SIZE* PSIZE, LPSIZE; export BOOL GetTextExtentPoint32(HDC, LPCSTR, int, LPSIZE); } However, when I compile the application -- and please notice here I am explicitly linking with gdi32.lib -- I get the following error message: D:\Code\Compilers\D\dmd\samples\d\winsamp>dmd winsamp.d gdi32.lib winsamp.def ... winsamp.obj(winsamp) Error 42: Symbol Undefined _GetTextExtentPoint32 16 --- errorlevel 1
Aug 04 2004
parent Ilya Minkov <minkov cs.tum.edu> writes:
Garett Bass schrieb:

MSDN has been lying. :) The function you are trying to use does not exist.

 Following the example set out in std.c.windows, I declared the following
 directly within "winsamp.d":
 
     extern(Windows)
     {
         struct SIZE
         {
             LONG cx;
             LONG cy;
         }
         alias SIZE* PSIZE, LPSIZE;
//export BOOL GetTextExtentPoint32(HDC, LPCSTR, int, LPSIZE); export BOOL GetTextExtentPoint32A(HDC, LPCSTR, int, LPSIZE); export BOOL GetTextExtentPoint32W(HDC, LPCSTR, int, LPSIZE);
     }
alias GetTextExtentPoint32A GetTextExtentPoint32; All windows functions are defined as either ASCII or Widechar(Unicode) versions, or both. The MSDN names are created in the header files by the preprocessor, or aliases in D. You must be careful because if the functions accept structs, these can have the same layout but different underlying types for unicode and ASCII versions. Better you use a more complete translation of windows headers already available. Do some text search in the LIB files if you have any linking problems, it can be of much help. -eye
Aug 14 2004
prev sibling parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
Gah! I meant gdi32. Sorry for the misdirection.

"Garett Bass" <gtbass studiotekne.com> wrote in message
news:cepuck$1vs1$1 digitaldaemon.com...
 Matthew wrote:
 Are you linking in user32.lib?
Thanks for your swift response. MSDN states that GetTextExtentPoint32 is defined accessed through gdi32.lib, so I'm not sure how user32.lib is indicated in this situation. I was not explicity linking to user32.lib. However, I get the impression that user32.lib was being linked automatically by dmd: D:\Code\Compilers\D\dmd\samples\d\winsamp>dmd winsamp.d gdi32.lib winsamp.def D:\Code\Compilers\D\dmd\bin\..\..\dm\bin\link.exe winsamp,,,gdi32.lib+user32+ker nel32,winsamp.def/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved winsamp.obj(winsamp) Error 42: Symbol Undefined _GetTextExtentPoint32 16 --- errorlevel 1 Unfortunately, adding user32.lib to the dmd command line, as follows, produces the same error: D:\Code\Compilers\D\dmd\samples\d\winsamp>dmd winsamp.d gdi32.lib user32.lib win samp.def D:\Code\Compilers\D\dmd\bin\..\..\dm\bin\link.exe winsamp,,,gdi32.lib+user32.lib +user32+kernel32,winsamp.def/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved winsamp.obj(winsamp) Error 42: Symbol Undefined _GetTextExtentPoint32 16 --- errorlevel 1
Aug 03 2004
prev sibling parent reply "Garett Bass" <gtbass studiotekne.com> writes:
Resolution:

    For the sake of those who may struggle with this in the future, the
solution was simple.  It is, in fact, GetTextExtentPoint32A -- notice the
"A" at the end -- not GetTextExtentPoint32 that is exported by gdi32.lib.
I'll have to look in the header files rather than the documentation in the
future.  In this case, I simply openned gdi32.lib in a text editor and
searched for "GetTextExtentPoint32".  Quite handy.

Best Regards,
Garett
Aug 04 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
In article <ceqp7f$2n9f$1 digitaldaemon.com>, Garett Bass says...
Resolution:

    For the sake of those who may struggle with this in the future, the
solution was simple.  It is, in fact, GetTextExtentPoint32A -- notice the
"A" at the end -- not GetTextExtentPoint32 that is exported by gdi32.lib.
I'll have to look in the header files rather than the documentation in the
future.  In this case, I simply openned gdi32.lib in a text editor and
searched for "GetTextExtentPoint32".  Quite handy.

Best Regards,
Garett
It sounds like what you're doing works, but it might be easier to pick up where someone else left off. There are a couple projects to port the Windows header files to D: Mike Wynn: http://dsource.org/projects/core32/ http://www.geocities.com/one_mad_alien/dcom_not_dcom.html The page is Japanese, but the port is good (and in English): http://hp.vector.co.jp/authors/VA028375/d/windows.h.html Also, you might find it helpful to get Microsoft's Platform SDK, but I can't remember the specific URL (and I think you might need to use Windows Update to download it -- yuck!). jcc7
Aug 04 2004
parent "Matthew" <admin.hat stlsoft.dot.org> writes:
"J C Calvarese" <jcc7 cox.net> wrote in message
news:ceqss3$2ula$1 digitaldaemon.com...
 In article <ceqp7f$2n9f$1 digitaldaemon.com>, Garett Bass says...
Resolution:

    For the sake of those who may struggle with this in the future, the
solution was simple.  It is, in fact, GetTextExtentPoint32A -- notice the
"A" at the end -- not GetTextExtentPoint32 that is exported by gdi32.lib.
I'll have to look in the header files rather than the documentation in the
future.  In this case, I simply openned gdi32.lib in a text editor and
searched for "GetTextExtentPoint32".  Quite handy.

Best Regards,
Garett
It sounds like what you're doing works, but it might be easier to pick up where someone else left off. There are a couple projects to port the Windows header files to D: Mike Wynn: http://dsource.org/projects/core32/ http://www.geocities.com/one_mad_alien/dcom_not_dcom.html The page is Japanese, but the port is good (and in English): http://hp.vector.co.jp/authors/VA028375/d/windows.h.html Also, you might find it helpful to get Microsoft's Platform SDK, but I can't remember the specific URL (and I think you might need to use Windows Update to download it -- yuck!).
You don't. IIRC, it's the Feb 2003 PSDK. I found the site a couple of weeks ago to get the latest update, but it's still Feb 03, so I didn't need to.
Aug 04 2004