Dear José,
I'm trying to embed code in following post http://www.jose.it-berater.org/smfforum/index.php?topic=2709.msg8089#msg8089
to be used from a DLL but it seems not working and not error seems reported (well, not tested very deeply so my sentence can be in-accurate).
When DLL starts I use:
CoInitialize ByVal %Null
and when DLL is released I use:
CoUninitialize
Do you see any problem on using that code from a DLL?
What I'm trying to achieve is to add WebBrowser control to thinBasic arsenal to be able to use html for user interface but at the same time been able to interact with html controls (mainly textbox and buttons, ...). TO be able to use in thinBasic I need to be able to use web control from a dll.
Thanks a lot
Eros
In order to give more info, CreateWindowEx fails to create the control. The following:
hCtl = CreateWindowEx(0, $OC_CLASSNAME, "Shell.Explorer", %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP, _
0, 0, 0, 0, hWnd, hID, GetModuleHandle(""), ByVal %Null)
Returns hCtl = 0
Ciao
Eros
Quote
When DLL starts I use:
CoInitialize ByVal %Null
and when DLL is released I use:
CoUninitialize
Do you see any problem on using that code from a DLL?
"Because there is no way to control the order in which in-process servers are loaded or unloaded, do not call CoInitialize, CoInitializeEx, or CoUninitialize from the DllMain function."
http://msdn.microsoft.com/en-us/library/ms678543.aspx
You should try to call CoInitialize or OleInitialize at the very start of the application and CoUnitialize at the very end, instead of in the DLL, because the new compilers now initialize the COM library in all threads.
When using the WebBrowser control, you should use OleInitialize instead of CoInitialize.
Quote
CreateWindowEx fails to create the control
If the "OC_WIN32" is registered in a DLL, you need to make it global.
Change:
wcex.style = 0
to:
wcex.style = %CS_GLOBALCLASS
in the OC_WinInit function in OLECON.INC.
BTW I'm going to change the code in OLECON.INC to:
#IF %PB_EXE = 1
wcex.style = 0
#ELSE
wcex.style = %CS_GLOBALCLASS
#ENDIF
when PB 9.01 will be released.
Ok, thanks José. All is working fine now.
You already suggested me in the past about %CS_GLOBALCLASS but I forgot it, sorry.
>If the "OC_WIN32" is registered in a DLL, you need to make it global.
Not by default, the CW should then use the same instance handle as used during registerwindow.
Global class is for incomplete.. o well, you know what i mean.
I know, but DDTer's use PBMAIN and ThinBasic nothing. It is easier to use CS_GLOBALCLASS than having to trying to convince them to use WINMAIN (too much typing to some :) )
Thanks to José code and help, I was successfully able to embed a web browser control into thinBasic user interface module.
I was also able to add possibility to interact with html elements reading and setting data from inside thinBasic scripts. I think this will open a lot of possibilities to create nice looking applications using html code and at the same time interact with elements to set and collect data.
Now I'm going to connect web control events with thinBasic script callbacks functions (thinBasic language has callbacks simulated that act exactly like real compiled callbacks from ascript point of vew).
I know how to do it but in order to be able to do it I need to have the handle of the web control firing the event from inside "onclick" method in Class "CHTMLDocumentEvents2" (I'm again referring to José example at http://www.jose.it-berater.org/smfforum/index.php?topic=2709.msg8089#msg8089 )
Thanks in advance for any help.
Eros
1.- Add an instance variable to both the CDWebBrowserEvents2 and CHTMLDocumentEvents2 classes:
INSTANCE m_hwnd AS DWORD
2.- Add the following method to both the CDWebBrowserEvents2 and CHTMLDocumentEvents2 classes:
METHOD SetHwnd <999999> (BYVAL hwnd AS DWORD)
m_hwnd = hwnd
END METHOD
3.- After calling
' Connect to the events fired by the control
pWBEvents = CLASS "CDWebBrowserEvents2"
EVENTS FROM pIWebBrowser2 CALL pWBEvents
add the following:
pWBEvents.SetHwnd GetDlgItem(hWnd, %IDC_IEWB)
4.- In the DownloadComplete event, after:
' Connect to the events fired by the page
pHTMLDocumentEvents2 = CLASS "CHTMLDocumentEvents2"
IF ISNOTHING(pHTMLDocumentEvents2) THEN EXIT METHOD
EVENTS FROM pHTMLDocument2 CALL pHTMLDocumentEvents2
add the following:
pHTMLDocumentEvents2.SetHwnd m_hwnd
1000 thanks !
I've implemented your suggestion both in thinBasic and in your example EX_OC_WB_WebGui_02.BAS
While in your example EX_OC_WB_WebGui_02.BAS events are working perfectly, in thinBasic events are fired twice.
Seems events handing are "installed" twice.
Searching reasons ...