|
I need to sink some form.onsubmit and input.onlick events in a C# BHO that I'm starting. I tried the method prescribed in MSDN but found that immediately after attaching the event handler the browser would no longer respond to mouse clicks in the tab containing the instrumented document.
After some searching I found this: http://www.dotnet247.com/247reference/msgs/48/241776.aspx[^]
I've tried this solution (see implementation below) and it works fine, and cleared the mouse lockup problem as described. But I am getting persistent DisconnectedContext MDA alerts that I suspect are related to this implementation. These appear at seemingly random times (my guess is when garbage collector runs), but only if I close a browser tab that contains HTML elements that I have attached these event handlers to.
Is it not necessary to remove these event handlers from the HTMLDocument instances that they are attached to, before the document is unloaded (navigate away, close tab), and to remove them on the same thread that instantiated them? If so, how can I do this?
Or am I approaching this in the wrong way? If there is a more robust way to sink mshtml document events in C# please let me know.
A related question: since document (element) references handler, which references document, is it possible that this solution may contribute to IE memory leakage if the event handler is not removed from the document element before the document is unloaded?
public delegate void HtmlEvent(mshtml.IHTMLEventObj e);
[ComVisible(true)]
public class HtmlDocumentEventHandler
{
private mshtml.HTMLDocument htmlDocument;
public HtmlEvent eventHandler;
public HtmlDocumentEventHandler(mshtml.HTMLDocument htmlDocument)
{
this.htmlDocument = htmlDocument;
}
[DispId(0)]
public void Call()
{
this.eventHandler(this.htmlDocument.parentWindow.@event);
}
}
[ComVisible(true)]
public class HtmlDocumentFormElement
{
private mshtml.IHTMLFormElement element;
private mshtml.HTMLDocument document;
public HtmlDocumentFormElement(mshtml.HTMLDocument document, mshtml.IHTMLFormElement element)
{
this.document = document;
this.element = element;
}
public event HtmlEvent onSubmit
{
add
{
object old = this.element.onsubmit;
HtmlDocumentEventHandler handler = old is HtmlDocumentEventHandler ? old as HtmlDocumentEventHandler : new HtmlDocumentEventHandler(this.document);
this.element.onsubmit = handler;
handler.eventHandler += value;
}
remove
{
object old = this.element.onsubmit;
HtmlDocumentEventHandler handler = old is HtmlDocumentEventHandler ? old as HtmlDocumentEventHandler : null;
if (handler != null)
handler.eventHandler -= value;
}
}
}
mshtml.IHTMLFormElement element = form as mshtml.IHTMLFormElement;
HtmlDocumentFormElement formElement = new HtmlDocumentFormElement(this.HTMLDocument, element);
formElement.onSubmit += new HtmlEvent(OnSubmitEventHandler);
Kim Briggs
Kinek Technologies
kim.briggs@kinek.com
|
|
|
|
|
I was curious if anyone currently had a C++ COM Library. I am wanting to use it to create various IE COM functions.
|
|
|
|
|
thatsgreat2345 wrote: I was curious if anyone currently had a C++ COM Library
I have written a few. What are you asking, exactly ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Retrieving the COM class factory for component with CLSID {F9504F0D-7A6C-4373-85B3-DB7E47593270} failed due to the following error: 80040154.
hi in my application, i have one DLL developed by VC++ 6.0( ATL COM Component)... I have added as ref and created object... during the runtime, but i need tot work with web application also using webservice....
i need to access the COM Class in my webservice class file.
while calling, ia have error like this...
Retrieving the COM class factory for component with CLSID {F9504F0D-7A6C-4373-85B3-DB7E47593270} failed due to the following error: 80040154.
can anybody help this issue...please...
Actually this asp.net c# web appplication...
public class JQLiteServer : System.Web.Services.WebService //// ( Webservice class)
{
ClientNotifyNWStorage notifyStorage=null; ( client created class inherited from the COM Interface)
public JQLiteServer ()
{
objectClient = new ClientNotifyNWStorage(); //// ( Here i am having error in this line objClient )
}
}
a.prabakar83@yahoo.com
|
|
|
|
|
I have a C# program that uses a COM object in late binding:
Type DllObj;
object ClsObj;
DllObj = Type.GetTypeFromProgID("MyDLL.MyClass");
ClsObj = Activator.CreateInstance(DllObj);
My problem is that after the call is returned, the DLL MyDLL.DLL is stil in memory. I can see it using the Process Explorer utility.
How can I release that DLL?
My original code used early binding, and I released the COM object after using it by calling System.Runtime.InteropServices.Marshal.ReleaseComObject(). It does not seem to work when I pass it the ClsObj.
|
|
|
|
|
|
thanks but I cannot call CoFreeUnusedLibraries() from a .NET C# code.
|
|
|
|
|
I believe it can be called using P/Invoke just like any other Win32 API.
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I have an application(MFC), which should work with some "registration-free" com-components. I have extended the the application manifest and created a "com-manifest", as shown in the ms-examples. Everything works fine.
BUT, one of my menuitems starts a userthread which needs one of the
"registration-free" com-components, an ocx. The creation of the component succeeeds, but the QuickActivate() fails with an access violation.
Some ideas what goes wrong?
Hoping for help, thank you.
|
|
|
|
|
Jürgen Jung wrote: I have an application(MFC), which should work with some "registration-free" com-components. I have extended the the application manifest and created a "com-manifest", as shown in the ms-examples. Everything works fine.
BUT, one of my menuitems starts a userthread which needs one of the
"registration-free" com-components, an ocx. The creation of the component succeeeds, but the QuickActivate() fails with an access violation.
Some ideas what goes wrong?
Hoping for help, thank you.
A .ocx file sounds like an ActiveX control dll, and ActiveX controls can only run in the user interface thread. It seems likely that whatever object you need to access would need special thread safety additions. If the component you need is itself an ActiveX control, then your problem is more difficuld. You can either find some way to get the control accessed from the UI thread, or you could factor out whatever you need access to into a thread safe component.
Nathan
|
|
|
|
|
Hi,
I am having an issue compiling the ATL/Com dll;
I have Three classes and their interfaces in a com dll as:
1- IMailInterface
2- IMyInterface1
3- IMyInterface2
Now,MFC application uses these interfaces. My application will never directly deal with 2nd and 3rd interface. Everything will be done with the help of IMainInterface. I want to add a method to IMainInterace as
GetMyInterface1(IMyInterface1** ptr); which will retrun the IMyInterface1 pointer
But while comiling getting an error error as:
D:\Work_ganesh\MPlusSrvOpticalDevice\Work In Progress\Ganesh\Samples\DemoCOM\DemoCOM.idl(18):error MIDL2025 : syntax error : expecting a type specification near "IMyInterface1"
D:\Work_ganesh\MPlusSrvOpticalDevice\Work In Progress\Ganesh\Samples\DemoCOM\DemoCOM.idl(18) : error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation
Error executing midl.exe.
I tried adding header file but it didn’t worked.
Thanks.
"A winner is not one who never fails...but the one who never quits"
|
|
|
|
|
The forward declaration will help:
interface IMyInterface1;
...<br />
[uuid...]<br />
interface IMyInterface : Ixxxx<br />
{<br />
...GetMyInterface1([...]IMyInterface1** ptr); <br />
};
With best wishes,
Vita
|
|
|
|
|
hi,
i wrote a program that changes the titel of a document.(the text that is displayed in the explorer if you enable the column "titel")
i used this sample-code for doing that: http://www.codeproject.com/KB/files/SummInfoPropSetFile.aspx[^]
so far setting the titel works fine, but if i open the file with word and click on properties i should see the whole text i set. but i only see the first letter of the titel text i wrote in the file.
the explorer displays the name correct and in full length so i'm not sure what i am during wrong, can someone help me?
my code to write the titel of files:
<br />
bool FileManager::setNewTitelOfFile(std::wstring path, std::wstring titel)<br />
{<br />
FMTID PropSetfmtid={0xf29f85e0,0x4ff9,0x1068,{0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9 }};<br />
<br />
HRESULT hr = S_OK;<br />
IPropertyStorage *pPropStg = NULL;<br />
IPropertySetStorage *pPropSetStg = NULL;<br />
PROPSPEC propspec; <br />
PROPVARIANT propWrite;<br />
<br />
hr = StgOpenStorageEx( path.c_str(),<br />
STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,<br />
STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage,<br />
reinterpret_cast<void**>(&pPropSetStg) );<br />
<br />
if (hr == S_OK)<br />
{<br />
hr = pPropSetStg->Create(PropSetfmtid,<br />
NULL,<br />
PROPSETFLAG_DEFAULT,<br />
STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,<br />
&pPropStg);<br />
<br />
if (hr == S_OK)<br />
{<br />
propspec.ulKind = PRSPEC_PROPID;<br />
propspec.propid = 0x00000002;<br />
<br />
TCHAR titelAsTCHAR[1024]={0};<br />
StringCbPrintf(titelAsTCHAR, 1024, L"%s", titel.c_str());<br />
char titelAsChar[1024] = {0};<br />
<br />
WideCharToMultiByte(CP_ACP,<br />
NULL,<br />
titelAsTCHAR,<br />
static_cast<int>(titel.length()),<br />
titelAsChar,<br />
static_cast<int>(titel.length()),<br />
NULL,<br />
NULL);<br />
<br />
propWrite.pszVal = titelAsChar;<br />
propWrite.vt = VT_LPSTR;<br />
<br />
hr = pPropStg->WriteMultiple(1, &propspec, &propWrite, PID_FIRST_USABLE);<br />
<br />
if (hr == S_OK)<br />
{<br />
pPropSetStg->Release();<br />
pPropStg->Release(); <br />
return true;<br />
}<br />
}<br />
else<br />
{<br />
pPropSetStg->Release();<br />
pPropStg->Release();<br />
}<br />
}<br />
<br />
return false;<br />
}<br />
<br />
<br />
</int></int></void**>
|
|
|
|
|
can nobody help me?
a clue or a guess what the reason could be would be fine too.
|
|
|
|
|
Hey Everybody!
I wrote a COM in C#, and I imported teh tlb in c++, and calling a function without parameters works great!
The problem is that when I call a function in c# that has parameters I'm getting
HRESULT == "E_OUTOFMEMORY"
also, in the output I'm getting:
"Access violation reading location 0x0328fffc."
just to give some more information, here are the functions:
public void printme() { Console.WriteLine("It's ALIVE! ALIVE!"); } // <--- Works great!
public void printme(string text) { Console.WriteLine(text); } <--- returns E_OUTOFMEMORY!
THANKS IN ADVANCE!
|
|
|
|
|
Please, post some C++ code where you call "printme" nethod. I think you have a mistake there.
With best wishes,
Vita
|
|
|
|
|
Thanks!
Here is the C++ code:
::CoInitialize(NULL);
ITestPtr ptrTest;
HRESULT hr = ptrTest.CreateInstance(CLSID_CTest);
BSTR text(L"Text");
::SysAllocString(text); // <-- I tried with and without allocating string.
hr = ptrTest->printme(text);
::CoUninitialize();
Thanks again!
|
|
|
|
|
BSTR text = SysAllocString(L"Text");
hr = ptrTest->primetime(text);
SysFreeString(text);
ptrTest->Release();
|
|
|
|
|
Hey
first of all Thanks!
I found the problem, I just had to use _bstr_t instead of BSTR! pretty weird eh...?
Thanks again!
|
|
|
|
|
Hi,
I have a Excel macro.
I have an array with values (example)
Human
Animal
Cooldrink
Telephone
I have any input parameter of "Animal 3". It loops through the array to search for a match, for example, if it checks the following:
Animal 3 = Animal, then it must bring back true.
It must just search for a partial value. How do I do this?
Thanks
Brendan
|
|
|
|
|
1.I call C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE using COM (OLE) of Visual C++.
2.I succeeded in call all the related _Application, _Workbook, Workbooks, Worksheets, _Worksheet, Range.
3.The problem I had is I search everywhere to find out the functions define (How to use) in all the related header files.
4.Below is an instance what I need.
This is the CAPPLICATION.h files, where I could possibly find out all the related definitions documentation?
// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard
// CApplication wrapper class
class CApplication : public COleDispatchDriver
{
public:
CApplication(){} // Calls COleDispatchDriver default constructor
CApplication(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
CApplication(const CApplication& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}
// Attributes
public:
// Operations
public:
// _Application methods
public:
LPDISPATCH get_Application()
{
LPDISPATCH result;
InvokeHelper(0x94, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
long get_Creator()
{
long result;
InvokeHelper(0x95, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Parent()
{
LPDISPATCH result;
InvokeHelper(0x96, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveCell()
{
LPDISPATCH result;
InvokeHelper(0x131, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveChart()
{
LPDISPATCH result;
InvokeHelper(0xb7, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveDialog()
{
LPDISPATCH result;
InvokeHelper(0x32f, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_ActiveMenuBar()
{
LPDISPATCH result;
InvokeHelper(0x2f6, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
CString get_ActivePrinter()
{
CString result;
InvokeHelper(0x132, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}
|
|
|
|
|
Hi, i want to use an activeX (component, control, i don't know which) to control an device, and send some data to perform a standard web login (ok ok a little unstandard).
the device is a biometrical reader (yes, you put your finger on ), i had read some documentation about, but i have a lots of questions yet...
questions like:
- Can i develop an average activeX object, using the visual studio c++ express (without the MFC, ATL, etc..)??
- Is possible install that features on my version of visual studio (express)??
- Can i access to my device from the activeX object....
Sorry, if my questions seems so newbies : )... but i really appreciate your help
|
|
|
|
|
Hi, my IT department have doubts if the COM components in production environment really correspond to the source code in the visual source safe. It's the hard truth.
So...I'm searching for methods to verify is the source code is valid.
Just recompiling the source and compare the generated DLL with the DLL in production environment is not a valid way. As I have seen, even on sequential compilations the generated DLLs (with binary compatibility) are different, and not only on some bytes (like timestamps) as I thought.
I'm also thinking about building a tool to extract the typelibraries to compare them, it's not the final comparison but can help in cases the interface is different.
Any ideas ? A comparison tool telling Yes or No (the two COM DLLs are the same or not) would be my dream
EDIT: the source code is VB6.
Thanks for any help.
modified on Tuesday, April 8, 2008 2:08 PM
|
|
|
|
|
someome can tell me the way, thanks.
|
|
|
|
|
Hi in my project i want add VC++ dlls to the asp.net application. While i adding i have the following error
"A reference 'C:\Windows\System32\JQLiteServer.dll' could not be added"
JQLiteServer.dll is developed by VC++6.0
The dll contains 5 methods. I want call these methods in my asp.net appln.
anybody help me please...
Thanks in Advance
Prabakaran.
|
|
|
|
|