Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I access the App's tab in the task Manager Pin
jeguzmanv27-Jun-07 5:52
jeguzmanv27-Jun-07 5:52 
QuestionProblem I can't get past. Pin
Cory Borrow26-Jun-07 13:54
Cory Borrow26-Jun-07 13:54 
AnswerRe: Problem I can't get past. Pin
Ed.Poore26-Jun-07 13:59
Ed.Poore26-Jun-07 13:59 
GeneralRe: Problem I can't get past. Pin
Cory Borrow26-Jun-07 14:49
Cory Borrow26-Jun-07 14:49 
AnswerRe: Problem I can't get past. Pin
Christian Graus26-Jun-07 15:02
protectorChristian Graus26-Jun-07 15:02 
GeneralRe: Problem I can't get past. Pin
Cory Borrow26-Jun-07 15:54
Cory Borrow26-Jun-07 15:54 
GeneralRe: Problem I can't get past. Pin
Christian Graus26-Jun-07 16:22
protectorChristian Graus26-Jun-07 16:22 
QuestionC#, IE, C++ & BHO's... getting a C# Explorer Toolbar to talk to a C++ BHO Pin
BenAnderson26-Jun-07 11:03
BenAnderson26-Jun-07 11:03 
Hello,
I'm a bit new at in-depth IE programming, and am having a bit of trouble with a couple of IE browser extensions (getting them to talk to each other).

The first one is a C++ Browser Helper Object (BHO).

I have a class (MyClass) that has a method called "ReferenceMe" that calls the browser's "PutProperty" method to save a reference to the BHO instance in IE.

Theoretically other COM object should be able to call IE's "GetProperty" method to retrieve this reference and use it to invoke methods in the BHO.

I also have another method in the BHO called "toggleActiveState" that just sets a boolean flag. That's the method I want to invoke from outside of the BHO.

Then I have a C# Explorer Toolbar object. I'm trying to call the BHO's "toggleActiveState" method from the C# code.

The problem I'm having is that I can't figure out how to invoke that "toggleActiveState" method in the C++ BHO from the C# code.

When I try to call the GetMethod function call in C# to retrieve the method's reference, it returns NULL.

Below are snippets of my code...

Here's the C++ code...

<br />
// This seems to work fine... it saves a reference to the BHO in an IE Property for later retrieval.<br />
HRESULT MyClass::ReferenceMe()<br />
{<br />
	BSTR bstrThisKey = SysAllocString(L"MyClass_IDisp");<br />
	VARIANT vThis;<br />
	HRESULT hr = S_OK;<br />
<br />
	if (!m_spWebBrowser)<br />
		hr = S_FALSE;<br />
	else<br />
	{<br />
		// Save this to a variant that will be referenced in IE Session<br />
		VariantInit(&vThis);<br />
		vThis.vt = VT_DISPATCH;<br />
		vThis.pdispVal = static_cast<IDispatch*>(this);<br />
<br />
		// Add our this pointer to IE session by adding a named property<br />
		if (FAILED( m_spWebBrowser->PutProperty(bstrThisKey, vThis) ))<br />
		{<br />
			hr = S_FALSE;<br />
		}<br />
	}<br />
	<br />
	VariantClear(&vThis);<br />
	SysFreeString(bstrThisKey);<br />
    return hr;<br />
<br />
}<br />
<br />
// This is the method that I want to call from the C# code<br />
// It's declared in the Public portion of the class in the .h file.<br />
void STDMETHODCALLTYPE MyClass::toggleActiveState()<br />
{<br />
	m_bActive = !m_bActive;<br />
}<br />
<br />


And here's my C# code...

<br />
private void toggleBHO()<br />
{<br />
	Object pvarPBHO = null;<br />
	// Get the property from IE that was put there by the C++ code's call to "PutProperty"<br />
	// This does seem to return a COM object, which I'm assuming is my BHO reference.<br />
	pvarPBHO = Explorer.GetProperty("MyClass_IDisp");<br />
	if (pvarPBHO != null)<br />
	{			<br />
		MessageBox.Show("About to call GetType.");<br />
		// Get the object's type.  This seems to work fine.<br />
		Type typExternal = pvarPBHO.GetType();<br />
		if (typExternal != null)<br />
		{                    <br />
			// Now try to retrieve a reference ot the "toggleActiveState" method within the C++ code<br />
			MethodInfo mthInv = null;<br />
			MessageBox.Show("About to call GetMethod.");<br />
			<br />
			// AT THIS POINT THE GetMethod FUNCTION RETURNS NULL...<br />
			<br />
			// I'm not sure if I'm not calling this right, or if my prototype isn't quite right<br />
			// to allow public access to the method, or what.<br />
			mthInv = typExternal.GetMethod("toggleActiveState");<br />
			if (mthInv != null)<br />
				mthInv.Invoke(pvarPBHO, null);<br />
			else<br />
				MessageBox.Show("GetMethod returned NULL.");<br />
		}<br />
		else<br />
			MessageBox.Show("GetType returned NULL.");<br />
	}<br />
	else<br />
		MessageBox.Show("GetProperty returned NULL.");<br />
}<br />


Perhaps my whole approach to this is off. Is there a better way to get these two COM objects to talk to each other?

Thanks very much!
Questionftp FtpWebRespose.GetRespone() Exception Pin
Mostafa Siraj26-Jun-07 8:43
Mostafa Siraj26-Jun-07 8:43 
QuestionUDP Error Pin
ramdil26-Jun-07 6:54
ramdil26-Jun-07 6:54 
AnswerRe: UDP Error Pin
Dave Kreskowiak26-Jun-07 7:07
mveDave Kreskowiak26-Jun-07 7:07 
GeneralRe: UDP Error Pin
ramdil26-Jun-07 7:50
ramdil26-Jun-07 7:50 
GeneralRe: UDP Error Pin
Dave Kreskowiak26-Jun-07 9:11
mveDave Kreskowiak26-Jun-07 9:11 
GeneralRe: UDP Error Pin
ramdil27-Jun-07 3:20
ramdil27-Jun-07 3:20 
GeneralRe: UDP Error Pin
Dave Kreskowiak27-Jun-07 11:45
mveDave Kreskowiak27-Jun-07 11:45 
GeneralRe: UDP Error Pin
ramdil29-Jun-07 2:52
ramdil29-Jun-07 2:52 
QuestionAlways on top Pin
max2929726-Jun-07 6:09
max2929726-Jun-07 6:09 
AnswerRe: Always on top Pin
Luc Pattyn26-Jun-07 6:37
sitebuilderLuc Pattyn26-Jun-07 6:37 
AnswerRe: Always on top Pin
led mike26-Jun-07 6:54
led mike26-Jun-07 6:54 
GeneralRe: Always on top Pin
Ed.Poore26-Jun-07 8:42
Ed.Poore26-Jun-07 8:42 
GeneralRe: Always on top Pin
led mike26-Jun-07 8:49
led mike26-Jun-07 8:49 
AnswerRe: Always on top Pin
Ed.Poore26-Jun-07 8:42
Ed.Poore26-Jun-07 8:42 
AnswerRe: Always on top Pin
Dan Neely26-Jun-07 8:54
Dan Neely26-Jun-07 8:54 
QuestionRunning Applications Pin
max2929726-Jun-07 6:08
max2929726-Jun-07 6:08 
AnswerRe: Running Applications Pin
Luc Pattyn26-Jun-07 6:34
sitebuilderLuc Pattyn26-Jun-07 6:34 

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.