Try to use inpout32.dll

For issues with communication ports, protocols, etc.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Try to use inpout32.dll

Post by jj2007 »

I thought something like this would work, but the linker can't find the dll (it's definitely there):

Code: Select all

#inclib "InpOut32.dll"

Declare Sub Out32 StdCall (data As short, port As short)
Dim As short MyData, MyPort

Out32(MyData, MyPort)
Print "all is fine"
sleep
Ha! Trial and error is the only way to succeed - this compiles and runs fine:

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
It will crash at the out dx, al instruction. Remarkable code btw. I wonder what the other 27kB are good for...

Code: Select all

Out32:
push ebp
mov ebp, esp
push ecx
mov al, [ebp+0C]
mov [ebp-1], al
push dx
mov dx, [ebp+8]
mov al, [ebp-1]
out dx, al       ; <<<<<<---- this is a privileged instruction
pop dx
pop ecx
pop ebp
retn 8

Inp32:
push ebp
mov ebp, esp
push ecx
push dx
mov dx, [ebp+8]
in al, dx       ; <<<<<<---- this is a privileged instruction
mov [ebp-1], al
pop dx
mov al, [ebp-1]
and ax, 00FF
pop ecx
pop ebp
retn 4
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Try to use inpout32.dll

Post by D.J.Peters »

You know dlltool works different for 32 and 64 bit ?

let say you have a dll "name.dll" and you created the "name.def" file.

32-bit: FreeBASIC\bin\win32\dlltool.exe -d name.def -l libname.dll.a

64 bit: FreeBASIC\bin\win64\dlltool.exe -m i386:x86-64 --as-flags --64 -d name.def -l libname.dll.a

By the way I put "gendef.exe" in the FreeBASIC/bin32/64 folder.

gendef.exe creates a .def file from any .dll file

dlltool.exe creates a .dll.a file from any .def file

Joshy
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Post by calatorius »

I tried all again and nothing happens.
I tried with several .dll to and with all happens the same, it creates a zero bytes file.
I create de def file first with gendef and after that I used the 64 bit method of dlltool like the last post and again a zero file created.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Try to use inpout32.dll

Post by paul doe »

calatorius wrote:I tried all again and nothing happens.
I tried with several .dll to and with all happens the same, it creates a zero bytes file.
I create de def file first with gendef and after that I used the 64 bit method of dlltool like the last post and again a zero file created.
Forget about that. You don't need it.

Simply create a folder for your code, and have all the code and the dlls needed there, like this:
Image
Works without fuss (no linker errors)
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Post by calatorius »

I did it but not work
https://imgbox.com/FElcFVe7
Last edited by calatorius on Oct 05, 2020 21:32, edited 3 times in total.
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Post by calatorius »

it said me the same error:
undefined reference to `Inp32'
linking failed: 'D:\basic\WinFBE_Suite\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\bin\win64\ld.exe' terminated with exit code 1
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Try to use inpout32.dll

Post by srvaldez »

you also need to #inclib "InpOut32" for 32-bit or #inclib "inpoutx64" for 64-bit
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Post by calatorius »

nothing , exactly the same problem. with #inclib..
I tried with the two versions, compiling in 32 or 64 bits give me always the same error.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Try to use inpout32.dll

Post by srvaldez »

did you follow paul doe's suggestion above?
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Post by calatorius »

yes, i sent the photo in the post with the folder like he did and in my case didnt work, I cant understand which is the difference.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Try to use inpout32.dll

Post by paul doe »

calatorius wrote:yes, i sent the photo in the post with the folder like he did and in my case didnt work, I cant understand which is the difference.
From what I can tell, the only one is in the backend (I compiled with gcc 5.2, you with 8.4). Try compiling it with gcc 5.2 (the 'official default' for FreeBasic as of 1.07.0), as I suspect there may be a mangling problem here?
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Try to use inpout32.dll

Post by srvaldez »

@calatorius
you need to place the dll in the same place where your inpout.bas is
for 64-bit this works

Code: Select all


#include "windows.bi"
'#include "inpout32.bi"

extern "Windows"

declare sub Out32(byval PortAddress as short, byval data as short)
declare function Inp32(byval PortAddress as short) as short
declare function IsInpOutDriverOpen() as BOOL
declare function IsXP64Bit() as BOOL
declare function DlPortReadPortUchar(byval port as USHORT) as UCHAR
declare sub DlPortWritePortUchar(byval port as USHORT, byval Value as UCHAR)
declare function DlPortReadPortUshort(byval port as USHORT) as USHORT
declare sub DlPortWritePortUshort(byval port as USHORT, byval Value as USHORT)
declare function DlPortReadPortUlong(byval port as ULONG) as ULONG
declare sub DlPortWritePortUlong(byval port as ULONG, byval Value as ULONG)
declare function MapPhysToLin(byval pbPhysAddr as PBYTE, byval dwPhysSize as DWORD, byval pPhysicalMemoryHandle as HANDLE ptr) as PBYTE
declare function UnmapPhysicalMemory(byval PhysicalMemoryHandle as HANDLE, byval pbLinAddr as PBYTE) as BOOL
declare function GetPhysLong(byval pbPhysAddr as PBYTE, byval pdwPhysVal as PDWORD) as BOOL
declare function SetPhysLong(byval pbPhysAddr as PBYTE, byval dwPhysVal as DWORD) as BOOL

end extern

#inclib "inpoutx64"

inp32(&H3d9)
sleep
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Try to use inpout32.dll

Post by D.J.Peters »

inpout32.dll and inpoutx64.dll both does not use any name mangling.
put both *.dlls in the folder of your exe thats all.
in case of 32-bit put "InstallDriver.exe" in same folder also !

Joshy

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
calatorius
Posts: 18
Joined: Oct 05, 2020 8:39

Re: Try to use inpout32.dll

Post by calatorius »

I tried with all archives in the exe folder, I copy the code like you post and in both cases, trying in 32 or in 64 bits the result is always the same:
prueba.o:fake:(.text+0x36): undefined reference to `Inp32'

