Results 1 to 6 of 6

Thread: qt about powerbasic :)

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    52
    Posts
    944
    Rep Power
    111

    qt about powerbasic :)

    short comeback

    please, can anybody help to fix this powerbasic dll example "input.bas" ? I tried to compile it but without success, line 28 may be a problem. I want to understand the dll handling for thinbasic too. I was working at an project during my training course (with freebasic and thinbasic for one of our programming course as viewing how to create message boxes examples). Now I would like to understand how to do this one on pb

    I have bought last week-end powerbasic 9.1 and have had a short look at this interesting tool. now my first question. would be great to get any help. I have in mind to create new things for thinbasic too, my novel is going up to the end now and I am very proud of it to finish the book until end of october, so there will be more time for thinbasic.

    powerbasic code:

    [code=thinbasic]'
    ' Example DLL to display a modal dialog and return a value to the calling
    ' application.
    '
    ' Requires PB/DLL v1.10 or later to compile.
    '

    $COMPILE DLL

    $INCLUDE "WIN32API.INC"

    DECLARE FUNCTION InputDlgProc(BYVAL hDlg AS INTEGER, _
    BYVAL wMsg AS INTEGER, _
    BYVAL wParam AS INTEGER, _
    BYVAL lParam AS LONG) AS INTEGER


    GLOBAL DlgAddr AS DWORD
    GLOBAL hCurInstance AS WORD

    GLOBAL gText AS ASCIIZ * 255
    GLOBAL gCaption AS ASCIIZ * 255
    GLOBAL gDefault AS ASCIIZ * 255

    FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _
    BYVAL wDataSeg AS DWORD, _
    BYVAL wHeapSize AS DWORD, _
    lpszCmdLine AS ASCIIZ) EXPORT AS INTEGER ' ??? mistake here?

    'Save the instance handle of the DLL
    hCurInstance = hInstance

    'Remember! We have to return a "one" to indicate successful
    ' initialization
    LIBMAIN = 1 'success!

    END FUNCTION


    FUNCTION InputBox(TEXT AS ASCIIZ PTR, _
    Caption AS ASCIIZ PTR, _
    DEFAULT AS ASCIIZ PTR) EXPORT AS INTEGER

    ' Get the address of the dialog callback
    DlgAddr = MakeProcInstance(CODEPTR(InputDlgProc), hCurInstance)

    ' If pointers are non-null, set default values for dialog
    IF TEXT THEN
    gText = @TEXT
    ELSE
    gText = "Enter Text"
    END IF

    IF Caption THEN
    gCaption = @Caption
    ELSE
    gCaption = "INPUT BOX"
    END IF

    IF DEFAULT THEN
    gDefault = @DEFAULT
    ELSE
    gDefault = ""
    END IF

    ' Pop up the modal dialog and get return value
    FUNCTION = DialogBox(hCurInstance, "INPUTBOX", 0, DlgAddr)

    ' If default buffer was passed, return the input text
    IF DEFAULT THEN
    @DEFAULT = gDefault
    END IF

    END FUNCTION


    ' **
    ' ** Generic routine to center any window given its handle.
    ' **
    SUB CenterWindow(BYVAL hWnd AS WORD)

    DIM WndRect AS RECT
    DIM x AS INTEGER
    DIM y AS INTEGER

    GetWindowRect hWnd, WndRect

    x = (GetSystemMetrics(%SM_CXSCREEN)-(WndRect.nRight-WndRect.nLeft))\2
    y = (GetSystemMetrics(%SM_CYSCREEN)-(WndRect.nBottom-WndRect.nTop+GetSystemMetrics(%SM_CYCAPTION)))\2

    SetWindowPos hWnd, %NULL, x, y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER

    END SUB


    FUNCTION InputDlgProc(BYVAL hDlg AS INTEGER, _
    BYVAL wMsg AS INTEGER, _
    BYVAL wParam AS INTEGER, _
    BYVAL lParam AS LONG) EXPORT AS INTEGER

    ' See INPUTBOX.RC script for details on the dialog itself

    SELECT CASE wMsg
    CASE %WM_INITDIALOG

    'Center the window
    CenterWindow hDlg

    'Assign the initial values to the dialog
    SetWindowText GetDlgItem(hDlg, 101), gText
    SetWindowText GetDlgItem(hDlg, 102), gDefault
    SetWindowText hDlg, gCaption

    FUNCTION = 1
    EXIT FUNCTION

    CASE %WM_COMMAND
    SELECT CASE wParam
    CASE 103, %IDOK
    'When the "OK" button is pressed, get the edit box value
    ' and end the dialog
    GetWindowText GetDlgItem(hDlg, 102), gDefault, 255
    EndDialog hDlg, 1
    FUNCTION = 1
    EXIT FUNCTION
    'When the "CANCEL" button is pressed, or escape is pressed, or
    ' the dialog is closed, end the dialog
    CASE 104, %IDCANCEL
    EndDialog hDlg, 0
    FUNCTION = 1
    EXIT FUNCTION
    END SELECT
    END SELECT

    END FUNCTION[/code]

    thanks in advance, lionheart
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: qt about powerbasic :)

    I didin't check fully your code because I'm on hurry and didn't try to compile so take my reply as suggestion.
    You seems to have taken code from an old example. Can it be?

    Check your PowerBasic help. It is very detailed.
    Anyway, PowerBasic LIBMAIN function is described at http://www.powerbasic.com/support/he...N_function.htm

    In your code there are also other problems like:
    [code=thinbasic]LIBMAIN = 1[/code]
    is not a PB code. To return a parameter function you have to to use
    [code=thinbasic]FUNCTION = ...[/code]
    and not the name of the function.

    [code=thinbasic]...
    DEFAULT AS ASCIIZ PTR) EXPORT AS INTEGER[/code]
    Is wrong. PTR parameters are always passed BYVAL so change to something
    [code=thinbasic]...
    BYVAL DEFAULT AS ASCIIZ PTR) EXPORT AS INTEGER[/code]
    The same for all other parameters PTR passed. All PTR must be declared as BYVAL ...
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    52
    Posts
    944
    Rep Power
    111

    Re: qt about powerbasic :)

    hello eros,

    the code I have pushed here is directly way from powerbasic.com website:

    http://www.powerbasic.com/support/downloads/demos.htm

    title: modal-dialog.

    so they have done something wrong with this example, isn't it ?
    I have tried it three, four times, you can imagine I have tested this modal-dialog closer.

    lionheart
    Attached Images Attached Images
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: qt about powerbasic :)

    Hi Frank,

    the example you downloaded is from 1996, so ... old
    The declaration of WinMain/LibMain is more accurate now, there are some more oddities as well.

    I could post corrected version, but I have more valuable information for you.
    If you want high quality examples, 100% working with latest release of compilers, neatly divided to categories, please visit José Roca forum.

    There are masters of Win32 coding, there is the latest technology use.

    I have nothing against examples on PB website archive, it has been useful resource for me for ages, but it might be little difficult for PB beginner to fix compatibility problems between old code and PB/WIN 9.

    PB compilers do not differ that much, but it is understandable 13 years old code is not directly usable with latest release.

    The examples on PB forum are usually also very good, just watch out for the date of the post.
    Once you become more experienced, you can come back to PB archive of samples and manage to translate it yourself without problem - Dave Navarro, Borje Hagsten and other PB heroes had always interesting examples to show.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: qt about powerbasic :)

    Petr is 100% right.

    It is not matter of right or wrong but syntactically correct for the compiler you are using now.
    PowerBasic back compatibility has been always very very good but in so big window time things change.

    In this case what changed is the way PTR (pointers) are passed as parameters.
    With current PowerBasic pointers are ALWAYS passed BYVAL so when you see something like the following in sub/function parameters:
    [code=thinbasic]AnyVar AS <whatevertype> PTR[/code]
    change to
    [code=thinbasic]BYVAL AnyVar AS <whatevertype> PTR[/code]

    Default passing parameters type in PowerBasic is BYREF so
    [code=thinbasic]AnyVar AS <whatevertype> PTR[/code]
    is in reality confusing because it seems you are passing a pointer to a pointer while
    [code=thinbasic]BYVAL AnyVar AS <whatevertype> PTR[/code]
    is for sure passing the pointer value.

    In PowerBasic to avoid headache be sure to always use BYVAL in function parameters unless you are conscious of what you want to achieve.
    With BYVAL, compiler will always do internal conversions of numeric parameters. Without explicit BYVAL, BYREF is the default and compiler expects the exact variable type to be passed. See BYVAL/BYREF help in PowerBasic manual.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6

    Re: qt about powerbasic :)


    I have adapted the code. See: http://www.jose.it-berater.org/smffo...c=3270.new#new

    It was so old that it was 16-bit and was using INTEGER instead of LONG and WORD instead of DWORD, plus many other things.

    What has taken me more time was that the call to DialogBoxParam was failing with an error of -1, until I discovered that the variable used to store the instance handle, hCurInstance, had been declared as WORD.

    There are no mistakes in the original code. It will compile if used with the compiler for what it was written, PB/DLL 1!

Similar Threads

  1. What PowerBasic can do
    By ErosOlmi in forum Power Basic
    Replies: 7
    Last Post: 01-05-2009, 04:58

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •