Discussion:
[python-win32] Implementing an instance of an external/physical .dll file?
Jacob Kruger
2015-01-19 12:36:29 UTC
Permalink
I have a .dll pulled from following hub:
https://github.com/qtnc/UniversalSpeech

What's the easiest/simplest way to then implement/instantiate an instance of it working via file path?

If possible, and, currently working with python 3.4, on a windows7 64 bit machine, FWIW.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."
Tim Roberts
2015-01-19 19:17:18 UTC
Permalink
Post by Jacob Kruger
https://github.com/qtnc/UniversalSpeech
What's the easiest/simplest way to then implement/instantiate an
instance of it working via file path?
If possible, and, currently working with python 3.4, on a windows7 64 bit machine, FWIW.
You can use the ctypes module to access virtually any arbitrary DLL.
That's what they mean when they talk about an FFI library. There's a
learning curve, but essentially anything is possible.

Let me caution you, however, that the DLL in that release is a 32-bit
DLL. If you are using 32-bit Python, you're OK. If you're using 64-bit
Python, you can't use the binary. You'd have to build it from source.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Jacob Kruger
2015-01-19 21:20:00 UTC
Permalink
----- Original Message -----
Post by Tim Roberts
You can use the ctypes module to access virtually any arbitrary DLL.
That's what they mean when they talk about an FFI library. There's a
learning curve, but essentially anything is possible.
Ok, both of the following code snippets execute without any errors/issues:
from ctypes import *
import os
#first one
uS = windll.LoadLibrary(os.path.realpath("UniversalSpeech.dll"))

#second one
uSc = cdll.LoadLibrary(os.path.realpath("UniversalSpeech.dll"))
#end code

But, issue then is that am really not sure how to then work with
functions/methods 'exposed' by the instance/DLL, since if look at some of
the ctypes tutorial material, it seems like you need to already know exactly
what the .dll offers, etc., to then set up/implement wrappers/pointers to
things like functions, etc.?
Post by Tim Roberts
Let me caution you, however, that the DLL in that release is a 32-bit
DLL. If you are using 32-bit Python, you're OK. If you're using 64-bit
Python, you can't use the binary. You'd have to build it from source.
I specifically stick to 32-bit python, in case it will affect target, etc.
Post by Tim Roberts
--
But, for example, when working with another alternative that has been
registered on system, and then using win32com.client, can just make function
calls, etc., but, think that one relates to that .dll having been run
through an effective regsvr32?

So, something along the lines of referring to it using it's ProgID:

#start code
import win32com.client
spk = win32com.client.Dispatch("Say.Tools")
spk.Say("hello world")
#end code

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."
Tim Roberts
2015-01-20 08:32:50 UTC
Permalink
Post by Jacob Kruger
----- Original Message -----
Post by Tim Roberts
You can use the ctypes module to access virtually any arbitrary DLL.
That's what they mean when they talk about an FFI library. There's a
learning curve, but essentially anything is possible.
from ctypes import *
import os
#first one
uS = windll.LoadLibrary(os.path.realpath("UniversalSpeech.dll"))
#second one
uSc = cdll.LoadLibrary(os.path.realpath("UniversalSpeech.dll"))
#end code
But, issue then is that am really not sure how to then work with
functions/methods 'exposed' by the instance/DLL, since if look at some of
the ctypes tutorial material, it seems like you need to already know exactly
what the .dll offers, etc., to then set up/implement wrappers/pointers to
things like functions, etc.?
Yes, of course you do. You can’t possibly expect to use a DLL without knowing how to use it. Unless someone has already done so, you will have to translate the C prototypes for all of the DLL’s exported functions into Python ctypes declarations (or, at least, the functions you need to use).
Post by Jacob Kruger
But, for example, when working with another alternative that has been
registered on system, and then using win32com.client, can just make function
calls, etc., but, think that one relates to that .dll having been run
through an effective regsvr32?
Yes, for DLLs that are COM servers, the DLL (or its type library) contains enough information about the parameters and parameter types that the win32com module can automatically generate the Python code to convert between them. This DLL is not a COM server, so you have to do all of that by hand..

Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.

Loading...