I used all convinations WinFbe, CLI, in 32 and 64 bits in both cases

prueba.bas:

Code: Select all

#include "windows.bi"
'#include "inpout32.bi"

extern "Windows"

declare sub Out32(byval PortAddress as short, byval data as short)
declare function Inp32(byval PortAddress as short) as short
declare function IsInpOutDriverOpen() as BOOL
declare function IsXP64Bit() as BOOL
declare function DlPortReadPortUchar(byval port as USHORT) as UCHAR
declare sub DlPortWritePortUchar(byval port as USHORT, byval Value as UCHAR)
declare function DlPortReadPortUshort(byval port as USHORT) as USHORT
declare sub DlPortWritePortUshort(byval port as USHORT, byval Value as USHORT)
declare function DlPortReadPortUlong(byval port as ULONG) as ULONG
declare sub DlPortWritePortUlong(byval port as ULONG, byval Value as ULONG)
declare function MapPhysToLin(byval pbPhysAddr as PBYTE, byval dwPhysSize as DWORD, byval pPhysicalMemoryHandle as HANDLE ptr) as PBYTE
declare function UnmapPhysicalMemory(byval PhysicalMemoryHandle as HANDLE, byval pbLinAddr as PBYTE) as BOOL
declare function GetPhysLong(byval pbPhysAddr as PBYTE, byval pdwPhysVal as PDWORD) as BOOL
declare function SetPhysLong(byval pbPhysAddr as PBYTE, byval dwPhysVal as DWORD) as BOOL

end extern

#inclib "inpoutx64"

inp32(&H3d9)
sleep
inpout32.bi:

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
Top
Result:

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

with all files in the fbc folder
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Try to use inpout32.dll

Post by jj2007 »

There is a thread at the PowerBasic forum. My own tests with the InpOut32.dll downloadable here indicate that Out32() and Inp32() work but several other functions are not available:

Code: Select all

not found (line 11):    IsInpOutDriverOpen
not found (line 12):    DlPortReadPortUshort
not found (line 13):    DlPortReadPortUlong
not found (line 14):    DlPortWritePortUShort
not found (line 15):    DlPortWritePortUlong
In contrast, DlPortIO from here misses Out32 and Inp32:

Code: Select all

not found (line 9):     Out32
not found (line 10):    Inp32
not found (line 11):    IsInpOutDriverOpen
The Dll should offer these, but the first three are not available in DlPortIO.dll:

Code: Select all

  Declare void Out32, 2	; ushort port, data
  Declare void Inp32, 2	; ushort port, data
  Declare IsInpOutDriverOpen	; no args
  Declare DlPortReadPortUshort, 1	; ushort port
  Declare DlPortReadPortUlong, 1	; int port
  Declare DlPortWritePortUshort, 2	; int port, data
  Declare DlPortWritePortUlong, 2	; int port, data
Post Reply