|
How to handle COM Events in Java script
How to use ATL COM in java script and handle COM event in java script
if the ATL COM is developed in C++
Abhiraj
modified on Tuesday, April 29, 2008 2:43 AM
|
|
|
|
|
|
Hi Steve
You took the question wrong ...
The question is how to handle events in Java script which are fired from ATL COM
I am able to call COM interface methods in java scripts but not able to handle events fired from the same ATL COM Component
and not "call java script functions in C++"
with regards
Abhiraj
|
|
|
|
|
You haven't explained properly. How is the ATL COM object hosted? If it's hosted on the page you can simply handle it like any other event in HTML. It it's not on the page you would sink the events with an interface implemented in C/C++ and the methods would delegate to the web page as described in my previous post.
Steve
|
|
|
|
|
Hi Steve
I would like to change my question...
How to use ATL COM in java script and handle COM event in java script
if the ATL COM is developed in C++
Abhiraj
|
|
|
|
|
Firstly, I’ll assume you’re embedding a COM object in a HTML page (you haven’t explicitly stated this). Here’s what my page looks like:
<html>
<head>
<title>CallMe</title>
</head>
<body>
<object id="my_obj" classid="clsid:7815559F-240E-406E-A0F0-974B7272C65F">
</object>
<script type="text/javascript" for="my_obj" event="Hello">
window.alert("Hello!");
</script>
<input type="button" value="Call into COM object" onclick="my_obj.CallMe();" />
</body>
</html>
Note that I used MSVC6, but other versions will have equivalent functionality.
You’ll have to use connection points to implement an outgoing interface. Here’s the IDL of my project:
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(4E413D85-21DC-48FC-AD65-B8635B74CBFF),
dual,
helpstring("IHostMeObj Interface"),
pointer_default(unique)
]
interface IHostMeObj : IDispatch
{
[id(1), helpstring("method CallMe")] HRESULT CallMe();
};
[
uuid(9598F3A4-B8DE-4BA8-9AE1-90903ED9EF38),
version(1.0),
helpstring("HostMe 1.0 Type Library")
]
library HOSTMELib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(5C211D24-97D2-4AA1-AB93-EE605DC97614),
helpstring("_IHostMeObjEvents Interface")
]
dispinterface _IHostMeObjEvents
{
properties:
methods:
[id(1), helpstring("method Hello")] void Hello();
};
[
uuid(7815559F-240E-406E-A0F0-974B7272C65F),
helpstring("HostMeObj Class")
]
coclass HostMeObj
{
[default] interface IHostMeObj;
[default, source] dispinterface _IHostMeObjEvents;
};
};
It’s also important to implement the IProvideClassInfo and IProvideClassInfo2 interfaces or the callbacks will not work.
The following articles (on the Wayback Machine, as the originals seem to have been deleted) may help:
http://web.archive.org/web/20060915111734/http://msdn.microsoft.com/archive/en-us/dnarguion/html/drgui082399.asp[^]
http://web.archive.org/web/20060921072123/http://msdn.microsoft.com/archive/en-us/dnarguion/html/drgui102599.asp[^]
Steve
|
|
|
|
|
Hi Steve
I have implemented the IProvideClassInfo and IProvideClassInfo2 interfaces for the callbacks and the callback are working fine
Now the issue is even if I fire Event from ATL COM once , its shown more than once on the web page as if i have fired event from ATL COM many times and everytime the count is getting increased ....
I have used this ATL Component in VB also , in VB its working fine if event is fired once the event is shown once and not more than that...
Here is the code snippet
......
MessageBox(NULL,TEXT("Fire Event Reached"),TEXT("OK"),MB_OK);
hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL);
MessageBox(NULL,TEXT("Fire Event Complete"),TEXT("OK"),MB_OK);
.........
I have used two message boxes just for the sake for debugging...
Now in VB whenever there is event i have shown a msg box so once event is fired only 3 messages boxes comes one after the other
1. Fired Event Reached
2. Event Message Box (When "pConnection->Invoke" is fired)
3. Fire Event Complete
Now in Internet Explorer its different.. whenever event is fired by ATL COM
Event Message Box is shown many times in the Internet Explorer and everytime the count is getting increased
What can be the problem...
with regards
Abhiraj
|
|
|
|
|
Why are you firing the event manually using IDispatch::Invoke . The ATL wizard generates that code for you when you select the “Implement Connection Point…” option in the IDE.
Steve
|
|
|
|
|
I am not firing the event manually.. i am using the code generated by the ATL Wizard as such..
For firing event from worker thread .... microsoft has given link to be implemented for the same thats the only change i have done and rest of the code i have not touched...
with regards
Abhiraj
modified on Wednesday, May 7, 2008 12:27 AM
|
|
|
|
|
Hi all!
I would like to serialize/deserialize a std::vector of objects of a class into some buffer of a stream or of some other buffer. Can you address me about how to do this with the highest performance possible?
If I had an ARRAY of these instances..I would switch to a std::vector using this code:
CMyClass d[20];
// fill the array!
std::vector<CMyClass> v(d,d+sizof(d)/(d[0]));
What in case I use deserialization from a stream?
Is there a way to let the std::vector copy or use itself access the buffer
of a stream?
I would like to avoid the istream::read line below to go faster..do you know some way or address some nice super STL feature?
CMyClass d[20]; // buffer is created continuosly
istream::read( d, 20 ); // copy data from the buffer ( IS AVOIDABLE? )
std::vector<CMyClass> v( d,d+sizof(d)/(d[0])); // get the std::vector
Kind Regards
ManuStone
|
|
|
|
|
Assuming CMyClass has a std::istream extractor, you could use this to read from a file called "a.a"
std::ifstream is("a.a");
std::vector<CMyClass> v;
std::copy(std::istream_iterator<CMyClass>(is), std::istream_iterator<CMyClass>(), std::back_inserter(v));
|
|
|
|
|
Thank you Stuart
I will test it immediately!
Actually what I would like to achieve is to directly move an entire block of data from the stream to vector someway!
I have doubt that std::copy probably might be slow, but I have to test it before saying that
Have a nice evening!
ManuStone
|
|
|
|
|
I am working on a button that has a custom shape, and I wanted to give the user the option to match the button color scheme used by XP. I was planning to fill the button region with a gradient matching the current XP theme.
I asked this question on the Yahoo WTL forum. The answer makes writing a custom shaped button a little more difficult.
I am trying to use theme colors in XP to draw a gradient background
that is not rectangular. I am utilizing atltheme.h to call
GetThemeColor(BP_PUSHBUTTON, PBS_HOT, TMT_GRADIENTCOLOR1, &c). I am
trying to retrieve just one gradient color at the moment. I've tried
using DrawThemeBackground for a button. The colors are correct, but
the shape cannot be changed to fit the region I am filling.
I've discovered that most theme parts do not return gradient colors.
(I am able to get some colors, just not the gradient colors.) Does
anyone know how to retrieve the gradient colors used to draw themed
buttons? Most of the examples I have found hard code the gradient
colors to look like the theme colors.
The answer I received:
Themed buttons are actually drawn using a template bitmap, so there are no
gradient colours to retrieve.
Is this documented some place? I searched using google and I've had no luck locating any references to bitmap templates used for buttons.
|
|
|
|
|
Jim Barry answered all of my questions on Yahoo WTL[^]. Many thanks to him.
Short answer: Oh yes, totally undocumented.
Jim's answer also made it clear to me why custom shapes are difficult to theme if you want to use the "Button" theme.
I am most grateful for Jim's quick and accurate answers.
|
|
|
|
|
Hello friends,
How can I use the VB.NET's library in VC++.
Any article that will give the clear idean on this problem.
Thanks in advance to all of you.
ritz1234
|
|
|
|
|
You could either try using COM interop[^], or you could check out how to use the /clr switch[^] with the C++ compiler.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
I developed a desktop application with WTL, which contains a toolbar. The tool bar was ceated like as following codes. It works well. But when I tried to modify the style of the toolbar and make it to be docable or vertical. I failed in all attempts. I wonder why it becaoms so difficult with WTL while it's very easy with MFC to modofy a toolbar from horozontal to vertical dynamically. I tried to look for useful sample codes from internet. But, failed to find any matching samples. I believe it's a simplist requirement for a toolbar to be docable or to present in vertical direction. There must be many developers who ever encountered the same confusion as me. Then how do they resolve thire problems?
Can anyone provide me some hints or contribute some of his samplke codes. I'll apprieciate so much. I attahched my sample. Can anyone help me to modify the toolbar into vertical or docable one? Thanks a lot in advance.
BOOL CreateToolBarCtlr(HWND hParent, CToolBarCtrl& toolBarCtrl, RECT rcBar, LPCTSTR lpszCaption) { ATLASSERT( hParent && lpszCaption); if(hParent == NULL || lpszCaption == NULL) return FALSE; <br />
ATLASSERT(toolBarCtrl.m_hWnd == NULL); <br />
if( toolBarCtrl.m_hWnd != NULL) return FALSE; <br />
DWORD dwStyle = CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE;<br />
dwStyle |= TBSTYLE_TRANSPARENT | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS |<br />
TBSTYLE_CUSTOMERASE; dwStyle |= ATN_CHILD_STYLE; <br />
toolBarCtrl.Create(hParent, rcBar, lpszCaption, dwStyle, 0); <br />
ATLASSERT(toolBarCtrl.IsWindow()); <br />
DWORD dwStyleEx = toolBarCtrl.GetExtendedStyle(); <br />
dwStyleEx |= TBSTYLE_EX_DRAWDDARROWS; <br />
toolBarCtrl.SetExtendedStyle(dwStyleEx); <br />
toolBarCtrl.SetButtonStructSize();<br />
toolBarCtrl.SetImageList(m_hImageList); return TRUE; }.
|
|
|
|
|
Hi, everyone
It's really urgent for me to learn more about how to create a vertical or docable toolbar with wtl. I'll apprieciate you so much if you give me any advice, even if give me any WTL forum URL, where I may found answers or solutions to my question.
Thanks a lot in advance.
|
|
|
|
|
HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE| CCS_VERT | TBSTYLE_WRAPABLE );
That should get you a vertical toolbar. Or try viksoe.dk ( look for atldock or WTL Docked UI )or even here[^] on CodeProject.
|
|
|
|
|
Hi,
Charles, Thanks a lot for your reply. I tried according to your hint. But didn't get vertical toolbar. And I don't know what's wrong happened.
Can you contribute a sample WTL project which demonstrates the vertical tooblar implementaion.
You may also send it to me by Email to JackLin5168@gmail.com or JackLin5168@yahoo.com .
Thank you so much. Charles.
Jack. China
modified on Monday, May 5, 2008 3:27 AM
|
|
|
|
|
Can anyone help me to resole this problem? I think there must be solution to my question.
|
|
|
|
|
Did you ever solve this problem? I am interested in the solution as well
|
|
|
|
|
Hello,
I have the following code that searches a list of wchar_t * strings.
What I want is a function like this:
vector <wchar_t *="">paths;
find (paths.begin(), paths.end(), L"some string");
What do I need to do to get this to return the string I'm searching for?
- BRC
|
|
|
|
|
This will not return a string but an iterator to the matching string. Your code would look something like this.
bool Comparer : public std::binary_function<wchar_t*, wchar_t*,bool>
{
public:
bool operator()(const wchar_t* s1, const wchar_t* s2) const
{
return (wcscmp(s1, s2) == 0);
}
};
std::vector<wchar_t*> paths;
std::vector<wchar_t*>::const_iterator it;
it = std::find_if(paths.begin(), paths.end(), std::bind2nd(Comparer(), L"some string"));
if (it != paths.end())
{
...
Pax Domini sit semper vobiscum
|
|
|
|
|
Hi,
I am having an issue compiling the ATL/Com dll;
I have Three classes and their interfaces in a com dll as:
1- IMailInterface
2- IMyInterface1
3- IMyInterface2
Now,MFC application uses these interfaces. My application will never directly deal with 2nd and 3rd interface. Everything will be done with the help of IMainInterface. I want to add a method to IMainInterace as
GetMyInterface1(IMyInterface1** ptr); which will retrun the IMyInterface1 pointer
But while comiling getting an error error as:
D:\Work_ganesh\MPlusSrvOpticalDevice\Work In Progress\Ganesh\Samples\DemoCOM\DemoCOM.idl(18):error MIDL2025 : syntax error : expecting a type specification near "IMyInterface1"
D:\Work_ganesh\MPlusSrvOpticalDevice\Work In Progress\Ganesh\Samples\DemoCOM\DemoCOM.idl(18) : error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation
Error executing midl.exe.
I tried adding header file but it didn’t worked.
Thanks.
"A winner is not one who never fails...but the one who never quits"
|
|
|
|