|
JoeRip wrote: Turns out that my event handlers for the COM object were not executing on the same thread as my form, and I was getting odd UI behavior as a result.
Awooga! Awooga!
Sorry, that's the sound of the alarm going off in my head.
Something's not right with your apartment setup. If you have forms, the thread that creates them should be marked with the [STAThread] attribute. This ensures that COM events are fired on the correct thread - it tells COM that this thread uses the apartment-threaded model (CoInitializeEx is called with the COINIT_APARTMENTTHREADED flag). Objects created by this thread have their calls sent back to this thread, regardless of which thread those calls were made from (if the object is implemented correctly).
The object is also marked for a given threading model - this is done in the registry for objects implemented as in-process servers (in DLLs). Normally automation objects are also marked apartment-threaded - this means that whichever thread you make a call to them on, COM will marshal the call to the thread you created the object on. However, COM can only do its stuff if you correctly marshal interface pointers between threads - if you just pass raw interface pointers around you can end up calling an object incorrectly on the wrong thread when it's not expecting it, causing unexpected race conditions or other thread-model violations. This is a particular problem if an event has to be raised by a worker thread.
This shouldn't happen if you're using an out-of-process object though, since those calls always need to be marshalled, which leads me to think that your UI thread isn't marked [STAThread] .
|
|
|
|
|
Ah, but it is. I'm using the standard VS .NET Windows Application template. Here's my main:
namespace Eye_On_iTunes<br />
{<br />
static class Program<br />
{<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
Application.Run(new frmEye_On_iTunes());<br />
}<br />
}<br />
}
and all of my code is running in the form class frmEye_On_itunes(). Note the thread model.
To get the iTunesApp object, I simply:
itunesapp = new iTunesLib.iTunesApp();
and to create event handlers for the iTunes events I simply
itunesapp.OnDatabaseChangedEvent += new _IiTunesEvents_OnDatabaseChangedEventEventHandler(itunes_OnDatabaseChangedEvent);
where itunes_OnDatabaseChangedEvent is a handler in the form class.
So I also assumed the event handler thread would be the form thread, and that it would be safe. However, apparently it wasn't.
I added a check to InvokeRequired, and re-routed the message back through with a delegate, like this:
private void itunes_OnDatabaseChangedEvent(object deletedObjectIDs, object changedObjectIDs)<br />
{<br />
if (InvokeRequired)<br />
{<br />
Invoke(new iTunesLib._IiTunesEvents_OnDatabaseChangedEventEventHandler(itunes_OnDatabaseChangedEvent), new object[] { deletedObjectIDs , changedObjectIDs});<br />
}<br />
else<br />
{<br />
}<br />
}
and all problems went away. So .NET says that InvokeRequired is true when this event fires for the COM object itunesapp, apparently.
|
|
|
|
|
Hi,
I am trying to hook into this HTMLWindow event.
Here is what I am doing :
In MyHandler class :
COM_INTERFACE_ENTRY_IID(DIID_HTMLWindowEvents2, IDispatch)
virtual HRESULT __stdcall onunload(IHTMLEventObj* pEvtObj) { ... }
STDMETHODIMP DocumentComplete(IDispatch *disp,
VARIANT *url) {
....
HRESULT hr = S_OK;
LPDISPATCH doc_disp = NULL;
CComQIPtr<ihtmldocument2> doc;
hr = browser->get_Document(&doc_disp);
doc = doc_disp;
....
SomeOtherFunc1(doc);
}
void SomeOtherFunc1(IHTMLDocument2* doc) {
CComQIPtr<ihtmlwindow2> wnd;
hr = doc->get_parentWindow(&wnd);
SomeOtherFunc 2(wnd);
}
void SomeOtherFunc 2(IHTMLWindow2* wnd) {
AtlAdvise( wnd, (IDispatch*)this,
DIID_HTMLWindowEvents2, &cookie);
}
The handler class is already hooking into DWebBrowserEvents2 and all the handlers get called (DocumentComplete among them).
And I added similar code for the HTMLWindowEvents2.
AtlAdvise returns S_OK and inside it finds the CPC and the CP and Advise returns success and a valid cookie.
But onunload is not called when I navigate away from a page.
The module is a BHO dll loaded by IE.
I believe the HTMLWindowEvents2 interface is dual so I should be able to use VTBL events, right ?
Am I missing something here ?
--
Thank you!
|
|
|
|
|
i made a program with matlab gui(guide user interface).
it works so right. i have two file first with *.fig extention
second with *.m extention
my problem is how to make my program a standlone application (with *.exe extention)..
how to convert fig file to exe file in matlab??
thanks..
uLTraSLan-uNi
|
|
|
|
|
Hi,
I'm writing a COM interop interface in C# (VS2005) to be used in VC++, and got into problem of proper exporting enum-s in such interface.
When i previously used C++ for writing COM interfaces, i would just declare the enum within IDL file, and then within the library section also declare it, that way way making my enum accessible when TLB file is imported using #import in C++;
Now in C# if i declare: public enum MyEnymType {val1, val2,...}, then such object when imported into C++ project is declared as: enum MyEnymType {MyEnymType_val1, MyEnymType_val2,...} instead of enum MyEnymType {val1, val2,...}
Is there a way to make C# embed my enum type into the object in such a way that it exports original enum declaration during import instead of such an ugly Type_Value thing?
Thank you,
Vitaly
Free C++ libraries with source code on www.neatcpp.com: TWAIN, DirectShow, Interprocess Communications, etc...
|
|
|
|
|
Please don't cross post.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
My question is on C# and COM at the same time - which is the right place to post then, if not in both C# and COM forums?....
Free C++ libraries with source code on www.neatcpp.com: TWAIN, DirectShow, Interprocess Communications, etc...
|
|
|
|
|
It is normal to post them on one forum. Pick the one that you think is most appropriate and then post it there. In this case, it is more relevant to the C# forum because that is where you want to override the enum.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Sir,
I have a third party component, which has displaying graphical chart functionality. This chart functionality is implemented as a part of coClass and an interface is provided to user. Using this interface i need to access the methods and properties of component. Could you throw some light on how to attach this component class to ole containers document window at runtime.
I have used coCreateInstance to create the class, but i want to know how can i attach this class to CWnd(window) class at runtime. so that i can get chart displayed at runtime in document window.
Thanks in advance.
Regards,
Praveen A.
praveena@navayuga.co.in
|
|
|
|
|
Probably you need to use OleCreate if I am understanding you correctly. For OleCreate you need to have an OleDocumentContainer in which you will host the control.
Look at the help of OleCreate in MSDN and tell me if you get any problem.
"Some people believe football is a matter of life and death.
I'm very disappointed with that attitude.
I can assure you it is much, much more important than that. -- Bill Shankly"
|
|
|
|
|
hello
i want to send data with com port of
a computer to another one
do you can help me with it?
thank
|
|
|
|
|
(1) The HARD side: You need a RS232 Null-modem or cross over cable.
(2) The SOFT side: It depends on the software env you're using.
(e.g. you can use Windows API such as ReadFile or the COM control MsComm ).
Hope that helps.
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.
|
|
|
|
|
if u know any thing about com port programing help me please.
thanks for your help
|
|
|
|
|
It depends on the language (and libraries) you intend to use.
I wrote:
(1) VB6 applications using MsComm control.
(2) C++ ones using the Win32 API (CreateFile(), ReadFile(), WriteFile() .
the (1) are fairly simpler, 'cause the (2) are much more low level (and usually you've to deal with threads.
Of course you can also use MsComm control in C++ applications (for instance using MFC). Though I've never done it.
AFAIK the .NET framework provides (so Visual Basic.NET, C#, ...) a SerialPort component that can make communication stuff as easy as MsComm do for VB6 (I never made an attempt). There is also a Microsoft example [^].
hope that helps.
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.
|
|
|
|
|
My DLL is a normal API without any COM interface i can't use regsrv32 to register my DLL.
How to design a C# COM+ object to wrap my DLL and how to include my DLL using implicit or explicit method.
If have example hope you will post the link thanks.
Regards Stellvia
|
|
|
|
|
Do you really neeed that (you can also use directly your DLL)?
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.
|
|
|
|
|
stellvia wrote: i can't use regsrv32 to register my DLL
A DLL is self registering (ie. by calling its DLLRegisterServer known function, in your case regsvr32.exe call this function) when it is a COM server.
stellvia wrote: How to design a C# COM+ object to wrap my DLL
You can use native DLLs from .NET using P/Invoke. Following MSDN article may be of help -
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/[^]
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi All,
I have made an IE Toolbar , using VC++ and ATL . Every thing works fine. But I am always getting my tool bar in the right corner . I need it to be shown in the Center , How can I achieve this Programmatically .
Thanks
George
|
|
|
|
|
Dear friends,
Can I use any alternate for DSO Framer control to display document, excel, ppt, pdf etc files. I tried aspose too, but it was
not meeting our requirements. Because they want a tool which takes the documents as it is like DSO Framer. In aspose to
change the document format we need to change the code also.
And I need to email this document too. So that document may be changed so frequently. And dont forget that document must have
to be made using .Net frame work library(com component is not preferable). What shoud I use in this case. Please help me.
Thank you.
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
Hi all,
I have already made a toolbar for IE, Now my requirement is to make a toolbar
for Mozilla also .But I am not finding any sample source code or help for
that.So how can I make a toolbar for mozilla. Please Help me.
Thanks in Advance
George
|
|
|
|
|
|
Hi Sohail,
Thank you for ur valid information. Actually I have made an IE toolbar using
vc++ ATL COM. It cotains Threads, And many things that mfc supports.
For example,
It consists of a Ticker that shows some information from a server. The ticker
is
actually a class inherited from CStatic. And also Threads in VC++ , that
performs various functionalities like, Collecting data from Server. Showing
Advertisements live , from different sites etc. So I think, I cant perform
these things in Mozilla tool bar made from XML. Right na.
Thanks
George
|
|
|
|
|
well you can certainly do in Mozilla what you have so far created in IE.
From what you said, I beleive your UI logic and Business logic are clubbed together and created only for IE.
If you seperate out the UI logic of toolbar in your IE and put the business logic in a seperate COM dll which is callable from the UI logic then you can invoke the same business logic from within Mozilla toolbar. The UI logic of toolbar is written in XML but there is a way to call COM interface methods. Mozilla also has something called XPCom - COM variant.
I hope this helps
-- modified at 5:59 Tuesday 2nd January, 2007
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi All,
How can i Import the MODI.dll into my visual c++ 2005 project. If you have any articles or sample codes please let me know immediately....
MODI:
Microsoft Office Document Imaging Library
Thankx in advance...
|
|
|
|
|
Dear All,
How to register a COM exe in a different system ?
Thanks.
|
|
|
|