Pelles C forum
C language => Windows questions => Topic started by: bitcoin on November 24, 2023, 06:21:04 PM
-
Can anybody tell me, what this code means and how to convert it to pure C? Is this possible?
// <-- WebView2 sample code starts here -->
// Step 3 - Create a single WebView within the parent window
// Locate the browser and set up the environment for WebView
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
[hWnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWnd
env->CreateCoreWebView2Controller(hWnd, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
[hWnd](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {
if (controller != nullptr) {
webviewController = controller;
webviewController->get_CoreWebView2(&webviewWindow);
}
-
Not easily, something wrong with that code.
Reformat it better way.
-
Hello, Timo!
Can you see whole code here ? https://github.com/arsher/WebView2GettingStarted
I don't understand , what means Callback<..> , -> and other
-
These give some hints:
https://stackoverflow.com/questions/66820213/basic-win32-webview2-example-not-working-in-pure-c
https://github.com/MicrosoftEdge/WebView2Feedback/issues/1124
https://stackoverflow.com/questions/70768030/usage-icorewebview2environmentoptions-in-cbuilder-11
and
https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/environment-controller-core?tabs=win32cpp
https://www.nuget.org/packages/Microsoft.Web.WebView2
-
Thank you TimoVJL!
Why don't they (micro$oft) want , that we to use the C language? First in GDI+, where you can't call them with C. Yes, a visual studio (ms sdk) does not allow use flat Api! You can try it. Only PellesC includes work!
-
TimoVJL, sorry, but I can't compile your code, in PellesC .
Error in string
completedHandler->lpVtbl->AddRef = HandlerAddRef;
error #2168: Operands of '=' have incompatible types 'unsigned long int __stdcall (*const)(ICoreWebView2CreateCoreWebView2ControllerCompletedHandler (aka struct ICoreWebView2CreateCoreWebView2ControllerCompletedHandler) *)' and 'unsigned long int __stdcall (*)(LPUNKNOWN (aka struct IUnknown *))'.
error #2033: Assignment to const location.
-
Hi bitcoin,
Thank you TimoVJL!
Why don't they (micro$oft) want , that we to use the C language? First in GDI+, where you can't call them with C. Yes, a visual studio (ms sdk) does not allow use flat Api! You can try it. Only PellesC includes work!
Here are some different opinions :
https://www.quora.com/Why-does-Microsoft-use-C-as-its-main-programming-language
https://content.techgig.com/technology-guide/microsoft-azure-cto-goes-against-c-and-c-heres-why/articleshow/94473671.cms
https://analyticsindiamag.com/why-microsoft-is-dumping-c-c-for-this-new-programming-language/
-
Hello, Vortex
Rust is more "better"...In future we must convert sources from Rust? No..
-
TimoVJL, sorry, but I can't compile your code, in PellesC .
Error in string
completedHandler->lpVtbl->AddRef = HandlerAddRef;
error #2168: Operands of '=' have incompatible types 'unsigned long int __stdcall (*const)(ICoreWebView2CreateCoreWebView2ControllerCompletedHandler (aka struct ICoreWebView2CreateCoreWebView2ControllerCompletedHandler) *)' and 'unsigned long int __stdcall (*)(LPUNKNOWN (aka struct IUnknown *))'.
error #2033: Assignment to const location.
I haven't fixed it yet, perhaps frankie can do it. MSC is more flexible with code, so those examples needs fixing.
-
TimoVJL, but you can compile it in MSVC? I can't . If you can - what version of studio you use?
-
Hi bitcoin,
Rust is more "better"...In future we must convert sources from Rust? No..
I agree with you. Rust is just another propaganda.
-
TimoVJL, but you can compile it in MSVC? I can't . If you can - what version of studio you use?
i couldn't compile it with cl neither. So a bad example from net >:(
WebView2 needs this too: WebView2Loader.dll
LIBRARY WebView2Loader.dll
EXPORTS
_CreateCoreWebView2EnvironmentWithOptions@16 = CreateCoreWebView2EnvironmentWithOptions
dll, include, libs :
https://www.nuget.org/packages/Microsoft.Web.WebView2
-
TimoVJL, thank you! COM and new C++ is terrible!
-
This is a quick and dirty sample, but working at least ::).
Derived from this link (https://stackoverflow.com/questions/66820213/basic-win32-webview2-example-not-working-in-pure-c).
-
Thanks frankie.
Don't work in Windows 7 :(
That was an important line:
webviewController->lpVtbl->AddRef(webviewController); // <-- here, increase the reference count for the webviewController
Now i can remove useless code.
WebView2 runtime :
https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section
In Windows 7
GetProcAddress(0x75090000 [KERNEL32.DLL], "SetThreadDescription") called from "EMBEDDEDBROWSERWEBVIEW.DLL" at address 0x66EC1D51 and returned NULL. Error: The specified procedure could not be found (127).
-
frankie, TimoVJL,
Amazed, but not surprised, you guys got this working in plain C!
I looked over the original sources posting and my eyes started watering,
what a mess IMO.
I don't know if I'll ever use it but downloaded it in case I need something
like a nightmare to keep me awake :) or maybe just make me comatose ;)
John Z
-
Thank you frankie!
TimoVJL, can you install microsoft edge in win7? May be this technology don't wort below win8?
-
My example was developed in Windows 7, but you need WebView2 Runtime
Distribute your app and the WebView2 Runtime (http://Distribute your app and the WebView2 Runtime)
In WebView2Test1_WS_dl.zip is for Deepl and it have minimal WebView2.h
-
Hi Timo and Frankie,
WebView2 runtime is installed on my Windows 7 system and I managed to run the application,many thanks.
Some academical \ philosophical questions :
What obligated M$ to invent this ugly beast of COM? Why plain API cannot to the job of COM? Are there some commecial benefits behind the creation \ invention of COM?
Everything should be made as simple as possible but not simpler.
- Albert Einstein
"Any intelligent fool can make things bigger,
more complex, and more violent.
It takes a touch of genius -- and a lot of courage --
to move in the opposite direction."
- E. F. Schumacher
A designer knows he has achieved perfection
not when there is nothing left to add,
but when there is nothing left to take away.
- Antoine de Saint Exupery
http://oby.ro/
-
It was important part of Visual Basic developments from beginning and useful for OOP languages.
Sadly it also leads to bigger programs.
https://en.wikipedia.org/wiki/Component_Object_Model
-
Old but an interesting thread :
The Unix model is built around the idea of lightweight processes that communicate with each other, through sockets, pipes, signals, and command lines. Historically, Unix didn't have threads (the POSIX thread model is only about 10 years old IIRC), but processes on Unix have always been much cheaper than on Windows, so it was more performant to factor functionality into separate executables than to allow a single program to grow large and monolithic.
In COM, you define binary interfaces that allow shared-memory communication. COM is tied to an object-oriented paradigm. In the classic Unix model, you define stream-oriented interfaces that allow communication over pipes, without shared memory. Conceptually, this is much closer to a functional programming paradigm.
The Unix model encourages making small programs that can be easily coupled together by a lightweight "shell", while the COM model encourages making large programs that expose "components" that can be reused by other large programs. It's really an apples-and-oranges comparison, since both models provide benefits and drawbacks for different scenarios.
Of course, modern Unix systems can have COM-like facilities. Mozilla has XPCOM, a cross-platform framework built on the same principles as COM. GNOME for a long time used Bonobo, which is conceptually very similar to Microsoft OLE, which was the forerunner to COM. But recent versions of GNOME have been shifting away from Bonobo in favor of D-Bus, which is more of an event/messaging pattern.
https://stackoverflow.com/questions/3063321/is-there-an-equivalent-to-com-on-nix-systems-if-not-what-was-the-nix-approa
-
Those, who want to develop it further :)
-
Hi Timo,
Thanks, your application works fine on Windows 7 with WebView2Loader.dll
-
Very late to this, but this is fantastic. It looks great! I couldn't' believe it. Digging further, it appears you can add link callbacks to trigger actions after a link href is clicked within the viewport. This is useful for launching windows or managing calls within the application.
However, this binds one to the Edge eco-system, which is already aggressive in marketing and overriding associations from other browsers in the registry. No Edge, no WebView2.
Very cool! Thank you.