Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Javascript properties in AtlBrowser

9 views
Skip to first unread message

Adrian Rosoiu

unread,
Jan 26, 2007, 11:14:02 AM1/26/07
to
Hi there,

My project is based on the AtlBrowser sample. Here is what I am trying to do:

JavaScript code:
-------------------
window.external.MyProperty = "test string";
alert(window.external.MyProperty);

In AtlBrowser.idl:
--------------------
[propget, id(DISPID_MYPROP), helpstring("property MyProperty")] HRESULT
MyProperty([out, retval] LPTSTR *pszVal);
[propput, id(DISPID_MYPROP), helpstring("property MyProperty")] HRESULT
MyProperty([in] LPCTSTR szVal);

In AtlBrCon.h:
----------------
STDMETHOD(get_MyProperty)(LPTSTR*);
STDMETHOD(put_MyProperty)(LPCTSTR);

In AtlBrCon.cpp:
------------------
STDMETHODIMP CAtlBrCon::get_MyProperty(LPTSTR *pszVal){
//*pszVal = NULL;
return S_OK;
}

STDMETHODIMP CAtlBrCon::put_MyProperty(LPCTSTR szVal){
MessageBox(szVal);
return S_OK;
}

Problem is that my functions get_MyProperty() and put_MyProperty() never get
called and I get a JavaScript error reading "Object doesn't support this
property or method."

What am I missing here? Or is there an easier way of doing this?


Thank you very much.

Igor Tandetnik

unread,
Jan 26, 2007, 11:32:01 AM1/26/07
to
Adrian Rosoiu <Adrian...@discussions.microsoft.com> wrote:
> My project is based on the AtlBrowser sample. Here is what I am
> trying to do:
>
> JavaScript code:
> -------------------
> window.external.MyProperty = "test string";
> alert(window.external.MyProperty);
>
> In AtlBrowser.idl:
> --------------------
> [propget, id(DISPID_MYPROP), helpstring("property MyProperty")]
> HRESULT MyProperty([out, retval] LPTSTR *pszVal);

Make it

[out, retval] BSTR* pVal

LPTSTR is not automation compatbile. I bet MIDL compiler tells you as
much.

> [propput, id(DISPID_MYPROP), helpstring("property MyProperty")]
> HRESULT MyProperty([in] LPCTSTR szVal);

Similarly, make it [in] BSTR val
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Adrian Rosoiu

unread,
Jan 26, 2007, 12:17:02 PM1/26/07
to

"Igor Tandetnik" wrote:

Thanks Igor,

I modified to BSTR* and BSTR but with no results.

What I've gathered is that the Invoke() function is called with dispidMember
= DISPID_MYPROP, so I'm thinking that I should manually call get_MyProperty()
and put_MyProperty() accordingly.

I'm a little dissapointed as I was expecting that it would do this
automatically. If I have to call my functions in Invoke() it does not make
sense to create the get_() and put_() functions. I can read and return
VARIANT values right there in the big switch() from Invoke().

Isn't there any more "elegant" way of doing it?

Igor Tandetnik

unread,
Jan 26, 2007, 12:37:50 PM1/26/07
to
Adrian Rosoiu <Adrian...@discussions.microsoft.com> wrote:
> What I've gathered is that the Invoke() function is called with
> dispidMember = DISPID_MYPROP

Then find out where the connection breaks between Invoke and your actual
functions. Most likely, the type library is not registered properly, or
template parameters to IDispatchImpl are incorrect (you are deriving
from IDispatchImpl, right?). Step through Invoke, see where it fails.

0 new messages