Author Topic: theForger's Tutorials revised  (Read 11701 times)

0 Members and 2 Guests are viewing this topic.

Arnold

  • Guest
theForger's Tutorials revised
« on: March 21, 2018, 02:27:32 AM »
Hello,

when I started to learn about OxygenBasic, one of my first projects was to explore theForger's Win32 API Programming Tutorial:

http://www.winprog.org/tutorial/

By reading the tutorials and porting the examples to Oxygen I not only learned about C (although I probably will never be able to code correctly in this language), but also about the Win32 Api and about using Oxygenbasic. Although I tried to use a more C-like syntax, the examples could also be coded e.g. in a more Freebasic-like style to some extent.

Oxygenbasic has evolved very much since my first attempt. By using corewin.inc there was only one function left which I had to define separately. (ZeroMemory, which in fact is not necessary in OxygenBasic).

Maybe there are some people who are interested in exploring the tutorials and the examples. I think they are very instructive and can also be further extended. If the folder of theForger_o2 is stored as a subfolder of e.g. \examples or of projectA\B\C then the accompanying batch files should work as expected. The .o2bas files are coded to create 64-bit executables. But they could also be created as 32-bit exes.

As I am not able to do this, perhaps there is someone else who would like to code at least the first two examples in another Basic like syntax. It would be interesting to see to what extent this is possible in Oxygenbasic.

My next step will be to apply Oxygen's own library functions with some of these examples.

Roland

chrisc

  • Guest
Re: theForger's Tutorials revised
« Reply #1 on: March 21, 2018, 04:22:29 AM »
Thanxx a lot Roland
this is a very good contribution

jack

  • Guest
Re: theForger's Tutorials revised
« Reply #2 on: March 21, 2018, 04:45:05 AM »
thank you Arnold :)

Aurel

  • Guest
Re: theForger's Tutorials revised
« Reply #3 on: March 21, 2018, 10:53:17 AM »
Thanks Arnold

I know for this site but i never look in this example:

App_four .... did you tried compile as 32bit exe ?
Why I ask ?
Maybe you know ..i have lot of trouble to force A043/progress to compile
properly my AurelEdit  .. toolbar & scintilla control problem.
With old release and using awinh with bind all works as it should be but now not.
So i see in this App_four that have toolbar and have this :

Code: [Select]
ZeroMemory(&tbb, SizeOf(tbb) * spanof(tbb))
            tbb[1].iBitmap = STD_FILENEW
            tbb[1].fsState = TBSTATE_ENABLED
            tbb[1].fsStyle = TBSTYLE_BUTTON
            tbb[1].idCommand = ID_FILE_NEW

            tbb[2].iBitmap = STD_FILEOPEN
            tbb[2].fsState = TBSTATE_ENABLED
            tbb[2].fsStyle = TBSTYLE_BUTTON
            tbb[2].idCommand = ID_FILE_OPEN

            tbb[3].iBitmap = STD_FILESAVE
            tbb[3].fsState = TBSTATE_ENABLED
            tbb[3].fsStyle = TBSTYLE_BUTTON
            tbb[3].idCommand = ID_FILE_SAVEAS

            SendMessage(hTool, TB_ADDBUTTONS, spanof(tbb), &tbb)

last LINE  is new for me ...
In old version i use just sizeof() ..not spanof()
maybe there is whole trick how to use this way to sand message to Toolbar control.
So i will study it again ..
thnx

Aurel

Aurel

  • Guest
Re: theForger's Tutorials revised
« Reply #4 on: March 21, 2018, 11:27:14 AM »
This is UDT what is exactly i use before with toolbar control

type TBBUTTON
  int       iBitmap
  int       idCommand
  byte      fsState
  byte      fsStyle
  byte      bReserved[2]
  dword     dwData
  int       iString
end type



Arnol i compile this example app_four.o2bas
and toolbar is properly created...
so i know what I need to do in my own.

IF WE AGREE that we must TEST OxygenbasicProgress... right?

Aurel
« Last Edit: March 21, 2018, 11:46:54 AM by Aurel »

José Roca

  • Guest
Re: theForger's Tutorials revised
« Reply #5 on: March 21, 2018, 11:33:11 AM »
Be warned that that structure definition is only valid for 32 bit.

Aurel

  • Guest
Re: theForger's Tutorials revised
« Reply #6 on: March 21, 2018, 11:44:30 AM »
Hi Jose

Yes I know that ...thanks  :)
my structure different and i am not sure how work with old version.
it is here:

TYPE TBBUTTON
   iBitmap    as long
   idCommand  as long
   fsState    as byte
   fsStyle    as byte
        bReserved[0] as byte
        bReserved[1] as byte
   dwData     as long
    iString     as sys
END TYPE


Jose
You probably mean on second member of
bReserved[1] as byte is needed for 64bit.... is that right?

For example from dlib Structure Viewer is :


Aurel

  • Guest
Re: theForger's Tutorials revised
« Reply #7 on: March 21, 2018, 12:00:47 PM »
Here is how look MDI app

José Roca

  • Guest
Re: theForger's Tutorials revised
« Reply #8 on: March 21, 2018, 12:22:10 PM »
> is that right?

