NO

Author Topic: How to convert this sh*tcode to C?  (Read 1659 times)

Offline bitcoin

  • Member
  • *
  • Posts: 179
How to convert this sh*tcode to C?
« 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?

Code: [Select]
// <-- 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);
}

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: How to convert this sh*tcode to C?
« Reply #1 on: November 24, 2023, 08:52:11 PM »
Not easily, something wrong with that code.
Reformat it better way.
May the source be with you

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: How to convert this sh*tcode to C?
« Reply #2 on: November 24, 2023, 09:27:21 PM »
Hello, Timo!
Can you see whole code here ? https://github.com/arsher/WebView2GettingStarted
I don't understand , what means Callback<..> , -> and other


Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: How to convert this sh*tcode to C?
« Reply #4 on: November 25, 2023, 12:47:03 PM »
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!

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: How to convert this sh*tcode to C?
« Reply #5 on: November 25, 2023, 01:12:52 PM »
TimoVJL, sorry, but I can't compile your code, in PellesC .

Error in string
Code: [Select]
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.

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: How to convert this sh*tcode to C?
« Reply #6 on: November 25, 2023, 01:27:37 PM »
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/
Code it... That's all...

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: How to convert this sh*tcode to C?
« Reply #7 on: November 25, 2023, 01:39:26 PM »
Hello, Vortex
Rust is more "better"...In future we must convert sources from Rust? No..

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: How to convert this sh*tcode to C?
« Reply #8 on: November 25, 2023, 01:41:05 PM »
TimoVJL, sorry, but I can't compile your code, in PellesC .

Error in string
Code: [Select]
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.
May the source be with you

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: How to convert this sh*tcode to C?
« Reply #9 on: November 25, 2023, 02:09:31 PM »
TimoVJL, but you can compile it in MSVC? I can't . If you can - what version of studio you use?

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: How to convert this sh*tcode to C?
« Reply #10 on: November 25, 2023, 02:10:25 PM »
Hi bitcoin,

Quote
Rust is more "better"...In future we must convert sources from Rust? No..

I agree with you. Rust is just another propaganda.
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: How to convert this sh*tcode to C?
« Reply #11 on: November 25, 2023, 04:56:41 PM »
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

Code: [Select]
LIBRARY WebView2Loader.dll
EXPORTS
_CreateCoreWebView2EnvironmentWithOptions@16 = CreateCoreWebView2EnvironmentWithOptions

dll, include, libs :
https://www.nuget.org/packages/Microsoft.Web.WebView2

« Last Edit: November 26, 2023, 02:28:28 AM by TimoVJL »
May the source be with you

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: How to convert this sh*tcode to C?
« Reply #12 on: November 25, 2023, 10:54:51 PM »
TimoVJL, thank you! COM and new C++ is terrible!

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: How to convert this sh*tcode to C?
« Reply #13 on: November 26, 2023, 01:08:28 AM »
This is a quick and dirty sample, but working at least  ::).
Derived from this link .
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: How to convert this sh*tcode to C?
« Reply #14 on: November 26, 2023, 01:50:49 AM »
Thanks frankie.
Don't work in Windows 7  :(

That was an important line:
Code: [Select]
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
Code: [Select]
GetProcAddress(0x75090000 [KERNEL32.DLL], "SetThreadDescription") called from "EMBEDDEDBROWSERWEBVIEW.DLL" at address 0x66EC1D51 and returned NULL. Error: The specified procedure could not be found (127).
« Last Edit: November 26, 2023, 11:21:55 AM by TimoVJL »
May the source be with you