I have some suggestions.
1) To be as correct as possible, specify the return types in the declarations. For instance, the docs say that InstallWinIoDriver returns a bool variable, so in your .decls file, you should state:
(This will allow you to test the return value.)
2) You should test the return value for these functions. If it's false (fails), don't continue, or recover from the error.
3) A DWORD (doubleword) in C just signifies a two-word segments. A word is 16 bits (2 bytes), therefore a dword is 4 bytes, or to Blitz, the exact same thing as an int%. So anywhere where you see a DWORD, you know in Blitz it's just an int.
4) But if you look at the documentation for GetPortVal, you'll see that the second parameter (pdwPortVal) is a *pointer* to a dword. So in this case, we must declare it as a pointer in the .decls file (use *, not %) and then in the blitz program, we must pass in either (a) a bank, and then use peekbyte to read the data, or (b) a custom type instance. I prefer the latter, simply because it's more readable. Something like this:
'p' represents (to Blitz) a pointer to a block in 4 bytes in memory. But because we declared as part of the GetPortVal function in the .decls file "pdwPortVal*" instead of "pdwPortVal%", Blitz will pass an actual windows pointer of the 4-byte chunk of memory to the DLL. Then we read it simply with the "p\val" syntax.
I hope that makes sense. It kind of gets into more advanced stuff.
PS: Watch out; you've declared SetPortVal to call GetPortVal in the .decls file...
PPS: Use <code> and </code> or <quote> and </quote> (except replace <> with []) to format your special text and retain indentation.
1) To be as correct as possible, specify the return types in the declarations. For instance, the docs say that InstallWinIoDriver returns a bool variable, so in your .decls file, you should state:
InstallWinIoDriver%(WinIoDriverPath$, IsDemandLoaded):"InstallWinIoDriver"...instead of:
InstallWinIoDriver(WinIoDriverPath$, IsDemandLoaded):"InstallWinIoDriver"
(This will allow you to test the return value.)
2) You should test the return value for these functions. If it's false (fails), don't continue, or recover from the error.
3) A DWORD (doubleword) in C just signifies a two-word segments. A word is 16 bits (2 bytes), therefore a dword is 4 bytes, or to Blitz, the exact same thing as an int%. So anywhere where you see a DWORD, you know in Blitz it's just an int.
4) But if you look at the documentation for GetPortVal, you'll see that the second parameter (pdwPortVal) is a *pointer* to a dword. So in this case, we must declare it as a pointer in the .decls file (use *, not %) and then in the blitz program, we must pass in either (a) a bank, and then use peekbyte to read the data, or (b) a custom type instance. I prefer the latter, simply because it's more readable. Something like this:
Type PortVal Field val End Type p.PortVal = New PortVal ;... GetPortVal($379, p, 4) DebugLog p\val
'p' represents (to Blitz) a pointer to a block in 4 bytes in memory. But because we declared as part of the GetPortVal function in the .decls file "pdwPortVal*" instead of "pdwPortVal%", Blitz will pass an actual windows pointer of the 4-byte chunk of memory to the DLL. Then we read it simply with the "p\val" syntax.
I hope that makes sense. It kind of gets into more advanced stuff.
PS: Watch out; you've declared SetPortVal to call GetPortVal in the .decls file...
PPS: Use <code> and </code> or <quote> and </quote> (except replace <> with []) to format your special text and retain indentation.