[Newbie] Explicit DLL Confusion - Programmer

This is a discussion on [Newbie] Explicit DLL Confusion - Programmer ; Hi All, I am trying to use the well-known inpout32.dll to read the parallel port under XP, and am having some difficulty figuring out what is going on. I understand the use of LoadLibrary() to return a handle, but GetProcAddress() ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: [Newbie] Explicit DLL Confusion

  1. [Newbie] Explicit DLL Confusion

    Hi All,

    I am trying to use the well-known inpout32.dll to read the parallel
    port under XP, and am having some difficulty figuring out what is
    going on. I understand the use of LoadLibrary() to return a handle,
    but GetProcAddress() has me tearing my hair out.

    Lets start with what I know already - the definitions of the two
    functions that I want to use in the dll are:

    short __stdcall Inp32(short port_address)
    void __stdcall Out32(short port_address,short data)

    Now the example code that I am looking at starts by declaring two
    typedefs for these functions of the form:

    typedef short __stdcall (*in_function_ptr)(short port_address);
    typedef void __stdcall (*out_function_ptr)(short port_address, short
    data);

    When I look at this I start to panic. If a typedef is just an alias
    between a known type and a user-defined name (such as typedef int
    kilometres) then what is going on above? How can you possibly have a
    typedef like those above that is not grossly illegal? How can you
    have a typedef for a function like this?

    Until I understand what is going on with this bit I have no hope of
    understanding the subsequent use of GetProcAddress() which follows.

    Any replies most welcome!

  2. Re: [Newbie] Explicit DLL Confusion

    Rodney B. Elliott wrote:

    > Hi All,
    >
    > I am trying to use the well-known inpout32.dll to read the parallel
    > port under XP, and am having some difficulty figuring out what is
    > going on. I understand the use of LoadLibrary() to return a handle,
    > but GetProcAddress() has me tearing my hair out.
    >
    > Lets start with what I know already - the definitions of the two
    > functions that I want to use in the dll are:
    >
    > short __stdcall Inp32(short port_address)
    > void __stdcall Out32(short port_address,short data)
    >
    > Now the example code that I am looking at starts by declaring two
    > typedefs for these functions of the form:
    >
    > typedef short __stdcall (*in_function_ptr)(short port_address);
    > typedef void __stdcall (*out_function_ptr)(short port_address, short
    > data);
    >
    > When I look at this I start to panic. If a typedef is just an alias
    > between a known type and a user-defined name (such as typedef int
    > kilometres) then what is going on above? How can you possibly have a
    > typedef like those above that is not grossly illegal? How can you
    > have a typedef for a function like this?
    >
    > Until I understand what is going on with this bit I have no hope of
    > understanding the subsequent use of GetProcAddress() which follows.
    >
    > Any replies most welcome!


    You are looking at the standard syntax for declaring a function pointer
    type. Legal and well documented in any C language book. If you are not
    familiar with function pointer concepts then GetProcAddress won't make
    much sense, so brush up on C function pointers before proceeding.

    --
    Scott McPhillips [VC++ MVP]


  3. Re: [Newbie] Explicit DLL Confusion

    "Rodney B. Elliott" wrote:

    > Lets start with what I know already - the definitions of the two
    > functions that I want to use in the dll are:
    >
    > short __stdcall Inp32(short port_address)
    > void __stdcall Out32(short port_address,short data)
    >
    > Now the example code that I am looking at starts by declaring two
    > typedefs for these functions of the form:
    >
    > typedef short __stdcall (*in_function_ptr)(short port_address);
    > typedef void __stdcall (*out_function_ptr)(short port_address, short
    > data);


    A tiny but important detail is wrong in the above. This should be:
    typedef short (__stdcall *in_function_ptr)(short port_address);
    typedef void (__stdcall *out_function_ptr)(short port_address, short data);

    --gv

+ Reply to Thread