Compiling errors #2

New to FreeBASIC? Post your questions here.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Compiling errors #2

Post by MrSwiss »

Josep Roca wrote:It is a void pointer. 4 bytes in 32 bit and 8 bytes in 64 bit.
No way!

By your own excerpt of windef.bi (which I double checked) --> Long Ptr (even in FBC 64)
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

caseih wrote:so you should never rely on knowing the contents of it.
I did not respond to that.

I have mentioned a couple of times in these pages that I have noticed the bi files, when using Windows APIs, stick to the MSDN data types like glue so I stick to to the bi data types like glue. Obviously, I have to ensure that the appropriate bi are included to get a successful compilation but I do not have to 'tunnel down' to see how the various data types are defined, I just let the compiler get on with it. I have noticed that many folk do not do that but I think that is a risky practice. They may have been using a particular data type for years without issue but I still think it a risky practice, nonethe less.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

No matter how you define it, it is an opaque value returned by some API functions and passed to other API functions. If it was not for type checking, you could use any data type of the appropriate size. Anyway, only Windows knows what to do with these handles.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

It is a bit of a nightmare.

Code: Select all

NTSTATUS WINAPI BCryptOpenAlgorithmProvider(
  _Out_ BCRYPT_ALG_HANDLE *phAlgorithm,
 
NTSTATUS WINAPI BCryptImportKeyPair(
  _In_    BCRYPT_ALG_HANDLE hAlgorithm,
The top API uses *phAlgorithm and the bottom uses hAlgorithm and pass BYVAL in FreeBASIC.

With PowerBASIC I would use hAlgorithm with both and pass BYREF.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Compiling errors #2

Post by MrSwiss »

José Roca wrote:If it was not for type checking, you could use any data type of the appropriate size.
Yes, and the difference is:
Any Ptr --> the size (it points to) is unknown (can be any size).
however:
Long Ptr (pointing to) --> defined size of 32-bit's (4 byte's), always (or a multiple thereof).
DeltaRho[...] wrote: It is a bit of a nightmare.

NTSTATUS WINAPI BCryptOpenAlgorithmProvider(
_Out_ BCRYPT_ALG_HANDLE *phAlgorithm, <---- dereferenced Ptr (to hAlgorithm)

NTSTATUS WINAPI BCryptImportKeyPair(
_In_ BCRYPT_ALG_HANDLE hAlgorithm, <---- the variable itself
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

@MrSwiss

I know - that is the point I was making - inconsistency.

I have tried to make life easier by using BYREF but the compiler put a contract out on me.<smile>
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: Compiling errors #2

Post by Juergen Kuehlwein »

If it was not for type checking, you could use any data type of the appropriate size
Well, this is the point! I know what i want to do and i know how to do it right, but the compiler won´t let me do it because of type checking.

If you look at it from an assembler point of view, all what matters is the size of arguments. The size must be correct, the type is immaterial - if you know what you do. Type checking adds a layer of "security" (and complexity) to your code, so that you can pass only expected (= correct) types of data, but sometimes in can be a real PITA.

Often there is more than one way of declaring an API and each way it works. But you cannot (as it seems) have the same API declared in different ways side by side, you must stick to the declares supplied with the includes.


deltarho[1859]

Indeed dynamic linking solves (circumvents) the problem, because i can declare it as i want to without getting into conflicts with previous static declares of the same API. While this works i would prefer to have a method of "overloading" API functions with different declares, or to be able to define different functions with different declares for the same API just like in PowerBASIC. At least the latter doesn´t seem to work in FreeBASIC (as i have learnt), because the compiler rejects different declares "pointing" to the same API.



Thanks


JK
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

Juergen Kuehlwein wrote:but sometimes in can be a real PITA.
Welcome to the world of FreeBASIC, Juergen. Many of FreeBASIC keywords do things which I would be hard pressed to emulate in PowerBASIC but, as I have said on many occasions on the short time that I have been here, sometimes we are made to jump through too many hoops. I liken it to tinkering with an engine but sometimes with FreeBASIC I seem to spend an inordinate amount of time trying to lift the bonnet up. <laugh>
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Compiling errors #2

Post by MrSwiss »

@deltarho[],

if you find the Win-API to be inconsistent, then:
plse. blame Bill Gates, or M$ but, don't blame FreeBASIC for such shortcomings!
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

Nobody is talking of inconsistencies in the Windows API, but about that FreeBasic doesn't support different declares for the same API procedure.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

@MrSwiss

Sometimes your logic leaves me dumbfounded. At what point did I blame FreeBASIC for shortcomings at MSDN?

Juergen Kuehlwein is a brilliant programmer and what I may regard as a steep learning curve Juergen doesn't even stand out of the saddle. It was very refreshing to see him use the term PITA.

There are some members at PowerBASIC who think their compiler is a gift from God and no other BASIC compiler comes close. Far be it from me to question their faith. No doubt there are members at FreeBASIC who think their compiler is a gift from God as well. Far be it from me to question their faith either. As for me I am bereft of any kind of faith and so am able to witness the shortcomings of both compilers; and they both have them because neither of them is a gift from God.

Both are excellent BASIC compilers but I must say that FreeBASIC is the more frustrating.

As for which I reckon is the better, the jury is out on that one and, I suspect, it always will be because, it seems to me, that although there are different aspects on both sides the scales, for me at the moment, seem to balance. I may change my mind in a year or two - but i doubt it.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Compiling errors #2

Post by MrSwiss »

> Nobody is talking of inconsistencies in the Windows API
Wrong, deltarho[] did, see a few posts back!

> about that FreeBasic doesn't support different declares for the same API procedure.
A good thing imho, one correct declare, does the job. (Better, than two halfway correct ones.)
deltarho[] wrote:Sometimes your logic leaves me dumbfounded.
Well, so does your apparently short lived memory.
Remembering what you've written, a few posts earlier.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

> A good thing imho, one correct declare, does the job. (Better, than two halfway correct ones.)

But not better than two correct declares. There is not such a thing as a unique correct declaration in all cases.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

MrSwiss wrote:Well, so does your apparently short lived memory.
When you get to my age it comes with the territory.
Remembering what you've written, a few posts earlier.
I can't even remember what I wrote in the last post, let alone a few posts earlier.
A good thing imho, one correct declare, does the job.
Which reminds me.

Can you make a correct declare of BCryptHash (Windows 10)? I mentioned it earlier when responding to a post by caseih. Oh my, my memory is coming back - it does that sometimes.<smile>
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

Yes, and the difference is:
Any Ptr --> the size (it points to) is unknown (can be any size).
however:
Long Ptr (pointing to) --> defined size of 32-bit's (4 byte's), always (or a multiple thereof).
So what. It is irrelevant to use a handle.
Post Reply