Author Topic: Basic UDTs..., ?  (Read 6784 times)

Steve A.

  • Guest
Basic UDTs..., ?
« on: October 23, 2010, 06:51:20 AM »
Hey guys,
I'm at a point in Bxbasic where I want to add some "Windows" functionality.
A concern I have is that, unlike a console mode app, where simple variables can store just about all parameters required for program operation, Windows functions tend to require a lot of "structures".
Now, I know how to build and use structures in C, not a problem.

The problem I'm encountering is that there just seems to be too many windows structures to create them all, on the chance that I may need to use one of them at some future point.

In interpreted Basic, structures are often referred to as UDTs (user defined types), but, they are the same thing as structures.
What I need to do is implement a UDT mechanism in Bxbasic for creating windows structures.

Here are just a few examples of what I mean:


    OSVERSIONINFO os;
    os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&os);


    WNDCLASS  wndclass;
        wndclass.style          = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = WndProc;
        wndclass.cbClsExtra     = 0;
        wndclass.cbWndExtra     = 0;
        wndclass.hInstance      = hInstance;*/
        wndclass.hIcon          = LoadIcon(NULL,IDI_APPLICATION);
        wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
        wndclass.lpszMenuName   = NULL;
        wndclass.lpszClassName  = szAppName;


    PAINTSTRUCT   ps;
    hdc = BeginPaint(hwnd, &ps);


    TEXTMETRIC   tm;
    GetTextMetrics(hdc, &tm);
    cxChar = tm.tmAveCharWidth;
    cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
    cyChar = tm.tmHeight + tm.tmExternalLeading;


    PIXELFORMATDESCRIPTOR pfd;
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.iLayerType = PFD_MAIN_PLANE;
    pfd.cDepthBits = 16;


Each of the above (in CAPS is a structure declaration and below it is an example of its usage.
Has anyone encountered this before and come up with a mechanism for building UDTs ?
I suspect it's not too different from creating arrays. You probably just have to build some sort of parser to keep track of each element and it's data type.
Any ideas or thoughts on this ?

Steve A.

JRS

  • Guest
Re: Basic UDTs..., ?
« Reply #1 on: October 23, 2010, 11:07:13 AM »
Quote
Any ideas or thoughts on this ?

I would look at a cross platform GUI toolkit. (IUP, Gtk, Qt, ...) Using the Windows GUI API seals your fate.

SB uses linked lists under the covers for it's dynamic array support.

I use associative arrays for UDT's like structures in SB.


E.K.Virtanen

  • Guest
Re: Basic UDTs..., ?
« Reply #2 on: October 24, 2010, 08:00:46 AM »
Steve, i think that if you ever want to make bxbasic as multiplatform, you should now concencrate for something else than win api.
Im not good in these things due i love good ol' ASCII stuff, but what i have heard, Gtk would be your best shot in here.

Steve A.

  • Guest
Re: Basic UDTs..., ?
« Reply #3 on: October 24, 2010, 11:36:26 AM »
Hey guys,
thanks for your input.

I guess I really mis-spoke when I used windows as an example.

@JRS
Quote
I would look at a cross platform GUI toolkit. (IUP, Gtk, Qt, ...) Using the Windows GUI API seals your fate.

Yes, no doubt.


@EKV
Quote
Steve, i think that if you ever want to make bxbasic as multiplatform, you should now concencrate for something else than win api.

I said "Windows functionality" and used windows examples, when I really meant "GUI functionality".
Poor choice on my part.


@Aurel
Quote
If i will made crossplatform i will siriusly look into wxWigets.

I'm not real happy with wxWidgets.
1) it requires a C++ compiler, (which I do have, but I prefer plain C),
2) it requires that you build the wxWidgets on your system,
3) I went out and bought the wxWidgets Book on Amazon and downloaded several recent releases of wxWidgets,
4) exchanged numerous emails with support forum, but, could never get wxWidgets to build without errors.

Just give me the damn code ! 
Don't make me build anything.
So there.

At this point, I'm not sure if wxWidgets uses DLLs or gives you linkable libraries.
I prefer not to use any DLLs for the GUI interface.
That's one reason I opted not to use Allegro, huge DLLs.

Still...,
on a windows system, I shouldn't prevent the end-user from using Win-API simply because I they can't construct UDTs (structure), since almost all Win32 system call want a structure address passed as a parameter. The API then fills in the structure elements with the required data.

That's what I need to figure out.

Steve

Pjot

  • Guest
Re: Basic UDTs..., ?
« Reply #4 on: October 24, 2010, 11:37:59 AM »
Why not use GTK? It is multiplatform also. The problem with wxWidgets or QT or FLTK is that they are implemented in C++. Therefore an interpreted program never can dynamically import their functions. More details on this issue is explained here.

Of course it can be decided to implement graphical functions hardcoded but this also will introduce a permanent dependency to those libraries. Then the user must install these external graphical libraries before he is able to run the interpreter.

jcfuller

  • Guest
Re: Basic UDTs..., ?
« Reply #5 on: October 24, 2010, 11:51:24 AM »
Steve,
  I've been experimenting with wxWidgets and Bcx. I hear where you're coming from re: libraries.
I first built a static 32bit ansi/debug which I still use for one or two application builds but for all else I decided to go with wxPack:  http://wxpack.sourceforge.net/
Still not too sure what is needed for just deployment though. I also like the fact it uses native widgets.
The wxWidget library has MUCH more than just a GUI.
I have Bcx code using wxWidgets that will compile on Linux or Windows.

James

JRS

  • Guest
