Gridwars : "Compile Error: Unable to convert from Byte Ptr to Int."

Started by echdareez, September 30, 2019, 13:00:14

Previous topic - Next topic

echdareez

Hi there,

Gridwars is one of my favourite games and I was shocked to realize last weekend that the sources were present all those years in my installdir  ;D
As I was planning on learning to code a 2D game, I thought : why not take this game as an example?
Downloaded BlitzMax_win32_x64_0.105.3.35.7z (78.292.684 bytes), ran MaxIDE, opened gridwars.bmx, verified the compilation options (Win32 on x86 - verbosed debug build) and immediately stumbled upon an error while trying to do a test build :

"Compile Error: Unable to convert from Byte Ptr to Int.  [C:/apps/BlitzMax/GridWars-master/bass.bmx;310;0] "

Had a look around : there's an Import in the gridwars.bmx towards sound.bmx and in here an Import to bass.bmx. The culprit line is :

Local dll:Int = LoadLibraryA("bass.dll")

Also found this article in here :
https://www.syntaxbomb.com/index.php?topic=3233.0
And this didn't get me further (tried -w on the command line, using bmk.exe directly, etc...)

Any pointers for a starting programmer? :-)
tx!
/e

Derron

Dunno if it is the bass-module from Brucey?
https://github.com/maxmods/bah.mod/tree/master/bass.mod


Byte Ptr -> Int
This problem arises from NG no longer accepting such stuff and is a bit more strict. DLLs want "pointers", not integers.


Means here LoadLibraryA("bass.dll") returns a "Byte Ptr" and not a "Int".

Local dll:Byte Ptr = LoadLibraryA("bass.dll")

should correct this line - but I assume there is more stuff to come.


bye
Ron

echdareez

Thanks a lot for your reply Ron!

And yes, it's that one as far as I can see.
Changing the INT to BYTE PTR did indeed get me further, but there's another function blocking the build later on (expecting an INT as a return) - no worries, it's a challenge but worthwile as a case study and a learning process ;-) 

Out of curiosity : also tried an older version (Blitzmax 1.5) : this DID compile is without any errors but the .exe gives an exception_access_violation when launching... Something for later :-)   Now for some "real work" and some Powershell coding - something I *do* have the knowledge for :-D

/e

Derron

that 1.5 blitzmax is BlitzMax 1.50 - and we call it "legacy" for a reason. It is no longer supported, only able to compile for 32 bit and the target platforms are also more limited.

With BlitzMax NG you gain 64 Bit compatibility, more platforms, updates, fixes ... but it comes with a price: it behaves more correct ("strict"). With 64 Bit in mind you seem to be no longer able to pass a Byte Pointer as Integer anymore.

So old code which did "advanced stuff" (handling DLLs, mangling memory...) needs to get adjusted here and there. Non-Strict code might now throw errors.
But all of them are no "logic changes" but language-ones. Means once you fixed the thrown errors the game should run as planned.


Feel free to post other issues you have with the code - maybe we can fix it together.

bye
Ron

_PJ_

I have a similar issue concerning an Extern call which I am hoping to convert for 64-bit

The "original" (written by another) is here:


Extern "Win32"

Function GetEnvironmentVariable:Int(lpName:Int, lpBuffer:Int, nSize:Int) = "GetEnvironmentVariableA@12"

End Extern


Function GetEnv$(envVar$)


Local buff:Byte[256]

Local rtnLen:Int= GetEnvironmentVariable(envVar$, buff, buff.length)


If rtnLen > (buff.length - 1)


buff = buff[..rtnLen]

rtnLen = GetEnvironmentVariable(envVar$, buff, buff.length)


EndIf

Return String.FromBytes(buff, rtnLen)

End Function


Changing "Int" to "Byte Ptr" is insufficient - also, if I am compiling for 64-bit target, should "Win32" be "wow64" or something?

_________________
_________________


The purpose of using the above is just to return the current user's %APPDATA% directory from the EnvVar. I no longer have working code to access the registry for the userfolder paths, so this appears to be the best option. If anyone has alternative solutions for obtaining these folders (i.e. for saving of game configurations etc.) please let me know.
_________________
_________________

semi-related::
The following seems to fail in NG for Windows 64-bit target it worked fine in 1.50
Quote
(QueryGadget(HWND_MAIN,QUERY_HWND)
Where HWND_MAIN is a valid Window obejct's TGadget handle

Derron

Checkout the module brl.volumes ...so retrieve the app data path.



Win32... This is a calling convention and decides wether it uses cdecl or stdcall. Depends on how the DLL is written and compiled.


Bye
Ron

Hardcoal

I had this problem yesterday. i change byte ptr into Int and it worked..

Sorry i didnt read all the thread incase ive missed something .. just a quick reply
Code