What I mean is that, for 64 bit, bReserved must be 6 bytes, and dwData and iString must be 64 bit pointers, not LONG as you're using in dwData.

José Roca

  • Guest
Re: theForger's Tutorials revised
« Reply #9 on: March 21, 2018, 12:24:16 PM »
Code: [Select]
typedef struct {
  int       iBitmap;
  int       idCommand;
  BYTE      fsState;
  BYTE      fsStyle;
#ifdef _WIN64
  BYTE      bReserved[6];
#else
#if defined(_WIN32)
  BYTE      bReserved[2];
#endif
#endif
  DWORD_PTR dwData;
  INT_PTR   iString;
} TBBUTTON, *PTBBUTTON, *LPTBBUTTON;

See: https://msdn.microsoft.com/es-es/library/windows/desktop/bb760476(v=vs.85).aspx

Mike Lobanovsky

  • Guest
Re: theForger's Tutorials revised
« Reply #10 on: March 21, 2018, 01:15:35 PM »
Aurel,

In OxygenBasic terms, the two bottom-most members should be declared as SYS because both of them are pointers as per MSDN, and pointers are automatically sensitive to system bitness, i.e. 32 bits on x86, and 64 bits, on x64.

Besides, there are certain things that O2 allows you to do with a 32-bit SYS but would silently refuse to do with an ordinary int, long, or DWORD. It may become your constant PITA if you fail to memorize it once and for all to avoid bugs that are difficult to isolate and cure.

José Roca

  • Guest
Re: theForger's Tutorials revised
« Reply #11 on: March 21, 2018, 01:30:31 PM »
Former VBer's use LONG and BYVAL AS STRING (sorry, Long and ByVal As String) a lot. This is because VB had not support for DWORD, pointers and null terminated strings. Together with the use of mixed case in keywords, it is a distinctive mark.
« Last Edit: March 21, 2018, 01:58:11 PM by José Roca »

Aurel

  • Guest
Re: theForger's Tutorials revised
« Reply #12 on: March 21, 2018, 02:14:41 PM »
Quote
It may become your constant PITA if you fail to memorize it once and for all to avoid bugs that are difficult to isolate and cure.

Mike
Can be ,,but is not
because some internal o2 changes ... that is why my programs written in older version not work properly.
I understand very well what is SYS ..it is Long Integer Pointer ...there are so many twisted types...
But here is problem with structures..
In older version such a structures are accepted and now not.And this is not first time.
Long time before you come here we ..me & peter and some others fight with similar stuff..
of course that was o2 just a new born baby with lot of quirks with strings and other suff.
for example:
if sys is a lpInt so logical way should be that he can hold address of any other variable

sys a
string b ="o2"

so if we try
a = @b

that's not work
but this yes :

@a = b

looking little but unlogical but thats the way things work.
I don't want to patronize and i accept that.

Charles explained in your topic;


To keep the rules simple:

Use @ explicitly when passing numeric primitives, their arrays, and procedures byref. Indirection is correctly resolved

Use strptr for all types of string passed byval . This is optional but more efficient.

UDTs and class objects (passed byref) do not require @, but you may do so for clarity.

Use @@ for Virtual objects passed byref

José Roca

  • Guest
Re: theForger's Tutorials revised
« Reply #13 on: March 21, 2018, 03:08:46 PM »
> I understand very well what is SYS ..it is Long Integer Pointer

Really? I thought that it was a sort of place holder to store 32 bit or 64 bit values depending of if you compile the application as 32 or 64 bit. Guess it will be a LONG in 32 bit and a signed QUAD in 64 bit, but not a pointer.

Mike Lobanovsky

  • Guest
Re: theForger's Tutorials revised
« Reply #14 on: March 21, 2018, 03:18:22 PM »
Aurel,

You seem to confuse different and irrelevant topics.

1. DWORD, int, long will stay 32-bit on any platform and will thus misalign your structure declaration on 64 bits if you use such declarations for the fields that are designed by MS (not by you or me or Charles) to store pointers. OTOH Oxygen's SYS will automatically expand to 64 bits on x64 and will keep the structure aligned exactly as MS requires. Get used to writing MS-compliant code to avoid booby traps you otherwise install for yourself throughout your own scripts.

2. There are certain operations that are valid only for SYS but not for other integer types. And this doesn't depend upon how long ago you came to this forum. You success here depends entirely on what your background knowledge was when you first came here, and how quickly you're prepared to learn from the mistakes you make.

3. I do not question Charles' rules and I really need none of your nuzzling. If you don't understand why I'm really putting my questions to Charles, then ask, and I will tell you: I'm evaluating if Charles' recent mods to Oxygen are sufficient to invest my time and effort in writing apps for the O2 environment it obviously needs -- in the style I find most efficient. Otherwise I need really little help in finding my way around floats, integers and pointers in any language.

My response isn't intended as flaming. We had pretty nuff of that in the past. You were curious why your structures are so lopsided -- I answered. Jose presupposes you can read C prototypes but I know you can't. That's why I'm trying to explain where everybody else would just RTFM you.

If you don't want, or aren't prepared, to listen to my explanations -- well, then just keep on pouring your sorrows out into the majestic silence. Good riddance.
« Last Edit: March 21, 2018, 03:31:09 PM by Mike Lobanovsky »