How to Create COM Server

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to Create COM Server

phanuwat
Hi

    I need create Dolphin COM Server.
I create idl file and import to dolphin by Activex Component wizard
and implementation of IDispatch. When deploy and use
imageStripper is AXDllImageStripper have error following

"There is no type library associated with this component or the type library
cannot be found. You may deploy this component, but it may then be necessary
to distribute and register the type library separately in order for the
component to function. If this component only implements interfaces defined
by other components (which themselves supply a type library), or the
component is not intended for use with Automation clients (and a separate
marshalling DLL is available), then you may not need a type library."

How can l solve it. Thank you very much


Reply | Threaded
Open this post in threaded view
|

Re: How to Create COM Server

Schwab,Wilhelm K
>     I need create Dolphin COM Server.
> I create idl file and import to dolphin by Activex Component wizard
> and implementation of IDispatch. When deploy and use
> imageStripper is AXDllImageStripper have error following
>
> "There is no type library associated with this component or the type library
> cannot be found. [snip]"

It's been a long time since I found need to create a COM server, and I
don't think I ever created a disp interface server.  I recall finding
need to create "lots" (read more than I thought should be necessary) of
clsid methods to get things to work.  Have you tried asking for the
#typeLibrary?  Should that work?  If so, and you get an error, that
might lead you to the problem.  Do you deploy from a clean image?  If
so, you might be missing out on lazy initialization of something.

As you get closer to having it go, it might help to look out for
"covered" message boxes.  I had something starting to work and didn't
realize it because it was opening a message box that never made it to
the top of the z-order =:0

There is a lot of information in Ian's newsgroup archives, so some
searching and reading would no doubt help.  Below is an edited version
of one of Blair's posts on creating a COM server.

Good luck!

Bill


<h2>Blair on COM - 12-2001</h2>
My recommendation when developing COM server's in Dolphin would be to
proceed as follows:
<ol>
<li>Don't start by defining the interface in Dolphin using the
#defineFunctions method and #compileInterfaceIntoImplementor: (or
whatever it is), but instead start by defining the IDL. You can always
revise the IDL later so don't get into analysis paralysis when defining
the interface. Generally I would recommend sticking to automation
compatible interfaces
(i.e. use the VB compatible types) since this will make the object
usable from the widest possible range of clients, and simplifies
marshalling issues.</li>

<li>Run the IDL through 'midl /Oicf'. Repeat until it "compiles" (which
can be tedious since MIDLs error reporting is, ahem, not top notch).</li>

<li>Now use Dolphin's Active-X component wizard to generate the Dolphin
interface class(es). In loading the type library it will automatically
register, which takes care of marshalling (assuming only automation
compatible types have been used - if not then a marshalling DLL will
have to be compiled up).</li>

<li>Add a COMInterfaceImp subclass that will implement the COM 'server',
e.g. MyCOMServer.</li>

<li>Add a #supportedInterfaces method to MyCOMServer, this needs to
return an
array containing the interface class generated at (3).</li>

<li>Add a #clsid method to the class side of MyCOMServer which answers
the correct CLSID (this should be the one associated with the coclass
declaration in the IDL). - if the coclasses default interface is
specified in the IDL then the generated wrapper class will have a clsid
method that can simply be copied over). You might also like to add a
#progId method which answers the user-friendly string name of the
object.</li>

<li>In Dolphin drag/copy across COM interface's methods (which can be
done by dragging the category, or the method protocol) to MyCOMServer.
If the protocol is dragged the implementations will all consist of
'Error notYetImplemented'. If not replace the bodies with 'self halt'.
Later these can be fleshed out with a bit of 'programming in the
debugger'.</li>

<li>Send #registerClassFactor to MyCOMServer to register a class
factory.  Now with Dolphin running it should be possible to create an
instance of the COM object, either from within Dolphin (e.g.
'IMyInterface new' or 'IMyInterface createObject: 'MyCOMObject.1'), or
from some external client. Because the development system is running
with a class factory registered, actual registry entries are not needed,
even for the external client. Personally I wouldn't start fleshing out
the object implementation until this point, because I find it so much
easier to program COM servers in the debugger when I can see the actual
types of the arguments that arrive. </li>

<li>Send #register to MyCOMServer to create the necessary registry
entries. It should now be possible to instantiate a MyCOMServer object
from an external client (such as VB) with the Dolphin development image
shut down.</li>
</ol>


<h2>From the same post on missing marshaling code</h2>
The symptoms you describe (of seeing the class factory invoked, and the
instance of your object created) are absolutely classic for the absence
of marshalling code. COM proceeds as far as creating the object and
querying off the interface, but then fails on attempting to marshal the
interface.  This is because the COM architecture allows an object to
perform its own marshalling, and hence COM doesn't find out that it
can't marshal the interface until quite late on. Unfortunately the error
reporting doesn't make it clear that the problem is a lack of
marshalling information/code.


--
Wilhelm K. Schwab, Ph.D.
[hidden email]