# Adopt COM-Server Wrapper from Python to Julia

**URL:** <https://discourse.julialang.org/t/adopt-com-server-wrapper-from-python-to-julia/79853>\
**Category:** Jobs\
**Tags:** com-server\
**Created:** [April 22, 2022, 3:37pm UTC](https://discourse.julialang.org/t/adopt-com-server-wrapper-from-python-to-julia/79853 "2022-04-22T15:37:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [April 22, 2022, 3:37pm UTC](https://discourse.julialang.org/t/adopt-com-server-wrapper-from-python-to-julia/79853/1 "2022-04-22T15:37:37Z")

</div>

Hi,  
Under python the script „makepy.py“ exists, it generates a wrapper for a specified COM-server.  
I wonder, can this wrapper code be rewritten in Julia-Style?  
If there is someone who offers such a service on the basis of a “contract for specific work” I would be interested in a quote.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [April 22, 2022, 9:18pm UTC](https://discourse.julialang.org/t/adopt-com-server-wrapper-from-python-to-julia/79853/2 "2022-04-22T21:18:45Z")

</div>

I was mostly curious to know more about this project, so I googled, and I suppose it could be done (but I will not), since I think everything you can to in Python (at least on Windows) can be done in Julia. I see most of the project is in C++ (but I don’t think that changes things), assuming it that first one:

> **[GitHub - mhammond/pywin32: Python for Windows (pywin32) Extensions](https://github.com/mhammond/pywin32)**
>
> Python for Windows (pywin32) Extensions. Contribute to mhammond/pywin32 development by creating an account on GitHub.

I do see the makepy.py file itself is rather small (at 455 lines): [https://github.com/mhammond/pywin32/blob/main/com/win32com/client/makepy.py](https://github.com/mhammond/pywin32/blob/main/com/win32com/client/makepy.py)

it’s a generator, so possibly it’s easiest to change that file (and keep it in Python would then be ok) to rather generate Julia code. Since the generated code, is now, in Python, there might be lots more you need to translate, or not, just use PyCall.jl, or maybe rather by now PythonCall.jl? I.e. generate Julia code that uses Python libraries, and thus Python also, was that what you wanted?

> **[COM Clients and Servers - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/com/com-clients-and-servers)**
>
> A critical aspect of COM is how clients and servers interact.

> There are two main types of servers, in-process and out-of-process. In-process servers are implemented in a dynamic linked library (DLL), and out-of-process servers are implemented in an executable file (EXE). Out-of-process servers can reside either on the local computer or on a remote computer.

Before I comment on that, I think you’re not asking to make a Julia COM server (that answer would be a bit involved), just a client for it, which the code should generate for you.

I haven’t seen much Windows-specific Julia code. Julia itself is cross-platform, most to not call the Win32 API directly (I’ve however seen a project for doing that, of course then tying you to Windows, or Wine e.g. under Linux), such as for a Windows GUI. [ ~~I’ve not seen anything for COM yet in Julia.~~ EDIT: found your post below:

> [@Is there something like pywin32 in Julia?](https://discourse.julialang.org/t/is-there-something-like-pywin32-in-julia/37024/3):
>
> Here is my example to use PyCall to open and modify an existing Excel-file via a COM server: # Create COM server via Python Interface # first: install "pywin32" via conda: # using Conda; Conda.add("pywin32") using PyCall using XLSX pw = pyimport("win32com") pwc = pyimport("win32com.client") FN\_excel = raw"C:\tmp\MyTest.xlsx"; if ~isfile(FN\_excel) XLSX.writetable(FN\_excel) end xlApp = pwc.Dispatch("Excel.Application") xlApp.Visible = 1 if isfile(FN\_excel) workBook = xlApp.Workbooks.O…

Personally I would like most to use cross-platform libraries such as Qt or GTK, also supporting Windows, or whatever is a COM replacement, if there is anything such (is there, or only a Linux replacement, but no abstraction targeting that or Windows?). If you need/want COM, I guess you do, but I’m curious, can you tell me what for?

It might be nice to know the real (business) problem you want solved. Maybe there’s another way, and this is an XY problem.

Before finding what I believe is the right code (please confirm), I also found:

> **[makepy](https://pypi.org/project/makepy/)**
>
> makepy: Handsfree Python Module Programming

there the code is only 390 lines (if someone want to start translating, I guess a slightly older version): [https://github.com/SublimeText/Pywin32/blob/master/lib/x32/win32com/client/makepy.py](https://github.com/SublimeText/Pywin32/blob/master/lib/x32/win32com/client/makepy.py)

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [April 22, 2022, 10:17pm UTC](https://discourse.julialang.org/t/adopt-com-server-wrapper-from-python-to-julia/79853/3 "2022-04-22T22:17:09Z")

</div>

> [@Palli](#):
>
> In-process servers are implemented in a dynamic linked library (DLL),

Hi Palli,

it is an “In-process server” provided by a the manufacturer of a digitizer /  
oscilloscope. The COM-interface as well as the software of the HW is MS-windows only.  
In matlab it is quite convenient to invoke / create this `COM In-process server`.  
The command to create the object and to use the server to open access to the proprietary binary file is:

```julia
myObject = actxserver('ServerName');
myObject.invoke('Open', 'data_file_name');

```

Unfortunately, under Octave the same approach fails.

Maybe the python `win32com` works, but I have not yet figured out, what the trick is.  
Up to now I have only worked with `PyCall.jl` I will have a look on `PythonCall.jl`, maybe this better suited to achieve my purpose.  
The objective is to transfer a proprietary binary file format into a mat-file.  
Unfortunately, my C-Coding skills are quite limited.  
Meanwhile, I received an interesting link that deals with my topic:  
[Accessing COM from Julia](https://gist.github.com/peteristhegreat/0d2d2580bd3fd353b178c1c4da2e455e)  
If someone is interested to receive the wrapper created by means of the python script `makepy.py` by mhammond please send my a note.

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [April 23, 2022, 7:00am UTC](https://discourse.julialang.org/t/adopt-com-server-wrapper-from-python-to-julia/79853/4 "2022-04-23T07:00:59Z")

</div>

Hi,

this morning I tried again to get it into operation in Python and today managed  
to do it in the right manner:

```julia
import win32com.client
from os.path import exists as file_exists

IFileManager_Object = win32com.client.Dispatch("COM_ServerName")

FN_iFile = 'C:/data/data_log/Data_Types/iFile/iFile'

if (not file_exists(FN_iFile)):
    raise TypeError("File not found!")

COM_ServerObject.Open(FN_iFile)
n_channels = COM_ServerObject.GetChannelCount('')

```

If the documentation of your COM-Server is not complete, the python script `makepy.py` by “mhammond” helps to figure out which function are available.

The same code under Julia looks like this:

```julia
# Create COM server via Python Interface
# first: install "pywin32" via conda:
# using Conda; Conda.add("pywin32")

using PyCall
pwc = pyimport("win32com.client")

COM_ServerObject = pwc.Dispatch("COM_ServerName")

FN_iFile = raw"C:\data\data_log\Data_Types\iFile\ifile_name";
if ~isfile(FN_iFile)
    error("file \"" * FN_mat * "\" does not exist!\n")
end

COM_ServerObject.Open(FN_iFile);
n_channels = COM_ServerObject.GetChannelCount("")

```
