Click here to Skip to main content
15,887,401 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Read String Pin
Iain Clarke, Warrior Programmer3-Aug-10 2:09
Iain Clarke, Warrior Programmer3-Aug-10 2:09 
AnswerRe: Read String Pin
Nemanja Trifunovic2-Aug-10 4:58
Nemanja Trifunovic2-Aug-10 4:58 
AnswerRe: Read String Pin
Moak2-Aug-10 5:20
Moak2-Aug-10 5:20 
GeneralRe: Read String Pin
Emilio Garavaglia2-Aug-10 20:25
Emilio Garavaglia2-Aug-10 20:25 
GeneralRe: Read String Pin
Moak2-Aug-10 22:26
Moak2-Aug-10 22:26 
GeneralRe: Read String Pin
Emilio Garavaglia3-Aug-10 20:17
Emilio Garavaglia3-Aug-10 20:17 
GeneralRe: Read String Pin
Moak3-Aug-10 22:22
Moak3-Aug-10 22:22 
QuestionCOM interface disappears from ROT [modified] Pin
Phil J Pearson2-Aug-10 1:09
Phil J Pearson2-Aug-10 1:09 
I have two applications, both of which I have written.
AppA was written in C++ using MFC. During startup it registers a CSingleDocTemplate and creates a document. The document provides a COM interface and registers itself in the ROT:
LPUNKNOWN punk = GetInterface(&IID_Welder); // doesn't AddRef
::RegisterActiveObject(punk, CLSID_Interface, ACTIVEOBJECT_WEAK, &m_dwRegister);

AppA revokes the entry in the ROT when it is destroyed:
if (m_dwRegister)
  ::RevokeActiveObject(m_dwRegister, NULL);

The destructor is only called when AppA terminates.

AppB is written in C# and is a client of the interface provided by AppA:
private void Connect()
  {
  welderInterface = (Welder.Interface)Marshal.GetActiveObject("Welder.Interface");
  Marshal.GetIUnknownForObject(welderInterface);	// AddRef's it ...
  }

private void Disconnect()
  {
  if (welderInterface != null)
    {
    Marshal.ReleaseComObject(welderInterface);
    welderInterface = null;
    }
  }
(error handling omitted for clarity)

That all works perfectly the first time AppB runs after AppA has started; AppB can call Connect and Disconnect as often as it wants and use the interface between. However, if AppB terminates and runs again (AppA still running) the interface is no longer available - Marshal.GetActiveObject throws an exception from MK_E_UNAVAILABLE. The only way to make the interface available again is to restart AppA - not an acceptable solution!

Please can someone suggest how I might fix this?
Phil



The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

modified on Monday, August 2, 2010 7:16 AM

AnswerRe: COM interface disappears from ROT Pin
Code-o-mat2-Aug-10 1:18
Code-o-mat2-Aug-10 1:18 
GeneralRe: COM interface disappears from ROT Pin
Phil J Pearson2-Aug-10 1:51
Phil J Pearson2-Aug-10 1:51 
GeneralRe: COM interface disappears from ROT Pin
Code-o-mat2-Aug-10 1:59
Code-o-mat2-Aug-10 1:59 
GeneralRe: COM interface disappears from ROT Pin
Phil J Pearson2-Aug-10 2:07
Phil J Pearson2-Aug-10 2:07 
AnswerRe: COM interface disappears from ROT Pin
Phil J Pearson2-Aug-10 2:19
Phil J Pearson2-Aug-10 2:19 
GeneralRe: COM interface disappears from ROT Pin
Code-o-mat2-Aug-10 2:24
Code-o-mat2-Aug-10 2:24 
QuestionClistCtrl Pin
alexander 19831-Aug-10 23:59
alexander 19831-Aug-10 23:59 
AnswerRe: ClistCtrl Pin
«_Superman_»2-Aug-10 0:14
professional«_Superman_»2-Aug-10 0:14 
AnswerRe: ClistCtrl Pin
David Crow2-Aug-10 2:49
David Crow2-Aug-10 2:49 
AnswerRe: ClistCtrl Pin
bleedingfingers2-Aug-10 3:18
bleedingfingers2-Aug-10 3:18 
AnswerRe: ClistCtrl Pin
KarstenK2-Aug-10 4:02
mveKarstenK2-Aug-10 4:02 
QuestionGet session based Cookies in C++ BHO Pin
Aendy1-Aug-10 22:16
Aendy1-Aug-10 22:16 
AnswerRe: Get session based Cookies in C++ BHO Pin
«_Superman_»1-Aug-10 23:27
professional«_Superman_»1-Aug-10 23:27 
GeneralRe: Get session based Cookies in C++ BHO Pin
Aendy2-Aug-10 0:46
Aendy2-Aug-10 0:46 
Questionfailed to start because MSVCP71.dll was not found ! ? Pin
zon_cpp1-Aug-10 19:48
zon_cpp1-Aug-10 19:48 
AnswerRe: failed to start because MSVCP71.dll was not found ! ? Pin
Richard MacCutchan1-Aug-10 21:25
mveRichard MacCutchan1-Aug-10 21:25 
QuestionCDateTimeCtrl Pin
john56321-Aug-10 6:21
john56321-Aug-10 6:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.