How do you define Windows API in GUI for .NET?

Posted by jquerijero on 25-Jun-2009 11:37

Or do we need to wrap it inside an ABL procedure?

All Replies

Posted by Peter Judge on 25-Jun-2009 11:43

Or do we need to wrap it inside an ABL procedure?

If you mean something like the code below, there's a bug in 10.2A that prevents you from doing so (so you have to use a .P). Note that you can forward-declare ABL function prototypes in classes in 10.2A without issue.

CLASS foo   : 

    DEFINE VARIABLE iResult AS INTEGER NO-UNDO.
   
    PROCEDURE MessageBoxA EXTERNAL "user32.dll":
        DEFINE INPUT PARAMETER hwnd AS LONG.
        DEFINE INPUT PARAMETER mbtext AS CHARACTER.
        DEFINE INPUT PARAMETER mbtitle AS CHARACTER.
        DEFINE INPUT PARAMETER style AS LONG.
        DEFINE RETURN PARAMETER result AS LONG.
    END.
   
    METHOD VOID runWindowsProc ():
        RUN MessageBoxA (0,
                         " It's a whole new world, again!!",
                         "ABL DLL Access",
                         0,
                         OUTPUT iResult).
    END.


END CLASS.

-- peter

Posted by Matt Baker on 25-Jun-2009 14:19

So to complete this:

    METHOD PUBLIC STATIC INT64 ShowMessageBox (
          hwnd AS INT64,
          mbtitle AS CHARACTER,
          mbtext AS CHARACTER,
          style AS INT64):
             
        DEFINE VARIABLE iResult AS INT64 NO-UNDO.
        RUN MessageBoxA (hwnd,
                         mbtext,
                         mbtitle,
                         style,
                         OUTPUT iResult).
          RETURN iresult.
    END.

Posted by jquerijero on 25-Jun-2009 14:24

That is correct. So we need to use a .p if we ever need to use Win32API.

Posted by Admin on 25-Jun-2009 14:29

Hopefully that "ever" ends with 10.2B - when I understood Peter J. correctly when he said it's a bug in 10.2A.

Posted by jquerijero on 25-Jun-2009 14:34

I think the better syntax would be THIS-OBJECT:MessageBoxA(. . . ).

Posted by Matt Baker on 25-Jun-2009 14:46

I see the MessageBoxA as being a static external definition of a function in user32.dll.  You could remove the static keyword from ShowMessageBox and treat it as a class member, but that would limit its usability.  You would then have to copy the procedure and method definition everywhere you wanted to use it.  You cannot use this-object:ShowMessageBox() on a static method, and you cannot use this-object syntax on a procedure.

Posted by jquerijero on 25-Jun-2009 15:44

I think we are getting mixed up. I'm not talking about how I'm going to implement it. I was just trying to follow the inside class definition sample which make more sense to use the colon syntax than using the RUN syntax.

But anyway;

Procedure (.p) - should remain as is

Class level, non-static definition - THIS-OBJECT:MessageBoxA(...) or myObject:MessageBoxA(...)

Class level, static definition - MyWin32API:MessageBoxA(...)

This thread is closed