error: stray '@' in program

BlitzMax Forums/Brucey's Modules/error: stray '@' in program

Grey Alien(Posted 2016) [#1]
Hi all, I finally started using NG! First I want to get my games working in Windows, then I'll try Linux, and then maybe IOS.

Anyway, I've fixed loads of compile errors so far but now I'm getting this error:
error: stray '@' in program
 extern BBINT __stdcall  GetEnvironmentVariableA@12(BBBYTE * bbt_lpName,BBBYTE* bbt_lpBuffer,BBINT bbt_nSize);


Due to this (and I have more similar declarations elsewhere):
?win32
Extern "win32"
	Global _bbusew:Int 'Defined in 'blitz.mod\blitz_app.c'.

	Function CloseLibrary(hLib:Byte Ptr) = "FreeLibrary@4"
	Function GetEnvironmentVariable:Int(lpName$z, lpBuffer:Byte Ptr, nSize%) = "GetEnvironmentVariableA@12"
	Function GetVersionExA(infoex:Byte Ptr)
	Function RegOpenKey%(hKeyParent%,SubKey$z,phkResult:Byte Ptr)="RegOpenKeyA@12"
	Function RegCloseKey%(hKey%)="RegCloseKey@4"
	Function RegQueryValueEx%(hKey%,ValueName$z,Reserved%,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)="RegQueryValueExA@24"
End Extern


Alas I'm a complete NG noob and have no idea how to sort that. I have scoured these threads and read something about an .x file (was a fan in the 1990s). If that's the solution can anyone explain in a simple way for me, or point me to a resource? Thanks!

There may be more questions soon...


Grey Alien(Posted 2016) [#2]
Update: OK so I commented out the bits like
= "GetEnvironmentVariableA@12"

and just changed then name of the function to be the one I want like:
Function GetEnvironmentVariableA


But now of course I get these errrors for everything:
D:/BlitzMaxNG/Jake/Regency Solitaire/source/.bmx/RegencySolitaire.bmx.gui.release.win32.x86.h:5222:25: error: conflicting types for 'GetEnvironmentVariableA'
 extern BBINT __stdcall  GetEnvironmentVariableA(BBBYTE * bbt_lpName,BBBYTE* bbt_lpBuffer,BBINT bbt_nSize);
                         ^
In file included from D:/BlitzMaxNG/MinGW32/x86_64-w64-mingw32/include/winbase.h:28:0,
                 from D:/BlitzMaxNG/MinGW32/x86_64-w64-mingw32/include/windows.h:70,
                 from D:/BlitzMaxNG/mod/brl.mod/blitz.mod/blitz_thread.h:7,
                 from D:/BlitzMaxNG/mod/brl.mod/blitz.mod/blitz.h:28,
                 from D:/BlitzMaxNG/mod/brl.mod/blitz.mod/.bmx/blitz.bmx.release.win32.x86.h:4,
                 from D:/BlitzMaxNG/Jake/Regency Solitaire/source/.bmx/RegencySolitaire.bmx.gui.release.win32.x86.h:4,
                 from D:/BlitzMaxNG/Jake/Regency Solitaire/source/.bmx/RegencySolitaire.bmx.gui.release.win32.x86.c:1:
D:/BlitzMaxNG/MinGW32/x86_64-w64-mingw32/include/processenv.h:38:27: note: previous declaration of 'GetEnvironmentVariableA' was here
   WINBASEAPI DWORD WINAPI GetEnvironmentVariableA (LPCSTR lpName, LPSTR lpBuffer, DWORD nSize);


This must be where the .x file comes in...


Derron(Posted 2016) [#3]
Yes ...

Similar to your --now done- adjustments, Brucey got rid of that "stray" part it this way:
https://github.com/maxmods/bah.mod/commit/cccdf234779fa8ce894e098f2bd1f3cbe7511bd5


@ .x-file
If you define an extern function _again_, you need to state that in an .x-file containing the function definition.

A sample is:
https://github.com/maxmods/bah.mod/blob/master/volumes.mod/vol_win.x



Sorry that I am not of more help, but that .x-file thingy was always something I left open for Brucey (leading in a fixed maxmod2-module for NG).


bye
Ron


Grey Alien(Posted 2016) [#4]
Thanks Derron! OK I think that makes sense. So I just make a .x file with the same name as my .bmx file with those externs in and put it in the same folder? Will give it a go.

When you say "_again_", what do you mean? Is there a smarter way I should do this in the .bmx than using a .x file?


Derron(Posted 2016) [#5]
@ _again_

If you import a module already defining that (external) function, you wont need to define it "_again_".


Have a look at this thread - and focus on this post/reply by Brucey.


bye
Ron


Derron(Posted 2016) [#6]
crap forum .. "double post because of post edit".


Grey Alien(Posted 2016) [#7]
OK great thx. Will read and attempt to understand.


Brucey(Posted 2016) [#8]
If it wasn't too much work, you may wish to consider bah.registry, which is an NG-friendly Windows Registry module.

You can use it like so:

Local key:TRegistryKey = RegOpenKey(HKEY_CURRENT_USER, "Software\TestDir")

If Not key Then
	Print "Creating registry entry..."
	
	key = RegCreateKey(HKEY_CURRENT_USER, "Software\TestDir")
	
	If Not key Then
		Print "Failed to create entry."
		End
	End If
Else
	Print "Registry key exists."
End If

Print "Setting values"
key.SetString("name", "BlitzMax")
key.SetString("style", "Kind of blue")
key.SetInt("num1", 69)
key.SetLong("num2", 9876547382:Long)

Print "Values..."
For Local value:TRegistryValue = EachIn key.values()
	Print "  Value : " + value.name + " : " + value.ToString()
Next


But obviously, it's hiding the real APIs behind a BlitzMax facade... so it wouldn't be a straight drop-in.


Brucey(Posted 2016) [#9]
re, adding .x file entries.

You can basically use the line indicated in the error :
WINBASEAPI DWORD WINAPI GetEnvironmentVariableA (LPCSTR lpName, LPSTR lpBuffer, DWORD nSize);

and tweak it to fit. You don't include argument names, or the "API" macros, and swap the semi-colon for an exclamation (!) :
DWORD GetEnvironmentVariableA (LPCSTR, LPSTR , DWORD )!

The filename must match that which has the Extern Function line, so if your file was myfile.bmx, you'd create a file called myfile.x


Grey Alien(Posted 2016) [#10]
Great thanks for the pointers. It's handy the error has the details I need :-)