January 16, 2021, 09:46:07 PM

Author Topic: best way to switch from INT to BYTE PTR ?  (Read 238 times)

Offline fielder

  • Full Member
  • ***
  • Posts: 101
best way to switch from INT to BYTE PTR ?
« on: December 31, 2020, 10:33:15 AM »
A lot of (Windows) old code on the web to manage ICONS and WINDOWS and WIN APIS uses INTs

what is the best way to "convert" these INT related lines?

here an example:

Code: [Select]
Function _loadAPI:Int( library$ )
Local api:Int = LoadLibraryA( library$ )
If Not api Then RuntimeError( "Failed to load API '"+library+"'" )
Return api
End Function

compiling fine on on Blitzmax (before NG)
but with a "Unable to convert from Byte Ptr to Int" on NG

other examples of these issues:

Code: [Select]
?win32
Global  icon:Int = LoadIconW(GetModuleHandleW(Null), Short Ptr(101)) ' Use the ordinal number in the resource file
SendMessageW(GetActiveWindow(), WM_SETICON, 1, icon)
?

and also... its.printing (the only printing library for blitzmax?) THROWNING THE SAME ERRORS: https://sourceforge.net/projects/itsprinting/files/?source=navbar


Offline Henri

  • Sr. Member
  • ****
  • Posts: 288
Re: best way to switch from INT to BYTE PTR ?
« Reply #1 on: December 31, 2020, 01:54:09 PM »
Hi,

LoadLibrary returns a Byte Ptr so change the 'api' variable from Int -> Byte Ptr. Also change the return type of your function from Int -> Byte Ptr.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline col

  • Sr. Member
  • ****
  • Posts: 474
Re: best way to switch from INT to BYTE PTR ?
« Reply #2 on: December 31, 2020, 04:49:57 PM »
To compliment the answer above and if you want to write code to support both compilers then you need to think ahead a little. I had issues because vanilla Max doesn't deal with nested conditional compiler constants (not sure if NG does but anyway you will need ?win32 and ?bmxng) . I ended up using a conditional to decide which file to import that would then have the?win32 conditional in it (not sure if NG has nested conditionals).

Such as
Code: [Select]
?bmxng
Import "code_for_ng.bmx"
?not bmxng
Import "code_for_vanilla.bmx"
?

Then drop the code functions specific for each compiler in the respective file.

You don't have to do it that way of course and it's a specific solution to get over nested conditionals - you can just as easy put the correct function definition inside the respective conditional.

Hope it makes sense.
To be is to be perceived.

https://github.com/davecamp

Offline fielder

  • Full Member
  • ***
  • Posts: 101
Re: best way to switch from INT to BYTE PTR ?
« Reply #3 on: December 31, 2020, 06:51:32 PM »
thank you guys!

Offline Derron

  • Hero Member
  • *****
  • Posts: 3331
Re: best way to switch from INT to BYTE PTR ?
« Reply #4 on: January 02, 2021, 08:30:53 AM »
(not sure if NG has nested conditionals).

It hasn't.
Each conditional (also in "includes" I think - so only "imports" help) stops the previous one.

Vanilla threats every "unknown" thing in "?..." as "false".
NG allows to combine stuff:

?(win32 and x64) or linux
print "windows 64bit  or linux"
?macos
print "mac"
?

https://blitzmax.org/docs/en/language/conditional_compiling/

The stuff after the "?" is evaluated, so math etc should be doable too. It just misses some "define" option...
I import vanilla/ng-dependend stuff the same as col.


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal