News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

COM objects and Python

Started by the_dog, October 20, 2005, 11:27:06 AM

Previous topic - Next topic

the_dog

Quick(ish) question -

I've been a high level scripting guy for various apps at work used internally.  I've been reading a great deal on lower level languages lately, to be able to rewrite the algorithms causing me the most pain in the high level languages.  My personal favorite in the high level is Python, which is interpreted, making me confused as to how I would link the assembler code in.  The most obvious answer to me would be creating a com object, as they are easy to use from python, but I'm not finding good documentation on that yet.  Where would I go to find info on COM objects from MASM?  Or, do you guys have a better suggestion?

Also - If dll's run inprocess, and therefore use the same memory space as the calling program to execute, what prevents the dll code's interaction with the memory from corrupting data objects assigned to arbitrary places in the calling program?  Apologies if I'm misunderstanding something, but I have read from msdn .exe = out of process , .dll = in process.  That combined with the way assembler has you effectively placing things in the memory space of a process worries me.  I have no idea where python will have put things when it calls my assembly logic, so where do I put things generated in the assembly logic?

OK, so not quick, and more than one question.  Just finishing a 12 hour shift, mostly trying to wrap my head around assembler <--> non-C program interaction.

the_dog

A clarification:

My normal model has been using Python to get and preprocess data, Macromedia Flash embedded in a Python app to display anything needing vector graphics / custom interactivity, wxWindows framework for python to build the interface otherwise (this abstracts the Windows API.)  My employer has been adopting more and more prepackaged Java GUI programs, so memory footprint is becoming a bigger deal to me all the time, as is CPU usage.  What I'm specifically looking to do in assembler is preprocessing (transformations, statistics, preplotting really big vector stuff for Flash) large amounts of data.

In other words, I'm quite happy with Python's overhead for doing things a few, tens, or sometimes hundreds of times.  When I'm looping through thousands, tens of thousands, or more objects....  I need a better answer.  That search led me to MASM and this forum.

hutch--

Hi dog,

Welcome on board. You will need to know your way around the interfaces of the stuff you are using to be able to use assembler and this will probably be stuff like DLL interface conventions and the like. There is a bit of stuff around on COM in MASM but COM is tending to be left behind with the introduction of .NET tchnology so I don't know if there is much future in using it. Now you will have to see if there is a way to interface Pyton with any DLL you write yourself but if you write it correctly it will allocate its own memory so you should not have a problem there.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

QvasiModo

Hi the_dog :)

Can't you simply write a Python-wrapped C module with inlined assembly? That seems a lot easier to do than implementing COM objects, if your only intention is to run native code from Python.

the_dog

I thought about C itself for implementing my problem logic more efficiently. That's the best documented, encouraged approach with Python.  But, I know anything I write will be running on a Wintel system, so assembly seemed the best tool for the job.  The only things that put me off of inlined assembly in C are:  I don't have a C compiler, and I haven't touched C since college (mid - late 90's).  I work on a variety of little projects in a variety of languages, and the learning curve of assembly itself is fairly intimdating, so I've been trying to dodge that route.

Also - on variety...  sometimes I collaborate with VB guys, which is part of my interest in the com object approach.  I could use python to create a C wrapped assembly com object for them to use, but I wonder if that would add extra bloat, defeating the purpose of going to assembly in the first place.

I've used Paul Carter's 'PC Assembly Language' as a starting point, which seems quite good for the basics.  Do any of you recommend any other books / sites?  I was going to ask about references specifically on interfacing assembly Dll's with other languages, but it sounds like assembler just 'does what it does', and calling an assembled Dll is something you'd find in the documentation of the calling language.  I've always had a fairly easy time getting a given language to do what I need it to do fairly quickly.  Getting two 'things' to 'talk to each other' has always been the hard part for me, be it database queries, machines on a network, or whatever else.  I'm fairly confident I could learn to write fairly efficient algorithms in assembly reasonably quickly.  I'm a bit paranoid about being able to get to those algorithms in code, and reference their output.

Biterider

Hi the_dog
If you are looking for a dll COM Server (in process Server) there are some examples on the forum on how to do it. The ObjAsm32 package also contains 2 Demos (Demo 16 and OCX_LED) that demonstrate how to use and interface them. I hope it helps.  :P

Regards,

Biterider

sluggy

Quote from: the_dog on October 21, 2005, 04:08:42 AM
Also - on variety...  sometimes I collaborate with VB guys, which is part of my interest in the com object approach.  I could use python to create a C wrapped assembly com object for them to use, but I wonder if that would add extra bloat, defeating the purpose of going to assembly in the first place.
You don't need to do a COM component - you can just write a normal dll, then you can call it from Python and your VB team mates can call it too.

You were worried about memory handling when running inproc - all you have to do is in the dll create your own private heap, and use memory for that. The private heap is private to your module, whatever else is running in the same process space won't touch it.