Re: Basic UDTs..., ?
« Reply #6 on: October 24, 2010, 11:56:15 AM »
Quote
Why not use GTK? It is multiplatform also.

Peter developed Gtk-Server which I use with SB via an extension module interface. (one function DLL/SO) Gtk-Server also suppports TCP/UDP/FIFO interfaces as well. It's a great GUI tool set for interpreters if you want to get a GUI running in your lifetime.  :D


Steve A.

  • Guest
Re: Basic UDTs..., ?
« Reply #7 on: October 24, 2010, 01:10:07 PM »
@Pjot
Quote
Why not use GTK? It is multiplatform also.

I'll have to take a look at it.

@jcfuller
Quote
The wxWidget library has MUCH more than just a GUI.


Oh, I know.
That's why I originally became interested in it and bought the book.


@JRS
Quote
Peter developed Gtk-Server which I use with SB via an extension module interface.

I only recently became aware of GTK-Server. I have to take a close look at it.

Steve



JRS

  • Guest
Re: Basic UDTs..., ?
« Reply #8 on: October 24, 2010, 02:49:49 PM »
Steve solved his dynamic DLL calling with his new DynaCall addition to his interpreter. He is now working on adding a cross platform GUI.


Steve A.

  • Guest
Re: Basic UDTs..., ?
« Reply #9 on: October 24, 2010, 03:59:04 PM »
Quote
The problem with wxWidgets or QT or FLTK is that they are implemented in C++.
Therefore an interpreted program never can dynamically import their functions.

Hey Aurel,
I think what Pjot means here (please correct me if I'm wrong), is that because those tool are written in C++, that they present a problem for my situation.
I've heard that there is a work-around for making wxWidgets to compile using plain C, but I don't know what that is.

My hope is to be able to statically link anything I use directly into Bxbasic.
I would rather compile and link any libraries for the core GUI functions rather than add DLL's, if possible.

Steve

Steve A.

  • Guest
Re: Basic UDTs..., ?
« Reply #10 on: October 24, 2010, 04:18:37 PM »
Peter,
I was looking over the info and docs you have at GTK-server and also the stuff at GTK.
Could you maybe fill in a few details I may have missed:

How does GTK-server work ?
What I mean is... linkable libraries or DLLs ?

I looked at some of the example scripts, like VB, Yabasic, ScriptBasic.
Are they calling an executable with parameters or accessing a DLL ?
I'm not sure what's happening there.

I noted that you require one of the dynamic loaders to be installed, (that we discussed previously), so that sort of implies DLLs.

What's the minimum files I need to get started using GTK-server ?

Here's what I downloaded:
gtk-server-2.3.1-installer.exe
gtk2-runtime-2.22.0-2010-10-21.ash.exe
glade-3.4.3-win32-1.zip
libglade-2.6.3.zip

Any light you can shed would be greatly apprciated,
Steve

JRS

  • Guest
Re: Basic UDTs..., ?
« Reply #11 on: October 24, 2010, 06:49:54 PM »
I'm sure Peter can be much more of a help on this subject but in general GTK-Server is a string (PTR) ASCIIZ passing interface if you use the DLL. If you open a socket, you can send/receive commands to/from the server to create a GUI framework and process events from the GUI GTK-Sever creates for you. GTK-Server is very popular with scripting and interpretive languages even though I have used it with compilers.

Peter even created a HUG high level GUI function library that makes it even easier to use GTK-Server. I could go on but Peter would be a better person to help you with your interface questions.

« Last Edit: October 24, 2010, 06:51:39 PM by JRS »

AIR

  • Guest
Re: Basic UDTs..., ?
« Reply #12 on: October 24, 2010, 10:56:54 PM »
Well, if you're gonna go third party/cross platform for GUI, IUP is an option.

Through it you get native widget support on Windows and *nix (via Gtk).

I did a proof-of-concept module for Scriptbasic with it, so it can be "plugged in" to a scripting language (Lua uses it too).

Just a thought...

A.

Pjot

  • Guest
Re: Basic UDTs..., ?
« Reply #13 on: October 25, 2010, 04:29:45 AM »
Quote
How does GTK-server work ? What I mean is... linkable libraries or DLLs ?

The GTK-server can be compiled as binary or as shared object/DLL. In the first case, the client program needs to execute it while specifying which communication interface is being used (STDIN/Pipe/TCP/UDP/IPC). In the latter the client has to import the 'gtk' function from the DLL dynamically.

In all cases the client program just sends the GTK functions in S-expression format towards the GTK-server, as John mentions. Then the GTK-server takes care of looking up the call in the GTK libraries, passing back the results to the client program. So in a sense it is a proxy for interpreted languages which cannot import calls from DLL's dynamically by themselves.

However as your Basic already has some sort of implementation for dynamic calls, using the GTK-server may be a little overkill here.

Quote
What's the minimum files I need to get started using GTK-server ?

For Unix/Linux all files required already will be in your system. For Windows you probably only need to install a GTK+environment.

Glade is only needed when your client program actually wants to use Glade calls.

Regards
Peter
« Last Edit: October 25, 2010, 04:31:43 AM by Pjot »

JRS

  • Guest
Re: Basic UDTs..., ?
« Reply #14 on: October 25, 2010, 08:55:44 AM »
Quote from: AIR
I did a proof-of-concept module for Scriptbasic with it, so it can be "plugged in" to a scripting language.

The concept is great and you proved it works. Is that it or will ScriptBasic see the fruits of your labor someday with the IUP extension module? If not, can you at least release the source so I or someone else doesn't have to start over?

« Last Edit: October 25, 2010, 11:48:55 AM by JRS »