Hello, could anybody help me and convert these 20 lines in Pascal to C++? (As I need to compile it by VS as desktop win32 arm EXE for jail-broken W8-1 RT.) Thanks. Code: program Shutdown; {$apptype GUI} {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} ComObj { you can add units after this }; var shell: Variant; {$R *.res} begin shell := CreateOleObject('Shell.Application'); shell.ShutdownWindows; end.
Code: #define COBJMACROS #include <windows.h> #include <shldisp.h> #include <shlguid.h> int main() { IShellDispatch *shell; CoInitialize(NULL); CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, &IID_IShellDispatch, (void **)&shell); // In C++ may become shell->ShutdownWindows() IShellDispatch_ShutdownWindows(shell); }
And for the sake of completeness, C++ is almost the same: Code: #include <windows.h> #include <shldisp.h> #include <shlguid.h> int main() { IShellDispatch *shell; CoInitialize(NULL); CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&shell); shell->ShutdownWindows(); } tip: Try to avoid C++ in Windows, it's not pretty and it will never will. Either use C and Win32 if you need to do something low level. VB/Pascal/C# for everything fancy, including COM interfaces.
@moderate: Use this to compile the source code in the first post that vyvojar made. http://www.smorgasbordet.com/pellesc/
Nice translation! "Try to avoid C++ in Windows" ?? Why would you say this? Choice of language is a very personal matter if the choice is free. Almost all Windows desktop programming is done in C++, more or less in ATL style. Just look at the Chrome code base for example. Not to mention almost all games. Classic Windows system code is a mix of C code from the 80s and C++ from 90s and 00s. Implementing COM in C? No thanks. VB/Pascal/C# all have performance issues, but I guess you mention these because of the GUI implementation. However, I agree with you C code is cleaner than C++ and perhaps more esthetic appealing.
I never understood why though. stdcall being standard in COM? The WDK build assumed stdcall no matter what. I have no idea how new Windows code looks like, but my guess is there's a lot of modern C++ with a C interface to conform to older code. Except for PowerShell, was there ever any windows system code written in C# or .NET? WinRT still feels like a thin layer in Windows 10, so my guess is Windows 10 is still 99% the same old C/C++ base written in the 80s-90s, although patched numerous times. But few know for sure.