beginner Q's about COM/.NET (context = exposing a pre-existing app to scripting)
- From: "Jason S" <jmsachs@xxxxxxxxx>
- Date: 24 Jan 2006 06:34:47 -0800
Hello, I am not sure if this group is the best place to post but I have
found it very unclear where the dividing lines are between
ATL/COM/.NET/Automation/ActiveX etc.
I have an existing app which has a few classes (which I need to
re-architect more sanely, but that's besides the point). These are all
non-GUI, relatively simple; the only OS-related thing about them is
some of them use the serial port, operate in more than one thread &
therefore contain mutexes to access the serial port.
They are and will continue to be implemented in C++ for various
reasons. At present I am starting out using ATL in MSVC 6.0.
I am trying to figure out how to wrap COM around (or incorporate it in,
or whatever you call it) these classes to expose them to scripting
languages & am having trouble finding a decent tutorial; all the
tutorials out there on the 'net seem to be too simple to explain some
of the common & important subleties, or they're about GUI objects which
are different in a lot of ways. (e.g. I have no interest in object
linking/embedding)
I understand most of the basic aspects of COM but am struggling with a
few of the subtleties.
Are there good resources to learn the following:
a) Should I abandon COM & go for .NET? I can't even find a good site
explaining what .NET is and why it's different. I don't think we have
an updated compiler here that supports .NET & am reluctant to upgrade.
A software engineer friend at first told me it would be easier to work
with .NET, not COM, but then he said if I'm just doing basic things &
not worrying about inter-computer security or object
marshalling/storage then COM is probably fine.
b) If I have a pre-existing object hierarchy where objects are created
within the hierarchy itself, how do I handle reference counting? I'm
fairly sure I won't be asking for new objects through CoCreateInstance
except for one initial call which returns a singleton object A; all the
other objects are derived through A's methods. e.g. B =
A.createB('B_name') or C = A.lookupC('preexisting_C'). B and C will
have cyclical links back to their parents & will not be destroyed
except explicitly through external methods. So it doesn't seem to make
sense to me how reference counting fits into the picture. (especially
how to handle the cyclical link case)
c) what is the proper behavior for the COM server to take if a script
stores a reference to an object B, which no longer exists, and then the
script later calls one of B's methods? (which Murphy's law says WILL
happen)
d) is there a way to disallow CoCreateInstance on a particular class B?
It needs to be public because my scripts will be receiving instances of
class B from class A's methods, calling their methods & passing them as
parameters to class A's methods -- but in no case do I want someone to
create an orphan class B outside the context of class A.
e) best practices for passing exceptions back to the script clients
calling my COM methods
f) recommended ways to create & return strings that contain formatted
numbers -- right now I'm using a fixed char[] buffer, calling
_snprintf() on it, then copying the buffer to a _bstr_t, and storing it
in the return value's variant BSTR field.
g) is there a suggested COM architecture to provide mutex
functionality? As I experiment w/ COM I am running a .EXE COM with the
STA model... If client process X calls A.lockserialport(), then does
stuff, then A.unlockserialport() and client process Y also makes the
same sequence of calls on the same object, I'm not clear whether my COM
server code would be running these in the same thread or different
threads. If the server runs in the same thread via a messageloop, a
standard mutex would not block. If the server runs them in different
threads, how do I guarantee this, and can I use WaitForSingleObject()
or do I have to use MsgWaitForSingleObject()?
sorry for all the questions; I've looked around for answers & haven't
been able to find them.
.
- Follow-Ups:
- Prev by Date: Re: another COM-Question: how to inject a type-lib into a dll?
- Next by Date: Re: another COM-Question: how to inject a type-lib into a dll?
- Previous by thread: how to launch a notepad with the supplied information
- Next by thread: Re: beginner Q's about COM/.NET (context = exposing a pre-existing app to scripting)
- Index(es):
Relevant Pages
|