Try to use inpout32.dll

For issues with communication ports, protocols, etc.
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Postby calatorius » Oct 06, 2020 9:20

Try again
if I use this pi file:

Code: Select all

#ifndef __FB_64BIT__
  extern "Windows-MS" lib "inpout32"
#else
  extern "Windows-MS" lib "inpoutx64"
#endif
  declare sub Out32(port as ushort, value as ushort)
  declare function Inp32(port as ushort) as ushort
end extern


and this basic code:

Code: Select all

#include "inpout32.bi"


#inclib "inpoutx64"

? "Hola mundo"
sleep


All is ok, compile perfect

if i use this bas:

Code: Select all

#include "inpout32.bi"


#inclib "inpoutx64"

? Inp32()
sleep


Result:
D:\basic\FreeBASIC-1.07.1-win64\prueba.bas(6) error 1: Argument count mismatch, found ')' in '? Inp32()'

and if I use this bas:

Code: Select all

#include "inpout32.bi"


#inclib "inpoutx64"

? Inp32(&h61)
sleep


then:
D:\basic\FreeBASIC-1.07.1-win64\prueba.o:fake:(.text+0x36): undefined reference to `Inp32'

Somebody could deduce which is the problem, it seems like the problem is in the argument pass in the function on?
jj2007
Posts: 1688
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Try to use inpout32.dll

Postby jj2007 » Oct 06, 2020 9:24

? Inp32() obviously expects an argument. Why do you insist to use a "static" library? What I posted above works fine.
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Postby calatorius » Oct 06, 2020 9:42

Because I tried too with your code in 32 and 64 bits

Code: Select all

#inclib "InpOut32"
Declare Sub Out32 Alias "Out32" (data As short, port As short)
Dim As short MyData=1, MyPort=2
Out32(MyData, MyPort)
Print "all is fine"
sleep


result:
D:\basic\FreeBASIC>fbc prueba.bas
prueba.o:fake:(.text+0x39): undefined reference to `Out32@8'

Code: Select all

#inclib "InpOutx64"
Declare Sub Out32 Alias "Out32" (data As short, port As short)
Dim As short MyData=1, MyPort=2
Out32(MyData, MyPort)
Print "all is fine"
sleep


Result:
Compiler output:
D:\basic\FreeBASIC-1.07.1-win64\prueba.o:fake:(.text+0x47): undefined reference to `Out32'
Xusinboy Bekchanov
Posts: 254
Joined: Jul 26, 2018 18:28

Re: Try to use inpout32.dll

Postby Xusinboy Bekchanov » Oct 06, 2020 10:28

calatorius wrote:Because I tried too with your code in 32 and 64 bits

Code: Select all

#inclib "InpOut32"
Declare Sub Out32 Alias "Out32" (data As short, port As short)
Dim As short MyData=1, MyPort=2
Out32(MyData, MyPort)
Print "all is fine"
sleep


result:
D:\basic\FreeBASIC>fbc prueba.bas
prueba.o:fake:(.text+0x39): undefined reference to `Out32@8'

Code: Select all

#inclib "InpOutx64"
Declare Sub Out32 Alias "Out32" (data As short, port As short)
Dim As short MyData=1, MyPort=2
Out32(MyData, MyPort)
Print "all is fine"
sleep


Result:
Compiler output:
D:\basic\FreeBASIC-1.07.1-win64\prueba.o:fake:(.text+0x47): undefined reference to `Out32'

Have you tried it:

Code: Select all

Declare Sub Out32 Lib "InpOut32" (data As short, port As short)
dodicat
Posts: 6687
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Try to use inpout32.dll

Postby dodicat » Oct 06, 2020 10:41

This is OK with 32 bit fbc, -gen gcc or -gen gas.
Note, gcc 5.2.0 with fbide.
If I use option -exx I get error 10 ("illegal instruction" signal) fault, but no problems calling the function.

Code: Select all

#inclib "InpOut32"
Declare Sub Out32 cdecl Alias "Out32" (data_ As short, port As short)

Dim As short MyData=1, MyPort=2

Out32(MyData, MyPort)
Print "all is fine"
sleep

I had to use cdecl to avoid a warning.
I didn't have to make an import library, but here is my .def file anyway

Code: Select all

;
; Definition file of inpout32.dll
; Automatic generated by gendef
; written by Kai Tietz 2008
;
LIBRARY "inpout32.dll"
EXPORTS
Out32@8
Inp32@4
 

I keep the .dll file in the same folder as the test.bas file (as paul doe mentioned earlier)
There is no point in putting a .dll into any of your system folders unless you really really like it and want to use it.
You will probably have to make an import library (InpOut32.dll.a) with dlltool.exe and the .def file for this if you want to do this, and put the .a file into your freebasic lib folder along with all the other .a files.
jj2007
Posts: 1688
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Try to use inpout32.dll

Postby jj2007 » Oct 06, 2020 10:51

calatorius wrote:Because I tried too with your code in 32 and 64 bits

Code: Select all

#inclib "InpOut32"
Declare Sub Out32 Alias "Out32" (data As short, port As short)
Dim As short MyData=1, MyPort=2
Out32(MyData, MyPort)
Print "all is fine"
sleep
Strange. That snippet works fine for me with both GAS and Gcc32.

dodicat wrote:I had to use cdecl to avoid a warning
That does indeed suppress some warnings but I am astonished that it works. Under the hood this is clearly a stdcall function.
marcov
Posts: 3010
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Try to use inpout32.dll

Postby marcov » Oct 06, 2020 11:27

Maybe the importlib stub changes calling convention?
dodicat
Posts: 6687
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Try to use inpout32.dll

Postby dodicat » Oct 06, 2020 12:04

Here is a relevant page
http://www.highrez.co.uk/downloads/inpout32/
Probably just as well I got an illegal instruction call, I really don't need any drivers installed here on Win 10.
That was a close shave!
I am usually careful running unknown dll's.
jj2007
Posts: 1688
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Try to use inpout32.dll

Postby jj2007 » Oct 06, 2020 12:08

marcov wrote:Maybe the importlib stub changes calling convention?
It certainly won't poke a retn (or retn 8) inside the DLL. There is a retn 8 at the end of out32, so it's stdcall.
dodicat
Posts: 6687
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Try to use inpout32.dll

Postby dodicat » Oct 06, 2020 12:16

The sample C++ code in the link uses stdcall, but stdcall gives a warning here.

extern "c"
bla bla
end extern
is OK also.
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Postby calatorius » Oct 06, 2020 12:41

EUREKA!

I got it, it's incredible but the only thing to run was to have the .def file create with pexports in inpoutx64.dll.
with this code:

Code: Select all

#inclib "InpOutx64"
Declare Sub Out32 Alias "Out32" (port As short, data As short)
Declare Function Inp32 Alias "Inp32" (port as short) as short
Dim As short MyData=2, MyPort=&h61
print inp32(&H3da)
Print "all is fine"
sleep


And the dll with its .def in the same directory compile and run fine.
The fact is that I don't know why inclib needs a def file :|
dodicat
Posts: 6687
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Try to use inpout32.dll

Postby dodicat » Oct 06, 2020 13:17

Glad you got it working.
FreeBASIC has inbuilt inp and out, so you wouldn't be stuck.
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Postby calatorius » Oct 06, 2020 13:26

yes
but inbuild inp and out don´t work because are protected instructions in windows.
It´s necesary to use external libraries to do it.
Thanks very much to everyone for your help
MrSwiss
Posts: 3599
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Try to use inpout32.dll

Postby MrSwiss » Oct 06, 2020 14:03

calatorius wrote:It´s necesary to use external libraries to do it.
Well, that isn't exactly correct as stated.

The driver (elevated privileges in OS) that the ext. lib. uses 'does the trick' in this context.

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest