Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralSmtpMail.Send exception Pin
EnkelIk17-Jun-03 23:16
EnkelIk17-Jun-03 23:16 
GeneralRe: SmtpMail.Send exception Pin
EnkelIk18-Jun-03 0:53
EnkelIk18-Jun-03 0:53 
GeneralRe: SmtpMail.Send exception Pin
EnkelIk18-Jun-03 1:43
EnkelIk18-Jun-03 1:43 
GeneralRe: SmtpMail.Send exception Pin
EnkelIk18-Jun-03 21:39
EnkelIk18-Jun-03 21:39 
GeneralRe: SmtpMail.Send exception Pin
EnkelIk22-Jun-03 20:38
EnkelIk22-Jun-03 20:38 
Questionhow to view property of a file in terms of coding Pin
puppiesLover17-Jun-03 22:49
puppiesLover17-Jun-03 22:49 
AnswerRe: how to view property of a file in terms of coding Pin
nfactorial17-Jun-03 23:11
nfactorial17-Jun-03 23:11 
QuestionHow can one call a script function from a C# WebBrowser Application? Pin
Alberto Colon17-Jun-03 17:12
Alberto Colon17-Jun-03 17:12 
Hi! I'm developing an application that hosts a WebBrowser control. Users will be able to input information into the pages but the information must be transferred to the application. The thing is that the pages content and controls are unknown and will change from time to time. My approach was to have some javascript code into the pages to handle the validation in each page and then "transfer" the information to the win form.

My question is how to call the javascript functions in the html pages. After searching the .NET documentation I found the execScript() function in the IHTMLWindow2 interface. I managed to get the IHTMLWindow2 reference through the WebBrowser.Document.parentWindow object (with the necessary casting to IHTMLDocument2).
The execScript() function worked and executed the defined functions in the HTML pages but the problem is that there is no way to get the return value of the functions.

After searching the MS site I found an article titled
"HOWTO: Call a Script Function from a VC WebBrowser Application (Q185127)" [http://support.microsoft.com/default.aspx?scid=kb;en-us;185127]
that handles a similar situation but using C++ code.

I need to know how to execute a javascript function from an HTML file in a WebBrowser control and then retrieve the return value of the functions, using a C# application. Here is included the VC++ code from the article. Since my COM experience is poor and my C++ experience is very limited (old DOS-Turbo C++), any help in porting the C++ code to C# managed code is extremely appreciated. All corrections, ideas and workarounds are welcomed and appreciated.

Thanks, Alberto Colon Smile | :) .


Here goes the article code (c++):
<br />
#import "C:\winnt\system32\mshtml.tlb" // location of mshtml.tlb<br />
<br />
    void CMyClass::ExecuteScriptFunction()<br />
    {<br />
        // m_WebBrowser is an instance of IWebBrowser2<br />
        MSHTML::IHTMLDocument2Ptr spDoc(m_WebBrowser.GetDocument());<br />
<br />
        if (spDoc)<br />
        {<br />
            IDispatchPtr spDisp(spDoc->GetScript());<br />
            if (spDisp)<br />
            {<br />
                // Evaluate is the name of the script function.<br />
                OLECHAR FAR* szMember = L"evaluate";<br />
                DISPID dispid;<br />
<br />
                HRESULT hr = spDisp->GetIDsOfNames(IID_NULL, &szMember, 1,<br />
                LOCALE_SYSTEM_DEFAULT, &dispid);<br />
<br />
                if (SUCCEEDED(hr))<br />
                {<br />
                    COleVariant vtResult;<br />
                    static BYTE parms[] = VTS_BSTR;<br />
<br />
                    COleDispatchDriver dispDriver(spDisp, FALSE);<br />
<br />
                    dispDriver.InvokeHelper(dispid, DISPATCH_METHOD, VT_VARIANT,<br />
                    (void*)&vtResult, parms, "5+Math.sin(9)");<br />
                }<br />
            }<br />
        }<br />
    }<br />

The following is the HTML for the Web page that contains the evaluate function:
<br />
<SCRIPT><br />
    function evaluate(x)<br />
    {<br />
        alert("hello")<br />
        return eval(x)<br />
    }<br />
</SCRIPT><br />

Generalchange icon at runtime Pin
albean17-Jun-03 15:54
albean17-Jun-03 15:54 
QuestionA .Net way to do PostMessage()? Pin
mcgahanfl17-Jun-03 15:41
mcgahanfl17-Jun-03 15:41 
AnswerRe: A .Net way to do PostMessage()? Pin
Oleksandr Kucherenko17-Jun-03 21:20
Oleksandr Kucherenko17-Jun-03 21:20 
GeneralRe: A .Net way to do PostMessage()? Pin
dynamic17-Jun-03 22:07
dynamic17-Jun-03 22:07 
GeneralRe: A .Net way to do PostMessage()? Pin
mcgahanfl18-Jun-03 3:04
mcgahanfl18-Jun-03 3:04 
GeneralNew to C# - API Usage Pin
User 665817-Jun-03 14:09
User 665817-Jun-03 14:09 
GeneralRe: New to C# - API Usage Pin
Jim Stewart17-Jun-03 15:25
Jim Stewart17-Jun-03 15:25 
GeneralRe: New to C# - API Usage Pin
J. Dunlap17-Jun-03 15:31
J. Dunlap17-Jun-03 15:31 
GeneralRe: New to C# - API Usage Pin
firat kocak17-Jun-03 20:12
firat kocak17-Jun-03 20:12 
GeneralRe: New to C# - API Usage Pin
User 665818-Jun-03 0:21
User 665818-Jun-03 0:21 
GeneralRe: New to C# - API Usage Pin
firat kocak18-Jun-03 1:07
firat kocak18-Jun-03 1:07 
GeneralRe: New to C# - API Usage Pin
User 665818-Jun-03 2:09
User 665818-Jun-03 2:09 
GeneralRe: New to C# - API Usage Pin
firat kocak18-Jun-03 2:50
firat kocak18-Jun-03 2:50 
GeneralRe: New to C# - API Usage Pin
User 665818-Jun-03 3:21
User 665818-Jun-03 3:21 
GeneralRe: New to C# - API Usage Pin
firat kocak18-Jun-03 3:52
firat kocak18-Jun-03 3:52 
GeneralRe: New to C# - API Usage Pin
User 665818-Jun-03 5:23
User 665818-Jun-03 5:23 
GeneralRe: New to C# - API Usage Pin
firat kocak18-Jun-03 20:26
firat kocak18-Jun-03 20:26 

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.