[Help:] Please, how rewrite these 20 lines in Pascal to C++?

Discussion in 'Mixed Languages' started by moderate, May 22, 2016.

  1. moderate

    moderate MDL Guru

    Aug 31, 2009
    2,619
    2,120
    90
    #1 moderate, May 22, 2016
    Last edited by a moderator: Apr 20, 2017
    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.
    
     
  2. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,502
    3,684
    120
    #2 Michaela Joy, Aug 22, 2016
    Last edited: May 5, 2017
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. vyvojar

    vyvojar MDL Novice

    Aug 10, 2016
    23
    24
    0
    #3 vyvojar, Aug 22, 2016
    Last edited by a moderator: Apr 20, 2017
    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);
    }
    
     
  4. vyvojar

    vyvojar MDL Novice

    Aug 10, 2016
    23
    24
    0
    #4 vyvojar, Aug 22, 2016
    Last edited by a moderator: Apr 20, 2017
    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.
     
  5. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,502
    3,684
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Tiger-1

    Tiger-1 MDL Guru

    Oct 18, 2014
    2,695
    2,697
    90
    #6 Tiger-1, Dec 13, 2016
    Last edited by a moderator: Apr 20, 2017
    thanks a lot for very useful info dude :worthy:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...