Thread: How can an api be accessed through other languages

  1. #1
    Shadow12345
    Guest

    How can an api be accessed through other languages

    I didn't really know up until a little while ago that an api can be accessed through other languages. In a visual C++ book I am reading it says that the winapi can be accessed through visual basic (duh) but also fortran, pascal, and other languages. How is it possible to make calls to the winapi (which is written mostly in C, right?) with languages such as fortran and pascal?

  2. #2
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    well win32 api is compiled as libraries wich you can link to just about anything since they're modules.. include the header for the apropriate language to get the prototypes of the win32api and link with the libraries you want and then you're ready make calls to them..
    haven't really done this in either fortran or pascal but I've done it in asm and that's the principle...

    maybe I'm wrong but I hope this somewhat helps..

    /btq
    ...viewlexx - julie lexx

  3. #3
    Shadow12345
    Guest
    Hmm okay so are you saying the Microsoft people wrote libraries for every language?

  4. #4
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    no, I'm saying they didn't have to bother ;)
    a DLL that exports its functions can be used by every language
    (maybe to some extent?).

    if you write a simple library with a function called:
    int ret(); that returns the value 4 everytime it's called and export this function, you can use it in every langauge with the apropriate prototype of this function and the propriate linking.

    for instance in masm you use this as the prototype for SetPixel:
    SetPixel PROTO :DWORD,:DWORD,:DWORD,:DWORD

    which is a function exported by Gdi32.dll.
    With this and linking with the Gdi32 library, you can use this function of the library..

    it doesn't really matter in which language you make the library in this aspect..

    hope this helps :)

    /btq
    ...viewlexx - julie lexx

  5. #5
    Shadow12345
    Guest
    This idea is still somewhat hazy. Where, exactly, does the conversion from a C++ prototype to an assembly prototype take place? (I didn't know assembly had functions, I know nothing of the lower level languages).

    if the cpp prototype is:
    void SetPixel(x)
    How does it go from that to
    SetPixel PROTO WORD,WORD,WORD,WORD

    Does the masm linker automatically read through it and convert it for you?

    Yes you are helping!

  6. #6
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    the prototype for SetPixel is
    Code:
    COLORREF SetPixel(
        HDC hdc,	// handle of device context  
        int X,	// x-coordinate of pixel 
        int Y,	// y-coordinate of pixel 
        COLORREF crColor 	// pixel color 
       );
    and this prototype would in masm look like:
    SetPixel PROTO :DWORD,:DWORD,:DWORD,:DWORD
    (in masm this is only used for macros such as Invoke which calls the function, though normally you just push the params on the
    stack and call the functions etc. so that was a bad example. )

    but think of it as a c++ source file. You have a c++ source file with a
    simple function. To use this function in another c++ sourcefile you
    need to include the c++ header file(which contains the prototype).
    this is kinda similar for load-time libraries. You need to know the
    prototypes of the functions to be able to use them...
    and these prototypes must be written in the language you're within..
    the functions that resides in the DLL doesn't care from what
    language you're calling them as long as they get the proper
    params pushed onto the stack etc..

    /btq
    ...viewlexx - julie lexx

  7. #7
    Shadow12345
    Guest
    Ok that makes more sense to me now, cool

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Want to learn Windows API for Game Programming
    By George M. in forum Windows Programming
    Replies: 15
    Last Post: 09-28-2008, 10:26 AM
  2. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  3. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  4. Is it foolish to program with Win32 API ?
    By Kelvin in forum Windows Programming
    Replies: 2
    Last Post: 07-09-2002, 02:03 PM
  5. pthread api vs win32 thread api
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 11-20-2001, 08:55 AM