|
You need to either marshal the event interface into the thread that needs to call back (which I always found was unreliable) or have the thread that needs to call back do so via an interface that effectively marshals the callback into the thread that VB registered the event sink in. My article does it the second way and works fine.
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Hi,
i've tried to marshal the event interface from the Interface Impl. class.
// this is CPort ( implementation from "interface IPort : IDispatch" )
HRESULT hr = CoMarshalInterThreadInterfaceInStream(DIID__IPortEvents,(_IPortEvents*)this,&pStream);
But "(_IPortEvents*)this" doesn't get the Event Interface.
I can only marshal the IPort Interface. How can i get the pertinent Eventinterface ?
Marco
|
|
|
|
|
The code in the article explains what you need to do and what you need to be aware of.
Your impl class probably doesn't implement the event sink interface, there would be no reason for it to, after all the interface is for users of your class to implement so that they can sink your class's events. You either have to marshal the interface that the client registers with you (during advise), but this is made complex if you happen to be using the ATL stuff to do the connection point management for you. OR you need to implement a new interface that you use to communicate between your worker thread and your main object's thread. See the article for a complete implementation. It's non trivial (hence the need for an article).
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Hi again,
now it seems to work ! I've tried your first suggestion.
I take the "m_vec" to get the IDispatch Interfaces, like the EventProxy Code it does. Then I marshal these Interfaces to global Variables.
Finally i unmarshal these interfaces and call the "invoke" Funktion, to
fire the event.
Your 2. Solution seems to extensively for my program.
Marco
|
|
|
|
|
Koep wrote:
now it seems to work ! I've tried your first suggestion.
I take the "m_vec" to get the IDispatch Interfaces, like the EventProxy Code it does. Then I marshal these Interfaces to global Variables.
Finally i unmarshal these interfaces and call the "invoke" Funktion, to
fire the event.
Sounds good! Glad it works.
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Hi,
I want to return Binary data i've read from a file.
I know it can be done by safe array.. can nebody give me some hint on how to do that
Regards
Sameer
|
|
|
|
|
Use the type VT_U1 to store the binary data.
|
|
|
|
|
|
I do something similar (return binary data in a safe array) in my COM Mailslots article. The code in question is:
STDMETHODIMP CMailslotData::Read(VARIANT *ppResults)
{
if (!ppResults)
{
return E_POINTER;
}
return CreateSafeArray(m_pData, m_length, ppResults);
}
where m_pData points to the bytes of data and m_length is the number of bytes we have.
HRESULT CreateSafeArray(
BYTE *pData,
DWORD dataLength,
VARIANT *ppResults)
{
SAFEARRAYBOUND sab;
sab.cElements = dataLength;
sab.lLbound = 0;
SAFEARRAY *pSa = SafeArrayCreateEx(VT_UI1, 1, &sab, 0);
PVOID pvData;
HRESULT hr = SafeArrayAccessData(pSa, &pvData);
if (SUCCEEDED(hr))
{
::CopyMemory(pvData, pData, dataLength);
hr = ::SafeArrayUnaccessData(pSa);
}
if (SUCCEEDED(hr))
{
::VariantInit(ppResults);
(*ppResults).parray = pSa;
(*ppResults).vt = VT_ARRAY | VT_UI1;
}
return hr;
}
Hope this helps.
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Hello,
i have to raise an event from outside the COM Class.
The Eventnotifier is a CObject MFC Class und should
raise the event in the COM Server Class. I have no
idea which header i should include to make this
possible.
MFC-Class should call CProxy_IXXXEvents ( Fire_OnXXXX )
Can anybody help me ?
Marco
|
|
|
|
|
Hi,
The best way would be to pass the pointer to the COM class
itself. Since you would not know in which COM class instance
you want to fire the event.
And then ofcourse it is as simple as Calling
pObject->FireEvent()
|
|
|
|
|
Hi all
I have a question regaring DCOM basic knowledge
the Q is : is it possible to create a client server application were the server can call a client without the client calling the server first.? is there any GOOD article to show me how to do so?
further more is DCOM works only over TCP/IP ?
|
|
|
|
|
1. Obvisously the Client in this sense becomes a server.
(Actually any program that offers services is a server.)
You could implement the client itself as a DCOM server implementing
only one COM object. In this sense you could start the Client and
marshall the IUnkown pointer from server to the client and from
then onwards the client can interact with the server.
2. No DCOM does not work only on TCP/IP, In fact till winnt 4.0
the preferred protocol was UDP.
|
|
|
|
|
I wish to have the ability to dynamically add script to my application without needing to recompile the VC++ code. I added support for VB Scripting following the example in Q221992 How to Add support for hosting VB Script to your MFC application. Using this I can enter VB Script into an Edit control to Launch Outlook, Word, Excel etc. However I am having trouble accessing events from these applications.
Is it possible to access these events - I have been trying to access the Close or New events without success.
If this is possible can anyone supply a simple example.
Any assistance would be very welcome.
Sara
|
|
|
|
|
I read an article on this site that might prove useful to you.
http://codeproject.com/com/dyn_idispatch.asp
Good Luck!
|
|
|
|
|
Hi
To receive event in VBScript (BTW I don't know how to do it with JScript)
you need to write your handler like this:
Let's say you have an object name: ctlMyActiveXObject
Sub ctlMyActiveXObject_Close()
' Do anything you want here...
End Sub
Close is the name of the event as you might actually guess!
I was at this point when I realized that you post this since May 26th, probably
you found the answer already...
Good luck!
One good thing about getting older, you don't lose the ages you've been!
|
|
|
|
|
Hello, I am using a commercial component in a VC++ app and I'm confounded by the use of BSTR.
The function I need to call was generated from Classwizard by using the Add Class function and pointing it to the .dll that contains the component, it's defined like this:
------
short _clsIIF::ReadIIF(BSTR* PathName)
{
short result;
static BYTE parms[] = VTS_PBSTR;
InvokeHelper(0x60030024, DISPATCH_METHOD, VT_I2, (void*)&result, parms,PathName);
return result;
}
----
The Microsoft docs say to use _bstr_t instead of BSTR, however the compiler won't accept any form of casting of _bstr_t which according to the docs is how to return the encapsulated BSTR object. The only solution I have been able to come up with that works is this:
---------------------
_bstr_t b(strPathToIIF);//strPathToIIF is a CString
BSTR B;
B = b.copy();
lResult=iif.ReadIIF(&B);
-----------------
It works fine, but it's very obviously an inelegant way of doing it, any help would be very much appreciated. The component I'm using has Visual Basic docs only and I don't know anything about VB and only slightly more about COM.
- John
|
|
|
|
|
_bstr_t bstr("Blah-blah-blah");
BSTR wsVal;
wsVal = (BSTR)bstr;
soptest
|
|
|
|
|
I was hoping to pass the _bstr_t variable directly somehow and avoid the BSTR variable entirely.
|
|
|
|
|
BSTR ws = strPathToIIF.AllocSysString();
soptest
|
|
|
|
|
Ahhh! Perfect, thank you.
|
|
|
|
|
Did you try YourFunc(_bstr_t(yourstring))?
Also, make sure you call SysFreeString any time you alloc a string.
Like it or not, I'm right.
|
|
|
|
|
J Cardinal wrote:
(BSTR* PathName)
You can't use pointer with BSTR .
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
Hello ,
i have a problem. my bluetooth pcmcia bluetooth cf card only contains drivers for pocket pc. But my device is windows CE 3.0 based.
I can`t contact the productvendor.
Is there a way to convert or create drivers for windows Ce 3.o from the pocket pc drivers.
I have a armadillo bluetooth cf card.
Plz respond thanks in advance.
Martijn Pijpers
accessor.martijn@wxs.nl
|
|
|
|
|
It has nothing to do with COM!
soptest
|
|
|
|