Scripting and external dll

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
Butterbelly
Posts: 7
Joined: Tue Feb 14, 2017 7:53 pm

Scripting and external dll

Post by Butterbelly » Sat Oct 06, 2018 1:23 pm

Hi

have asked this on astroart forum and not got very far
Then thought this may be the best option - SHARPCAP

is it possible to interact with an external dll from the script language - the reason I ask is I would like to control my Hitecastro power hub - specifically the dew heaters from scripting - I have done a little research but it is 5 years since I did any serious programming with windows and com etc so forgive my simple questions.


Hitecastro supply a dll and quote


Using mhpCOM.
mhpCOM can be used with any programming or scripting language which
supports COM interop. Examples are the .net languages from Microsoft. Visual
Basic.net, Visual C# .net and Visual C++ can be downloaded freely from the
Microsoft Visual Studio Express site. Many other languages and tools will also
be eminently suitable. Scripting languages such as VBScript or JavaScript can
also leverage the functionality of mhpCOM.


an example use from vbscript would be

Dim mhp
Set mhp = CreateObject(“mhpCOM.mhpCOM”)

or


Dim mhp
Set mhp = CreateObject(“mhpCOM.mhpCOM”)
mhp.Heater 3, 75



My question is

Is this easy from scripting?
If not what do I need to get into to achieve this?
Any other question that I cant think of due to my ignorance!?

many thanks

Keith Butterworth

User avatar
admin
Site Admin
Posts: 2010
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Scripting and external dll

Post by admin » Sat Oct 06, 2018 8:08 pm

Hi Keith,

I think what you need is...

Code: Select all

from System import Activator
from System import Type
mhp = Activator.CreateInstance(Type.GetTypeFromProgID("mhpCOM.mhpCOM"))
mhp.Heater(3,75)
I'm fairly sure the first 3 lines are correct - the last is my guess based on your sample code - it may need tweaking.

cheers,

Robin

Butterbelly
Posts: 7
Joined: Tue Feb 14, 2017 7:53 pm

Re: Scripting and external dll

Post by Butterbelly » Sun Oct 07, 2018 7:12 am

Thanks for replying - I will try that out after updating and installing necessary dll
Cheers Keith Butterworth

Butterbelly
Posts: 7
Joined: Tue Feb 14, 2017 7:53 pm

Re: Scripting and external dll

Post by Butterbelly » Mon Oct 08, 2018 10:34 am

Hi no joy when I tried the commands
I got an error message which I have attached - I tried 1 or 2 variations of the syntax and always had the same error
.
The first 2 commands were accepted.

When I tried the smart context sensitive menus on the command it didn't seem to have picked anything up !?


Any suggestions
Attachments
screenshot.png
screenshot.png (283.32 KiB) Viewed 72 times

User avatar
admin
Site Admin
Posts: 2010
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Scripting and external dll

Post by admin » Mon Oct 08, 2018 4:03 pm

Hi,

it looks like the code

Code: Select all

Type.GetTypeFromProgID("mhpCOM.mhpCOM")
is not returning a valid object - that means that either the mhpCOM.mhpCOM string is incorrect or the DLL providing that object hasn't been registered correctly.

The following code demonstrates the basic technique with a COM object that will be correctly registered on your system

Code: Select all

from System import Activator
from System import Type
test = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
test.BrowseForFolder(0, "hello", 0)
This wlll show a folder browser window.

You may find that registering your dll for COM helps fix your original problem - from an administrative command prompt run

Code: Select all

regsvr32 "<full path to your mhpcom.dll>"
Robin

Butterbelly
Posts: 7
Joined: Tue Feb 14, 2017 7:53 pm

Re: Scripting and external dll

Post by Butterbelly » Mon Oct 08, 2018 4:47 pm

Robin
again thanks for your help
I will try your test code that should work and go from there
cheers
Keith

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest