|
Hi Martin,
I think you are on right track. Just make sure you are not holding any reference in your own code. Use smart pointer (CComPtr, CComQIPtr). If you queried for an interface, make sure you release it in your OnDestroy. I don't think it matters that you are using an MFC extension DLL, as long you release your interface, it should work fine.
Did you try creating a separate project (simple dialogbox) using the activeX in question?
In the end, we will remember not the words of our enemies, but the silence of our friends. - Martin Luther King Jr.
Ernest Laurentin
|
|
|
|
|
Hi Ernest,
thanks for your reply.
Until today morning I used no smart pointers, but using them does not change a thing.
I didn't expect a change in behaviour, because in my MFC C++ ActiveX control I could see, while debugging, that my reference handling was ok.
Ok - now I've introduced CComIQPtr and CComPtr, but it changes nothing.
The question is, why in comparison to the MFC ActiveX control one additional reference to the VB ActiveX control is hold!? And how/what is holding this reference to which interface?
The question raises, because releasing "my" interface I got a count of hold references of 3 with the MFC ActiveX control, but 4 with the VB ActiveX control.
And debugging through the deletion of my hosting CWnd I see only 3 releases on the interfaces of the MFC and the VB Active control.
So - where is the last reference on a interface to be found?
And ... do I have the possibility to change this behaviour?
Best regards,
Martin
|
|
|
|
|
Hello again,
first - I'm sorry, because I didn't provide any information about the development environment:
Microsoft Visual Studio 6.0 SP6
Microsoft Visual Basic 6.0 SP6
And ... no ... I can not upgrade - currently!
Second - I created a new most simple MFC application only loading the VB ActiveX control and raising an exception on exiting.
It has a CWnd* member on which CreateControl is called and which is deleted while deleting the dialog object.
So it shows the same behavior than the big MFC application I normally work on.
Has someone a hit or suggestion?
Best regards,
Martin
|
|
|
|
|
Hello,
after trying a bit I changed my VB ActiveX Control to execute the "UserControl_Terminate" things in the "UserControl_Hide" event handler.
Only the call "App.LogEvent ..." stayed in the "UserControl_Terminate" event handler.
And now everything seems to work fine.
Even a VB ActiveX Control with CommonControls (not even touched in the "UserControl_Terminate" event handler) works now.
So - I don't know why, but now everything works.
I found a solution, but no understanding for the problem.
Best regards,
Martin
|
|
|
|
|
Hi,
I am using a third party COM library, I am initializing one interface(I1) and all interfaces are initialize with I1. Am I need to call realese on every inreaface when I used any function of these intefaces?
|
|
|
|
|
It depends on what you mean by "all interfaces are initialize with I1".
Presumably this means that the interface I1 is queried for the other interfaces and the rules of COM says that when an interface is queried for, the reference count is set to 1 is the query was successful.
This means that you most likely have to release the interface when you're done with it.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Is the same true for smart interface pointer?
modified on Tuesday, October 21, 2008 4:51 AM
|
|
|
|
|
Smart pointers such as CComPtr will call Release() when they go out of scope. If you try to call AddRef() or Release() on a CComPtr, you'll get an error.
The CComPtr has the COM rules for reference counting built in, so you don't have to worry about that if you're using CComPtr . Even CComQIPtr works the same way.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi
I have a server which wil be fetching live Prices and i have to convert this server into a com+ service which wil be running on the server.. i to use the com + service in my aspx (i.e) webapplication . when ever the com + component raises a event i should be able to capture the event raised by the com+ service.. can we achieve this... Pls help me out
|
|
|
|
|
hi friend
Can any body tell me what is the advantages of .pfx file. and why we use it.
wasim khan
|
|
|
|
|
hI,
I am using the MSComm port for recieving data in c#.net while recieving data in parts from the OnComm event of mscomm i am not able to get the correct frame i.e. instead of 60bytes i am getting 80 bytes.
Can anybody tell the solution
|
|
|
|
|
tauras81 wrote: instead of 60bytes i am getting 80 bytes.
Well, you get 20 for free.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Firstly, if you're using .NET 2.0 or later you should be using the SerialPort class. The MsComm control is ancient and wasn't particularly good even with Visual Basic 6.0.
Secondly, serial communications are not framed - write boundaries are not preserved. You will get whatever is in the buffer when the read timeout expires, depending on how you've set up your serial port timeouts; this may be less than the number of bytes you requested.
"Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu
|
|
|
|
|
|
You must always match AddRef and Release calls. Do not rely on the return value of Release.
QueryInterface and CoCreateInstance add a reference implicitly, so they must always be matched with a call to Release.
"Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu
|
|
|
|
|
In VS6 C++, I have a windowless ATL control. To get a Device Context from the container, I belive I need to execute the GetDC() method of one of the base classes for the control, specifically IOleInPlaceObjectWindowless. I tried to do this:
CDC *pDC = IOleInPlaceObjectWindowless::GetDC();
But it doesn't work so I am at a loss as to how to execute a method on the IOleInPlaceObjectWindowless interface.
Any help would be greatly appreciated,
Thanks,
Doug
Doug Knudson
|
|
|
|
|
You can use methods exposed by interfaces ,only. Or you want to say smething else ?
|
|
|
|
|
Thanks for the reply. I didn't ask my question very well, but basically I am writing a windowless ATL component and need the Device Context from the Parent/Container so that I may draw in event handlers (for example, in MouseMove()). During my length time searching, all I could find was people saying that I needed to just execute the GetDC() method of the IOleInPlaceObjectWindowless interface like this:
HDC hDC = NULL;
HRESULT hr = IOleInPlaceObjectWindowless::GetDC(myRect,myFlags,&hDC);
The compiler interprets the above as trying to execute a static member function, which, of course, GetDC() isn't. If I just use:
GetDC();
I get the API GetDC() that expects there to be a m_hWnd, which there isn't (windowless control), so I am pretty lost as to how to do this.
Thanks,
Doug
Doug Knudson
|
|
|
|
|
There is no GetDC method on the IOleInPlaceObjectWindowless interface, nor any of its base interfaces.
You should generally be doing all your drawing in your implementation of IViewObject::Draw , i.e. in OnDraw .
If you need to do some drawing outside of this, the GetDC call is on IOleInPlaceSiteWindowless, which you have to ask the container for. I believe you should call InternalGetSite (which is inherited from CComControlBase ) to retrieve a pointer to this interface.
"Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu
|
|
|
|
|
Hi Mike,
Thanks! I will give that a try. I am doing the bulk of my drawing in OnDraw() but I need to drag a selection rectangle during the MouseDown, MouseMove, MouseUp events so I need to (or at least I think I need to ) have the DC outside of what is handed to me in OnDraw() ??
Thanks again,
Doug
Doug Knudson
|
|
|
|
|
I am trying to access a .net dll from excel via VBA. I am able to successfully do that on my machine.
But when I try to do the same on user's machine(which does not have VS 2003 but has .net Framework 1.1) The excel (as soon as I open the excel file) gives me an error "File or assembly name QueryData, or one of its dependencies, was not found".
I follow the following steps on the user's machine:
1. Register the .net dll using regasm tool and create a .tlb file
Regasm QueryData.dll /tlb:QueryData.tlb
2. Add this tlb file to the references of the excel.
3. Close the excel sheet and open it again (I have some code in the workbook_open event of excel).
I don't get any errors while generating the tlb file, but as soon as I open the excel I get the error mentioned above. I have also copied all the dlls from the bin folder of my dev machine to the folder (having QueryData.dll) on the user machine.
I have no clue why the excel file is not able to find the dll. Any pointers??
Thanks,
Neeraj
|
|
|
|
|
How to convert interface object to its class?
I have an interface object say IMarkSet. I passed to an COM function. There i need to access a function which takes CMarkedSet .
Thanks
Mohan
|
|
|
|
|
AnanyaMohan wrote: I have an interface object say IMarkSet. I passed to an COM function. There i need to access a function which takes CMarkedSet .
^
|
v
How to convert interface object to its class?
The answer is really simple: you don't.
The reason may be a bit more complicated....
This is a design flaw either in your class or the interfaces it exposes and perhaps even a combination. This is all about abstraction and encapsulation.
A COM object/server exposes several interfaces that can be used to alter the behaviour and/or state of the server. Whatever the server is supposed to do, it must be possible to trigger it through the interfaces. Perhaps you need to query for another interface, or even implement an additional interface, but that's all right; it's supposed to work that way.
But how the server accomplishes its task is entirely up to the server and is encapsulated behind interfaces.
In short: you have to re-evaluate your design.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
AnanyaMohan wrote: There i need to access a function which takes CMarkedSet
That simply is wrong thing, you are trying to do. Always talk through interface.
|
|
|
|
|
Hi,
Iam using a c++ dll in my .net application.It is running fine on the system where visual studio 2005 is installled.
In the deployment environment we have only framework2.0 installed on the machine.Then Iam getting a pop-up error as
"<big><b>Microsoft visual c++ runtime library
Runtime error
c:\testapp\bin\debug\test.exe
The application has requested the application to terminate in the unusual way
Please contact the application's support team for more information</b></big>"
Please kindly help ASAP
|
|
|
|