Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Time sharing: The use of many people by the computer.


programming / comp.lang.tcl / Re: ffidl to access dll functions

SubjectAuthor
* ffidl to access dll functionspd
`* Re: ffidl to access dll functionsAshok
 `* Re: ffidl to access dll functionspd
  +* Re: ffidl to access dll functionspd
  |`- Re: ffidl to access dll functionsAshok
  `* Re: ffidl to access dll functionsAshok
   `- Re: ffidl to access dll functionsStephan Effelsberg

1
Subject: ffidl to access dll functions
From: pd
Newsgroups: comp.lang.tcl
Date: Sat, 16 Apr 2022 00:20 UTC
X-Received: by 2002:a05:620a:6cc:b0:69b:dd1b:3235 with SMTP id 12-20020a05620a06cc00b0069bdd1b3235mr860405qky.374.1650068443530;
Fri, 15 Apr 2022 17:20:43 -0700 (PDT)
X-Received: by 2002:a05:6808:140b:b0:2ec:f41e:a4c6 with SMTP id
w11-20020a056808140b00b002ecf41ea4c6mr565266oiv.17.1650068443204; Fri, 15 Apr
2022 17:20:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 15 Apr 2022 17:20:43 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=119.12.228.135; posting-account=fwjo5QoAAAAcS9TSqEAQL1VEl7b8nCOq
NNTP-Posting-Host: 119.12.228.135
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com>
Subject: ffidl to access dll functions
From: eukel...@gmail.com (pd)
Injection-Date: Sat, 16 Apr 2022 00:20:43 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 28
View all headers
I was trying to use ffidl to access functions defined in a dll located in the same folder of my tcl script.

I'm using a windows machine executing the script both using cmd.exe and cygwin to execute "tclsh.exe myscript.tcl"

Every attempt get the same error:

couldn't load file "AutoItDLL.dll" : ???

I've tried every combination of path to name the dll file, for example this:

lappend auto_path [pwd]
package require Ffidl
set DLL AutoItDLL.dll
set DLL [file nativename "[pwd]\\$DLL"]
puts "$DLL"
ffidl::callout AUTOIT_BlockInput {int} int [ffidl::symbol $DLL AUTOIT_BlockInput]

c:\tcl> tclsh pp.tcl
C:\tcl\AutoItDLL.dll
couldn't load file "C:\tcl\AutoItDLL.dll" : ???
    while executing
"ffidl::symbol $DLL AUTOIT_BlockInput"
    invoked from within
"ffidl::callout AUTOIT_BlockInput {int} int [ffidl::symbol $DLL AUTOIT_BlockInput]"
    (file "pp.tcl" line 9)

If I use a system dll like user32.dll everything goes ok, maybe is ffidl only able to open system dll's ?

regards


Subject: Re: ffidl to access dll functions
From: Ashok
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sat, 16 Apr 2022 05:31 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: palm...@yahoo.com (Ashok)
Newsgroups: comp.lang.tcl
Subject: Re: ffidl to access dll functions
Date: Sat, 16 Apr 2022 11:01:17 +0530
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <t3dkb5$ilh$1@dont-email.me>
References: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Apr 2022 05:31:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="eebb4274cd87374feabcb708b4133562";
logging-data="19121"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pQVRgVnYJIj81GKyMpDMN"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:aK2QMUYKy4uUERaG1xYWPpOm3Ns=
In-Reply-To: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com>
Content-Language: en-US
View all headers
On 4/16/2022 5:50 AM, pd wrote:
I was trying to use ffidl to access functions defined in a dll located in the same folder of my tcl script.

I'm using a windows machine executing the script both using cmd.exe and cygwin to execute "tclsh.exe myscript.tcl"

Every attempt get the same error:

couldn't load file "AutoItDLL.dll" : ???

  Two possibilities come to mind - it's a 32-bit/64-bit mismatch in either direction, or some support DLL that autoitdll.dll depends on that is missing  (including possibly a C runtime version that is not installed on the system)

/Ashok



Subject: Re: ffidl to access dll functions
From: pd
Newsgroups: comp.lang.tcl
Date: Sat, 16 Apr 2022 14:36 UTC
References: 1 2
X-Received: by 2002:ac8:4e46:0:b0:2e1:b933:ec06 with SMTP id e6-20020ac84e46000000b002e1b933ec06mr2414439qtw.684.1650119792525;
Sat, 16 Apr 2022 07:36:32 -0700 (PDT)
X-Received: by 2002:a4a:4c49:0:b0:339:e96:11c9 with SMTP id
a70-20020a4a4c49000000b003390e9611c9mr1120259oob.71.1650119792228; Sat, 16
Apr 2022 07:36:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 16 Apr 2022 07:36:32 -0700 (PDT)
In-Reply-To: <t3dkb5$ilh$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=119.12.228.135; posting-account=fwjo5QoAAAAcS9TSqEAQL1VEl7b8nCOq
NNTP-Posting-Host: 119.12.228.135
References: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com> <t3dkb5$ilh$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <beeb6db8-4ec3-441d-8844-83d465a8a8cbn@googlegroups.com>
Subject: Re: ffidl to access dll functions
From: eukel...@gmail.com (pd)
Injection-Date: Sat, 16 Apr 2022 14:36:32 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 126
View all headers
El sábado, 16 de abril de 2022 a las 7:31:21 UTC+2, Ashok escribió:
On 4/16/2022 5:50 AM, pd wrote:
I was trying to use ffidl to access functions defined in a dll located in the same folder of my tcl script.
Every attempt get the same error:

couldn't load file "AutoItDLL.dll" : ???

Two possibilities come to mind - it's a 32-bit/64-bit mismatch in
either direction, or some support DLL that autoitdll.dll depends on that
is missing (including possibly a C runtime version that is not
installed on the system)

It seems it's a problem of arch mismatch, all local dlls I have tested are 32-bit compiled,  I create a simple 64-bit dll just to test and it is loaded correctly and I can use the function.

But I'm a bit confused because I've also copied the user32.dll from my system32 folder to my test folder and tried to load it from my local folder, getting "couldn¡t load file" error while using the system user32.dll works fine.

My OS is a windows 10 x64 and I'm executing the tcl scripts both from cygwin (assume 32-bit) and windows cmd.exe, with same results.

Here you are my tests and my conclusions, for every test I show the tcl script, the kind of dll and the script execution commad:

[1] ------------------------  trying to load AutoItDLL.dll which is a 32bit i386 dll    result: error loading dll
$ cat ai.tcl
lappend auto_path [pwd]\\Ffidl0.6
package require Ffidl
set dll [file nativename [pwd]\\AutoItDLL.dll]
puts "$dll : [file exists $dll]"
ffidl::callout AUTOIT_WinMinimizeAll {} int [ffidl::symbol $dll AUTOIT_WinMinimizeAll]
AUTOIT_WinMinimizeAll
                                                                                         
$ file AutoItDLL.dll
AutoItDLL.dll: PE32 executable (DLL) (GUI) Intel 80386, for MS Windows, UPX compressed

$ tcl ai.tcl
C:\tcl\AutoItDLL.dll : 1
couldn't load file "C:\tcl\AutoItDLL.dll" : ???
    while executing
"ffidl::symbol $dll AUTOIT_WinMinimizeAll"
    invoked from within
"ffidl::callout AUTOIT_WinMinimizeAll {} int [ffidl::symbol $dll AUTOIT_WinMinimizeAll]"
    (file "ai.tcl" line 8)

[2] ------------------------  trying to load system user32.dll         result: success
$ cat u.tcl
lappend auto_path [pwd]\\Ffidl0.6
package require Ffidl
ffidl::callout findwin {pointer-utf8 pointer-utf8} long [ffidl::symbol user32 FindWindowA]
puts "win:  [findwin {} {}]"

$  tcl u.tcl
win:  0

[3] ------------------------  trying to load user32.dll which is a copy of system32\user32.dll a 64 bit x86-64 dll    result: error loading dll
$ cat lu.tcl
lappend auto_path [pwd]\\Ffidl0.6
package require Ffidl
set dll [file nativename [pwd]\\user32.dll]
puts "$dll : [file exists $dll]"
ffidl::callout findwin {pointer-utf8 pointer-utf8} long [ffidl::symbol $dll  FindWindowA]
puts "win:  [findwin {} {}]"

$ file user32.dll
user32.dll: PE32+ executable (DLL) (GUI) x86-64, for MS Windows

$ tcl lu.tcl
C:\tcl\user32.dll : 1
couldn't load file "C:\tcl\user32.dll" : ???
    while executing
"ffidl::symbol $dll  FindWindowA"
    invoked from within
"ffidl::callout findwin {pointer-utf8 pointer-utf8} long [ffidl::symbol $dll  FindWindowA]"
    (file "lu.tcl" line 9)

[4] ------------------------  trying to load libhola.dll a test dll which only one function, it's a 64 bit x86-64 dll         result: success
$ cat f.tcl
lappend auto_path [pwd]\\Ffidl0.6
package require Ffidl
set dll [file nativename [pwd]\\libhola.dll]
puts "$dll : [file exists $dll]"
ffidl::callout hola {pointer-utf8 } void [ffidl::symbol $dll  hola ]
hola {hola mundo!}

$ file libhola.dll
libhola.dll: PE32+ executable (DLL) (console) x86-64, for MS Windows

$ tcl f.tcl
C:\tcl\libhola.dll : 1
hola mundo!                                                                                                                                                


What get me confused is user32.dll is the same kind of dll than libhola.dll : PE32+ executable (DLL)  x86-64
The only difference is libhola is a console DLL while user32.dll is a GUI DLL:
libhola.dll: PE32+ executable (DLL) (console) x86-64, for MS Windows
user32.dll: PE32+ executable (DLL) (GUI) x86-64, for MS Windows

libhola.dll works ok when loaded from current dir but user32.dll doesn't work from current dir, it only works when using the system one  (being both same arch, x86-64 64-bit)

Any idea of what's happening here?

regards



Subject: Re: ffidl to access dll functions
From: pd
Newsgroups: comp.lang.tcl
Date: Sat, 16 Apr 2022 14:48 UTC
References: 1 2 3
X-Received: by 2002:a05:6214:dcc:b0:446:4e6e:e919 with SMTP id 12-20020a0562140dcc00b004464e6ee919mr533841qvt.24.1650120483861;
Sat, 16 Apr 2022 07:48:03 -0700 (PDT)
X-Received: by 2002:a05:6830:154c:b0:5e6:85c5:ed8b with SMTP id
l12-20020a056830154c00b005e685c5ed8bmr1235328otp.253.1650120483598; Sat, 16
Apr 2022 07:48:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 16 Apr 2022 07:48:03 -0700 (PDT)
In-Reply-To: <beeb6db8-4ec3-441d-8844-83d465a8a8cbn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=119.12.228.135; posting-account=fwjo5QoAAAAcS9TSqEAQL1VEl7b8nCOq
NNTP-Posting-Host: 119.12.228.135
References: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com>
<t3dkb5$ilh$1@dont-email.me> <beeb6db8-4ec3-441d-8844-83d465a8a8cbn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d41b9315-f536-46d4-9788-cb313a69ddfen@googlegroups.com>
Subject: Re: ffidl to access dll functions
From: eukel...@gmail.com (pd)
Injection-Date: Sat, 16 Apr 2022 14:48:03 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
El sábado, 16 de abril de 2022 a las 16:36:34 UTC+2, pd escribió:
Two possibilities come to mind - it's a 32-bit/64-bit mismatch in
either direction, or some support DLL that autoitdll.dll depends on that
is missing (including possibly a C runtime version that is not
installed on the system)
It seems it's a problem of arch mismatch, all local dlls I have tested are 32-bit compiled, I create a simple 64-bit dll just to test and it is loaded correctly and I can use the function.

another question,  Is it possible to load 32-bit dll or 64-bit dll on demand from a tcl script using ffdi ?   I mean, I can choose to load 32-bit version or 64-bit version (for example chossing the right ffidl.dll ) or I'm constrained by the machine arch?    I ask this because the ffidl.dll I'm using is a 32-bit dll and it seems to load only 64-bit dll


Subject: Re: ffidl to access dll functions
From: Ashok
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 17 Apr 2022 15:28 UTC
References: 1 2 3 4
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: palm...@yahoo.com (Ashok)
Newsgroups: comp.lang.tcl
Subject: Re: ffidl to access dll functions
Date: Sun, 17 Apr 2022 20:58:07 +0530
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <t3hbm9$p58$1@dont-email.me>
References: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com>
<t3dkb5$ilh$1@dont-email.me>
<beeb6db8-4ec3-441d-8844-83d465a8a8cbn@googlegroups.com>
<d41b9315-f536-46d4-9788-cb313a69ddfen@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 17 Apr 2022 15:28:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="63dbd11246a88cca9dee5538e45ce85f";
logging-data="25768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2kYx/jEuP1fVHZgLKc6j3"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Cancel-Lock: sha1:VEOUUn27SXUk32rCBnh3/AjRGmA=
In-Reply-To: <d41b9315-f536-46d4-9788-cb313a69ddfen@googlegroups.com>
Content-Language: en-US
View all headers
On 4/16/2022 8:18 PM, pd wrote:
El sábado, 16 de abril de 2022 a las 16:36:34 UTC+2, pd escribió:
Two possibilities come to mind - it's a 32-bit/64-bit mismatch in
either direction, or some support DLL that autoitdll.dll depends on that
is missing (including possibly a C runtime version that is not
installed on the system)
It seems it's a problem of arch mismatch, all local dlls I have tested are 32-bit compiled, I create a simple 64-bit dll just to test and it is loaded correctly and I can use the function.

another question,  Is it possible to load 32-bit dll or 64-bit dll on demand from a tcl script using ffdi ?   I mean, I can choose to load 32-bit version or 64-bit version (for example chossing the right ffidl.dll ) or I'm constrained by the machine arch?    I ask this because the ffidl.dll I'm using is a 32-bit dll and it seems to load only 64-bit dll

 From a 32-bit Tcl, ffidl.dll must also be 32-bit and the DLL you are trying to load must also be the same. No way around it.

Ditto for 64-bit.

I cannot see how you might be using a 64-bit dll from a 32-bit ffidl. It's simply not possible.

/Ashok


Subject: Re: ffidl to access dll functions
From: Ashok
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 17 Apr 2022 15:30 UTC
References: 1 2 3
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: palm...@yahoo.com (Ashok)
Newsgroups: comp.lang.tcl
Subject: Re: ffidl to access dll functions
Date: Sun, 17 Apr 2022 21:00:10 +0530
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <t3hbq2$p58$2@dont-email.me>
References: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com>
<t3dkb5$ilh$1@dont-email.me>
<beeb6db8-4ec3-441d-8844-83d465a8a8cbn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 17 Apr 2022 15:30:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="63dbd11246a88cca9dee5538e45ce85f";
logging-data="25768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/t0pHNcaLgA1vwNSge28TP"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Cancel-Lock: sha1:vcv+yvA5KeNpwLxEBdjOiCt3yCQ=
In-Reply-To: <beeb6db8-4ec3-441d-8844-83d465a8a8cbn@googlegroups.com>
Content-Language: en-US
View all headers
On 4/16/2022 8:06 PM, pd wrote:
bhola.dll works ok when loaded from current dir but user32.dll doesn't work from current dir, it only works when using the system one  (being both same arch, x86-64 64-bit)

Any idea of what's happening here?

regards


I do not remember the details, but I think Windows has special handling for the system DLLs (like user32.dll). It enforces that they have to be loaded from the system directory (to prevent some type of malware).

I could be wrong.


/Ashok


Subject: Re: ffidl to access dll functions
From: Stephan Effelsberg
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 19:40 UTC
References: 1 2 3 4
X-Received: by 2002:ad4:5a03:0:b0:456:5533:4ab1 with SMTP id ei3-20020ad45a03000000b0045655334ab1mr15165700qvb.24.1652125241222;
Mon, 09 May 2022 12:40:41 -0700 (PDT)
X-Received: by 2002:a05:6808:ed0:b0:2f9:c6f8:8b38 with SMTP id
q16-20020a0568080ed000b002f9c6f88b38mr8464245oiv.215.1652125240953; Mon, 09
May 2022 12:40:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 12:40:40 -0700 (PDT)
In-Reply-To: <t3hbq2$p58$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.220.10.110; posting-account=xi3p4wkAAADb3iGADRJjvFLMqHyukyk7
NNTP-Posting-Host: 94.220.10.110
References: <086bb5a8-60fb-472a-9a09-09bcb7e47bbfn@googlegroups.com>
<t3dkb5$ilh$1@dont-email.me> <beeb6db8-4ec3-441d-8844-83d465a8a8cbn@googlegroups.com>
<t3hbq2$p58$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3ad41fd0-6f3b-423b-b8f0-5cad71fba233n@googlegroups.com>
Subject: Re: ffidl to access dll functions
From: s.effels...@googlemail.com (Stephan Effelsberg)
Injection-Date: Mon, 09 May 2022 19:40:41 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2148
View all headers
I'm juggling with 32-bit and 64-bit DLLs myself from time to time. When working with system DLLs, you'll get the version that fits the bitness of the requesting process. Be aware of the File System Redirector:

https://docs.microsoft.com/en-us/windows/win32/winprog64/file-system-redirector

Try it yourself: Use the Windows command line to make a copy of user32.dll
copy c:\Windows\System32\user32.dll <somewhere>
You'll get a 64-bit copy of the DLL, you can even inspect the file with a simple text editor to verify this. Search for the string "PE", it's near the start of the file (offset 232, methinks). The third character after PE is "d" for a 64-bit PE and "L" for a 32-bit PE.

Now use a 32-bit shell, e.g. a 32-bit Tclkit.
file copy c:/Windows/System32/user32.dll <somewhereelse>
You'll get the 32-bit copy of that DLL.

-- Stephan


1
rocksolid light 0.7.2
clearneti2ptor