|
Heh... it's a deep well, Earl. Where would you like to start? I'll help where I can. I would say I'm intermediate developer now with activeX, but there is a huge conceptual hill you have to climb. When all of a sudden you say, "Wow!", you're at the top of the hill.
How's your VC++?
Charlie Gilley
Will program for food...
|
|
|
|
|
Hi Charlie. Thanks for your response. At this stage I'm trying to understand if my approach makes sense. e.g. to use ActiveX. If it is, then the next step is for me to understand what I need to do in order to have an ActiveX "thing" that allows my JS/HTML to call into it for purpose of reading and writing files. My VC++? .... I've been around for a while so fairly confident ... that said, I don't know where to start. Any advice?
|
|
|
|
|
Hi,
I'm writing a ATL COM Service (with the wizard on VC2003).
it look like that :
// IDeviceManager
[
object,
uuid("D9D097B1-FBE8-43D8-AEC6-6C740D01E911"),
dual,
helpstring("IDeviceManager Interface"),
pointer_default(unique)
]
__interface IDeviceManager : IDispatch
{
// Device manager.
[id(1), helpstring("method EnumDeviceDriver")] HRESULT EnumDeviceDriver([out,retval] LONG * pDeviceDriverCount);
....
}
// _IDeviceManagerEvents
[
dispinterface,
uuid("55370094-D0DE-438C-8D0A-E907A884F50B"),
helpstring("_IDeviceManagerEvents Interface")
]
__interface _IDeviceManagerEvents
{
[id(1), helpstring("method OnFireDeviceEvent")] HRESULT OnFireDeviceEvent ( [in] ULONG iDevice, [in] BSTR Param1, [in] BSTR Param2, [in] BSTR Param3, [in] BSTR Param4, [in] BSTR Param5, [in] BSTR Param6, [in] BSTR Param7, [in] BSTR Param8, [in] BSTR Param9 ) ;
};
// CDeviceManager
[
coclass,
threading("apartment"),
event_source("com"),
vi_progid("Manager.DeviceManager"),
progid("Manager.DeviceManager.1"),
version(1.0),
uuid("5CCB5A39-BF78-40A4-89E4-D0DBE82D8B7D"),
default(IDeviceManager),
helpstring("DeviceManager Class")
]
class ATL_NO_VTABLE CDeviceManager :
public IObjectWithSiteImpl<cdevicemanager>,
public IDeviceManager
{
public:
CDeviceManager ();
__event __interface _IDeviceManagerEvents;
DECLARE_PROTECT_FINAL_CONSTRUCT()
...
}
When i fire an event in EnumDeviceDriver it work.
The CDeviceManager container a thread that try to fire event but it failed with RPC_E_WRONG_THREAD(0x8001010EL).
I see a lot of article that say i need to modify advice and unadvice but with the Wizard i don't found how do it...
A link to expert exchange that explain a solution but not with the vc2003 wizard generated code: http://209.85.129.104/search?q=cache:HcncZHwaAUoJ:www.experts-exchange.com/Programming/Languages/CPP/Q_20528104.html+queryinterface+IDispatch+0x8001010E&hl=fr&ct=clnk&cd=1&gl=fr
If someone can explain me how do it with my code ?
Thanks
-- modified at 5:52 Thursday 8th November, 2007
...
|
|
|
|
|
The main thing here is that you're using an interface from another apartment than it was created in.
When you're crossing apartment boundaries you have to marshal the interface.
When it comes to firing events I've found Michael Lindig's solution to satisfy my needs; check it out here[^].
If you want to know more about marshalling and multithreaded COM you should read Lim Bio Liong's article series starting here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi,
Thanks for the answer but i already see this article, the problem is how integrated it to my code, i understand the problem, and i have a lot of solution but i can found have integrated it
I try a lot of things like this (remove wizard event and implement it manually => It crash, like the sample of Michael Lindig's.
If you have a small working sample (client\server) i will be happy... Multithread event is very hard for me, i found how do it in single thread on 10 minutes... And for multithread, i search from 4 days...
My last try that crash on start…
// CDeviceManager
[
coclass,
threading("apartment"),
//event_source("com"),
vi_progid("Essilor.Manager.DeviceManager"),
progid("Essilor.Manager.DeviceManager.1"),
version(1.0),
uuid("5CCB5A39-BF78-40A4-89E4-D0DBE82D8B7D"),
default(IDeviceManager),
helpstring("Essilor DeviceManager Class")
]
class ATL_NO_VTABLE CDeviceManager :
public IObjectWithSiteImpl<<cdevicemanager>>
, public IDeviceManager
, public IConnectionPointImpl<<cdevicemanager, &__uuidof(_idevicemanagerevents),="" ccomdynamicunkarray_git="">>
{
public:
CDeviceManager ();
//__event __interface _IDeviceManagerEvents;
...
Thanks for your help.
Arnaud
...
|
|
|
|
|
achainard wrote: Multithread event is very hard for me
Well, nobody said it would be a walk in the park.
That's why I suggested that you read up on the subject in Lim Bio Liong's article series to get a basic understanding.
achainard wrote: i found how do it in single thread on 10 minutes...
Of course you can post a message to the main thread of the server and fire the event from there.
achainard wrote: My last try that crash on start…
So, why does it "crash"? Look in the call stack for clues.
BTW, you are aware that Michael's implementation is in C++, right?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
It's definitively a good day...
I found : use CoMarshalThreadInterfaceInStream and CoGetInterfaceAndReleaseStream...
Thanks for your help,
Arnaud
...
|
|
|
|
|
In c++ I could overload the class which implements the calls to the COM / Active X object I used and add additionally member functions in the overloaded class.
How do that in c# with NET ? The "object" I get is only an interface with a CoClass. Deriving from the interface without implementation of all functions of the CoClass is not possible ... I dont have any dispatch pointer etc...
The member function should access a static Hashtable which returns some values.
Any Idea ?
|
|
|
|
|
FriendOfAsherah wrote: In c++ I could overload the class which implements the calls to the COM / Active X object I used and add additionally member functions in the overloaded class.
How do that in c# with NET ? The "object" I get is only an interface with a CoClass. Deriving from the interface without implementation of all functions of the CoClass is not possible ... I dont have any dispatch pointer etc...
The member function should access a static Hashtable which returns some values.
Any Idea ?
In C#, I think you're reduced to writing a class that contains the COM object. Your class could implement the interface by just passing the calls on to the contained object, but it's still a lot more work than you'd need in C++.
Nathan
|
|
|
|
|
Yes, but away from defining about 40 properties,functions get/set I dont know how to write them becouse:
The Interface class shows only the definitions like:
[DispId(0)]
string _Name { get; set; }
The CoClass similar like:
[DispId(0)]
public virtual string _Name { get; set; }
Which code to write into the class which inherits from the Interface ???
public class CMyClass : ICOMClass
{
public virtual string _Name { get { ??? }; set{ ??? }; }
....
I cannot leave the get/set empty but I dont have any parameters
Or how can I put something like a DispatchId and a dispatch pointer there ??

|
|
|
|
|
FriendOfAsherah wrote: Yes, but away from defining about 40 properties,functions get/set I dont know how to write them becouse:
The Interface class shows only the definitions like:
[DispId(0)]
string _Name { get; set; }
The CoClass similar like:
[DispId(0)]
public virtual string _Name { get; set; }
Which code to write into the class which inherits from the Interface ???
public class CMyClass : ICOMClass
{
public virtual string _Name { get { ??? }; set{ ??? }; }
....
I cannot leave the get/set empty but I dont have any parameters
Or how can I put something like a DispatchId and a dispatch pointer there ??
My guess is it would be:
public class CMyClass : IComClass
{
private IComClass m_Inner;
public virtual string _Name
{
get {return m_Inner._Name;}
set{m_Inner._Name = value}
}
...
and the constructor would set m_Inner to a new instance of ComClass, or use one provided to it.
Nathan
|
|
|
|
|
How easy ... by containment ...
This works !!
I spend hours trying to use typecasting and calling base.Function() and base.Property=...
This is the COM Interface I have:
[CoClass CCOMClass]<br />
...<br />
public interface ICOMOuter : ICOMInner<br />
{
}<br />
<br />
public interface ICOMInner<br />
{<br />
[DispId1]<br />
public string Property1 { get; set; }<br />
... etc.<br />
}<br />
And I tried derive, inherit with:
public class MyClass : ICOMOuter<br />
{ ....<br />
}<br />
And
public class MyClass : ICOMOuter , ICOMInner<br />
{ ...<br />
}<br />
both never compiled ....
Dont know why until now
Thanks a lot :-Dfor the idea !
|
|
|
|
|
Creating a COM dll -module that fires events is simple enough (ATL -project -> add ATL simple object with Connection point -support -> Add a couple methods etc.), but:
What flags are needed for multiple instances to catch the same event when it is fired? I.e. when I CoCreateInstanceEx a connection to module from let's say 2 separate exe's, both can receive the same event. Tried quite a few combinations so far and yet no success.
|
|
|
|
|
You need another Class Factory. Use the DECLARE_CLASSFACTORY_SINGLETON macro. In this case all COM-clients get the same instance. In this case your COM-Object must be threadsafe !
Greetings
|
|
|
|
|
Even with singleton COM objects if it is an in-process component then you'd still get separate notifications from multiple EXE clients. You would either have to make the component out-process or CoCreateInstance it from one EXE and load it up into the Running Object Table (ROT) using RegisterActiveObject and grab a reference to it from the second EXE using GetActiveObject .
|
|
|
|
|
That did the trick. Thanks a lot!
|
|
|
|
|
Quesiton:
i encounter the trouble when i invoke execmthod.(wmi)
the return error is WBEM_E_INVALID_METHOD_PARAMETERS.
I have a specail situation than standard one.
that is the method's input parameter is also an wmi class.(it is defined by my bios)
therefore, when i invoke getmethod() to get input param object, I can't direct put data into property by put() method.
(because the property is defined inside the wmi class)
so i invoke the getobject to get the new input param object.
And i put the data into the property.
Final, i use the new input param object for the execmethod's input param.
And the error appears.
Who can help me to sovle such problem?
thanks
|
|
|
|
|
What is TLB file? What Regtlib does? Does it create any specific kind of structure in the Registry under HKEY_CLASS_ROOT while registring the TLB file?
Ajay kumar, Sr System Analyst
Satyam Computers, Banglore
India
ajay.kumar.ind@gmail.com
|
|
|
|
|
TLB[^]
From MSDN -
RegTLib is used for .tlb registration for stdole2.tlb. Regtlib.exe calls the LoadTypeLib and RegisterTypeLib application program interfaces (APIs) on the type library (.tlb or .olb) file that is passed in.
hiajay wrote: Does it create any specific kind of structure in the Registry under HKEY_CLASS_ROOT while registring the TLB file?
Yes, TLB registration is done under HKEY_CLASSES_ROOT\TypeLib.
FYI, if you are working with COM Interop in .NET, then you may want to look at
tlbimp.exe[^]
tlbexp.exe[^]
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
What about C++ based TLB.What are the subkey created inside HKEY_CLASSES_ROOT\TypeLib
Thanks
Ajay
|
|
|
|
|
hiajay wrote: C++ based TLB
TypeLibrary is independent of C++
I would suggest going through the following link to understand TypeLibrary
http://msdn2.microsoft.com/en-us/library/aa366757.aspx[^]
Also, reading "Essential COM" or "Inside COM" book will be helpful.
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hello
What are the best resources / books to start learning COM?
Thanx
|
|
|
|
|
There are a lot of good articles here at CP.
go into All Topics, MFC/C++ >> COM/DCOM/COM+ section, check out, for instance the beginners articles.
There are, of course, a pletora of good books about COM. A nice one is Don Box's Essential COM [^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I can advise the Microsoft author "Beck Zaratian"... Book names is "Programmer's Guide". I can sale mine? if you want?
What is this¿
|
|
|
|
|
And so you suggest a title you're selling out?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|