Hello Guest it is March 28, 2024, 03:33:39 PM

Author Topic: Com Interface Questions  (Read 5093 times)

0 Members and 1 Guest are viewing this topic.

Com Interface Questions
« on: February 17, 2009, 04:49:43 PM »
I am experiencing some difficulties using the  com interfaces:
        mach:=TCMach4Doc.create(self);
        mach.ConnectKind:=ckRunningInstance;
        mach.Connect;
        iMach:=mach.GetScriptDispatch as iMyScriptObject;

It instantiates and connects to a running instance fine.  I am able to utilize all of the functions and procedures of the scriptObject.
If however I try to disconnect and then reconnect, Mach fails and closes.  If I set my mach variable to nil, mach fails and closes.  If I close my app, Mach fails and closes. 

If I use a connectKind of ckNewInstance I get a dialog box with several unknown profiles.  I can create a profile but then I get an invalid license prompt, followed by a user agreement dialog and then several failed dll calls.

How robust are the interfaces? 
Has reference counting been implemented for each new interface?
Am I using these incorrectly?

TIA

RT

PS.  I have written several com applications and am able to utilize com interfaces with many other applications like M$ excel,word, powerpoint. 
Re: Com Interface Questions
« Reply #1 on: February 18, 2009, 12:09:32 PM »
Hi,

Why do you need to attach and detach from the Object Model during a single session?  Anyways, I believe there are some reference counting issues, I DO NOT Release() any interfaces at shutdown time since it appears that the Scripter has already gone away at that point...

See the Mach3ObjectModel.cpp and .h files in the Custom Plugin posted in reply #41 in my tutorial thread.

http://www.machsupport.com/forum/index.php/topic,4884.0.html - reply #41

-James

Re: Com Interface Questions
« Reply #2 on: February 18, 2009, 01:23:11 PM »
Good day Jim,

Thanks for taking time to respond.  As to why would I want to connect and disconnect in single session, I use my DIY beveller in several modes.  As such I write modules that are designed to perform specific tasks ( woodworking tasks like mortise and tenons, box joints, dado's and rabbits.  Bamboo rodmaking tasks like mortising reel seats, sawing strips, flaming culms, and of course bevelling individual strips.).  Mostly they generate the gcode automatically but I have conceived of several other uses and have modules to perform those tasks.  Having to restart Mach each time I want to utilize one of these is a PITA.  I could write one master app that does it all but you know how much harder that is to maintain.  I guess I could write one that calls dlls for each task and reuses the scripting object but it just would be nice if the com objects would play nice and allow for connecting and disconnecting like you would expect. 

Every time I try to do something out of the ordinary I get stymied.  I would like to write some new screens but screen4 won't work on the vista64 bit machine that I use for development.  Jason's controls are at this time are still limited.  My attempts at creating Dll's accessed by VB scripts is fallling short since I can't seem to get access to the main Mach hWnd to allow for new forms/windows.

After 20 years of programming in object pascal I am loathe to pay for another development environment and relearn C++ just for this when I have access to the interface.  Even then I don't think you can change plugins on the fly easily (maybe I am missing something here).

Sorry for the rant but it's just one of those days. 

RT

PS I have looked at your examples many times and you are to be lauded or your work.  I have SDK 2.62 which I think is the last version.  My type library generated from mach matches you scriptObject.
Re: Com Interface Questions
« Reply #3 on: February 18, 2009, 01:43:13 PM »
Hi,

Ok, then you are connecting an EXE in Delphi out-of-process.  I have zero experience with that.  If you look at the same source code you will see how to get the Mach3 main window HWND using FindWindow.  The trick is the window caption has a trailing space character that is not visible.  If you include that FindWindow work just fine.

Why not write a plugin using the techniques I show, then export C linkage functions that you can call from your other applications?  That way you have a single instance of the scripter that you can reuse in multiple external EXE applications.

-James
« Last Edit: February 18, 2009, 01:45:42 PM by jemmyell »