|
The apartment is initialized for each thread once when you call CoInitInstance ( Ex). If you use COINIT_MULTITHREADED, you can pass around the interface ptr without any problems in any thread marked as MTA. Between threads with different apartments you must marshall the interface ( you can use CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream)
|
|
|
|
|
hello,
i try to create com objects which can be used by scripting clients and by c++ clients
very easily. this is no problem with the objects itself. but i have some trouble with
the events.
if i create the source interface as a standard interface based on idispatch the
wscript.exe crashes. if i look at the event proxy class generated by msvc, i see that
the methods on the interface are called directly, i think this will not work on script
clients. so i changed the interface to a dispinterface, now the generated proxy class
calls the method via invoke, scripting client works fine. but if i want to receive this
event in a simple c++ app the methods are not called directly, well, of course the
invoke method is called instead. so it is not so easy usable in c++. therefore i always
implement two source interfaces per object, on dispinterface as [default,source] for
script clients, and another iunknown based interface with the same methods as [source]
for c++ clients. this works fine, although it is more work to do. i do not know, if
there is a better way to support idispatch clients via invoke, and vtable clients directly
via the method calls? i thought maybe i can qi the interface connected to the cp, and
the idispatch connection will only return the idispatch interface, but it also returns
the event interface without error, but the method call fails.
second problem is that i do not get the automagic in wscript running. the event handler
is called the right way, but it is not executed. i always have to use the
WScript.ConnectObject obj, "obj_" method to connect to the events, then it is working
with vbscript. any idea why? do i need to support additional interfaces for the automagic
support? i added the IProvideClassInfo2Impl and IObjectWithSiteImpl to get the connect-
object method working.
and i have no idea how to use the events in a html-page with jscript. i do not get the
automagic working there, too, maybe the same problem. and attaching a function directly
to an event, like obj.event = myeventfunc, does not work, i always get the error, that
the object does not support the method or property. does it make any problems that the
event has parameters? the sample for onload, onclick do not have parameters. or is something
like the wscript.connectobject available for jscript and html?
well, that all for now, i hope someone could answer one or another? would be great.
many thanks in advance
enrico
|
|
|
|
|
I would like to offer the following decision.
[
oleautomation,
uuid(XXXXXXXX-XXXX-...),
helpstring("...")
]
interface ISomeEvents : IDispatch
{
[id(SomeDispid),helpstring("...")] HRESULT OnSomeEvent();
...
};
[
uuid(XXXXXXXX-XXXX-...), version(n.m), helpstring("...")
]
library SomeLib
{
...
[
uuid(XXXXXXXX-XXXX-...), helpstring("...")
]
coclass SomeCoClass
{
[default] interface ISome;
[default, source] interface ISomeEvents;
};
};
The sink of this interface can be implemented by ATL::IDispatchImpl instead of ATL::IDispEventImpl or ATL::IDispEventSimpleImpl.
With best wishes,
Vita
|
|
|
|
|
hello,
well, i tried this, but the result is almost the same. the msvc wizard creates a proxy class
with direct calls to the functions instead of the invoke, therefore the wscript crashes.
what i the idea of not using the dual? could you explain this? why use dual, why not?
enrico
|
|
|
|
|
I think that you should correct the Wizard to indirect call to the functions. Server must made a call only by Invoke. It's a script requirement.
But your C++ client can realize the sink more simply.
VB, VBS and all ole-automation clients will use the dispatch's Invoke.
But C++ clients can use ATL::IDispatchImpl class (with TLB inforamtion, but without BEGIN_SINK_MAP) instead of ATL::IDispEventImpl class (with manual BEGIN_SINK_MAP), which has also some bugs within it.
HTH
With best wishes,
Vita
|
|
|
|
|
oh, ok, i see, well this would be easier for c++ clients, you're right. thanks.
any idea how to get the automagic, the automatic assignment of events in a script
to the object_event methods working?
enrico
|
|
|
|
|
Can com post message to app? I own the COM and app.How to do this? Any function I can use?
|
|
|
|
|
Yes, it can - depends what you see under 'message'.
But in a general way - if it is interprocess COM he can use wide range of 'messages'.
First it is COM events - like ActiveX components also the COM library can fire events - this OnSomething functions.
It can also send the old plain window message (WM_USER ).
It can use the Win32 events - here the message is only 1 bit of info (evt set or not).
then its the whole range of IPC stuff (pipes, mailslots, sockets...).
Depends what you want to do and what you want to achieve.
|
|
|
|
|
Can you give me an example(source code)? many thanks.
|
|
|
|
|
Unfortunatelly, I do not have any source or example for sending message, but I think that this link will be useful - I check it quickly and I think it contains answer to all your questions with sending message
Message Management[^]
Hope this helps
|
|
|
|
|
Hello:
I have a basic problem. I create a COM server dll project. Then I create an ATL object (name: Test1). I select custom interface and I compile it. The server is registered OK, but when I launch the OleViewer I see that the Test1 object doesn't implement the ITest1 interface. Why?
Thanks in advance,
Jose.
|
|
|
|
|
1) Sometimes ( at least VC6 ) get's screwedup.... Find .tlb file and delete it...
2) Can you see your method/Interface when you view IDL????
Brian
|
|
|
|
|
I need my COM server to return an icon to my COM client. Can anyone suggest the best way of doing this?
I was thinking along the lines of my COM server loading a bitmap resource as (say) a CBitmap object. Then I could pass each byte (using the GetBitmapBits() function) in a SAFEARRAY to my client. My client could then build the bitmap locally (using the SetBitmapBits() function).
"The folly of man is that he dreams of what he can never achieve rather than dream of what he can."
"If you think education is expensive, try ignorance."
|
|
|
|
|
Another way is the looking at implementation of ATL :: CStockPropImpl :: put_Picture property.
Server old_Object -> quering IPersistXXXX interface -> making and fillng IStream object -> passing IStream to client -> loading client's new_Object from IStream.
I hope you are able to divide the CStockPropImpl code into server and client codes.
With best wishes,
Vita
|
|
|
|
|
Hi All,
I am working on a project(.dsp in Visual C++ 6.0) which
has multiple .idl files, many of these .idl files has
cross reference. Actually what I mean is, a function
inside file1's interface(interface_of_file1) takes a
parameter of file2's interface(interface_of_file2). Plus,
a function in interface_of_file2 takes parameter of
interface_of_file1. I hope you people got the idea that
both files need the other file to be compiled. In this
situation, if I import file2 in file1 and compile file1,
compiler tries to compile file2 first and gives error
that:
error MIDL2025 : syntax error : expecting a type
specification near "interface_of_file1" .
Now this is a kind of Dead Lock. I did Forward declaration
instead of importing the file(I do not exactly know the
method offorward declaration in MIDL). I did it in file1
like:
interface interface_of_file2;
Now this gives a different error and a warning:
==============================================
error MIDL2011 : unresolved type declaration :
interface_of_file2 [ Parameter 'parameter1' of
Procedure 'get_CashPeriod' (
Interface 'interface_of_file1' ) ]
warning MIDL2039 : interface does not conform to
[oleautomation] attribute : [ Parameter 'parameter1' of
Procedure 'get_CashPeriod' (
Interface 'interface_of_file1' ) ]
==============================================
Now please tell me, whether I'm doing forward declaration
wrongly? or can anyone suggest some other solution to this
problem?
I will be really thankful for any good answer.
Regards,
Ahsan
Ahsan
|
|
|
|
|
i think what you can do is to compile the first idl file using midl compiler and then include the generated files into the 2nd midl and then compile it..in this way hopefully u wont come across this problem again..
regards
safee
|
|
|
|
|
I am doing the same thing. What I do is that I right click the .idl file and compile only that file from there. Do you want me to specifically do it from command prompt? Btw, I have tried this as well But this gives the same problem.
What do you suggest now?
Ahsan
|
|
|
|
|
oh ok...i think then there is some problem in:
1. either the dependencies settings
2. the header files..
regards
|
|
|
|
|
hi there...
first of all ..thanks for ur time..
i wanted to know if you have any idea about MsOCF or any Place where i can find some information on the MsOCF Framework..or any help on how to map it to the now used OLE 2.0...
thanks..
|
|
|
|
|
If MsOCF maps to MS OLE CF, then this library is part of OLE and implements the compound document model (IStream/IStorage interfaces).
|
|
|
|
|
good to hear from you Rod..and after readin your profile i think you are the guy after all whom i can talk with about reverse engineering and stuff...
for the last one year i have been doing reverse engineering.
the project which i have got is an old but decent sized spread sheet..
the thing is it was built in 1995..with MSOCF framework(i dont know what it means.. completely) but that it was used before OLE 1 came to being..
so the thing is that once i have opened the code now the problem is of mapping the old framework to the new OLE2 and MFC..
there are many classes which are merged now and many methods which are no longer there..
please advise me how do i proceed with this strange problem?
i mean there is no reference material that i may refer to interms of MSOCF..and no mapping from it to the new OLE2..
please suggest something..
thanks
safee
|
|
|
|
|
safeeullah wrote:
MSOCF framework(i dont know what it means.. completely)
MS Ole Compound Framework. Again, it's a unit library which implements stream/storage, the basic elements of a compound document.
You can find equivalent implementations for this library in several places including :
- OpenOffice (that was required to read Word/Excel/... files)
- WINE32 (winehq)
- some simple implementations on the net
safeeullah wrote:
i mean there is no reference material that i may refer to interms of MSOCF..and no mapping from it to the new OLE2..
There is but you have to dig old MSDN papers (prior 1997). I believe that books like Inside OLE should provide good support for it.
Or may be an MS pal which advertedly would read this thread could forward you a couple white papers.
Large software companies that require extensive stream/storage support usually buy the code library from Microsoft. So in practice, this is not an issue.
|
|
|
|
|
thanks for the reply rod..
do u mean the book inside OLE by brockshmidt?
but it contains hardly anything that relates to any thing this prehistoric
the thing is if u can help me in locating some of the white papers that MS may have published at the time when they were abandoning msocf and moving on to atl and stuff..that would be most instrumental..
please rod, do look into this as it is something very important..
Peace!
regards
safee
|
|
|
|
|
thanks for the reply rod..
do u mean the book inside OLE by brockshmidt?
but it contains hardly anything that relates to any thing this prehistoric
the thing is if u can help me in locating some of the white papers that MS may have published at the time when they were abandoning msocf and moving on to atl and stuff..that would be most instrumental..
please rod, do look into this as it is something very important..
Peace!
regards
safee
|
|
|
|
|
What about ordering old MSDN CDs? That's what I would do.
|
|
|
|