Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Managed C++ server side executables ?

Managed C++ server side executables ?

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpquestionc++sysadmintutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jerry Evans
    wrote on last edited by
    #1

    Hi all Is it possible to run MC++ apps from (for example) a C# .NET web application ? I'll be checking with the host but was wondering if anyone else had done this or similiar. BTW the app in question 'brands' .EXE files for registered customers and I'd prefer not to port the existing code to C# etc. TIA Jerry

    L 1 Reply Last reply
    0
    • J Jerry Evans

      Hi all Is it possible to run MC++ apps from (for example) a C# .NET web application ? I'll be checking with the host but was wondering if anyone else had done this or similiar. BTW the app in question 'brands' .EXE files for registered customers and I'd prefer not to port the existing code to C# etc. TIA Jerry

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Why do u wanna run it as an app? Just load it as an assembly reference! :) leppie::AllocCPArticle("Zee blog");
      Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

      J 1 Reply Last reply
      0
      • L leppie

        Why do u wanna run it as an app? Just load it as an assembly reference! :) leppie::AllocCPArticle("Zee blog");
        Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

        J Offline
        J Offline
        Jerry Evans
        wrote on last edited by
        #3

        Go on. Gimme a bit more detail :-))

        E H 2 Replies Last reply
        0
        • J Jerry Evans

          Go on. Gimme a bit more detail :-))

          E Offline
          E Offline
          E L Golpe
          wrote on last edited by
          #4

          One of the major benefits of Microsoft® .NET is that it provides a language-independent development system. You can write classes in Visual Basic®, C++, C#—whatever—and use them in other languages; you can even derive from classes in a different language. But what happens when you want to call some old-school unmanaged DLL? You have to somehow translate .NET objects into the structs, char*'s, and function pointers C expects. In techno lingo, your parameters must be marshaled. Marshaling is a big topic, but luckily you don't have to know much to get the job done. To call a DLL function from C#, first you must provide a declaration, something programmers using Visual Basic have been doing for years. In C#, it's DllImport: using System.Runtime.InteropServices; // DllImport public class Win32 { [DllImport("User32.Dll")] public static extern void SetWindowText(int h, String s); } In C#, you use DllImport to tell the compiler where the entry point lives and bundle your wrapper functions inside a class. You can give this class any name you like; I chose Win32. You can even put the class inside a namespace. To compile Win32API.cs, type: csc /t:library /out:Win32API.dll Win32API.cs Now you have a Win32API.dll you can use in any C# project. using Win32API; int hwnd = // get it... String s = "I'm so cute." Win32.SetWindowText(hwnd, s); Practice sesquipedalianism! ;)

          J 1 Reply Last reply
          0
          • J Jerry Evans

            Go on. Gimme a bit more detail :-))

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            The .NET Framework includes the base class library (BCL) and the common language runtime (CLR). The CLR just-in-time compiles (jit's) intermediate language (IL, or more specifically MSIL) and executes it. Languages that target the CLR (MC++, C#, VB.NET, J#, PERL.NET, etc.) compile to IL in the form of assemblies, which are executable files (.exe, .dll) that contain 0 or more modules (compiled code), 0 or more embedded resources, various assembly attributes, and a manifest (like a plane or boat passenger manifest) of all that stuff in the assembly. So, it doesn't matter which language you use they all compile to assemblies using IL. Make yourself a Managed DLL project for MC++ and puts some classes into it. Make a Windows Forms application (or something) in C#. If both of these projects are in VS.NET in a single solution, right-click on the Windows Forms project and click Add Reference. Click the Project tab and select your other project. Otherwise, click the .NET tab and browse for the MC++ assembly. Use classes from the MC++ assembly and compile your app. Viola'! This is - in essence - no different from library bindings in Win32 or any other programming platform. It's all in the docs! Consider yourself educated - now go out and read the docs to further your education! :rolleyes:

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            J 1 Reply Last reply
            0
            • E E L Golpe

              One of the major benefits of Microsoft® .NET is that it provides a language-independent development system. You can write classes in Visual Basic®, C++, C#—whatever—and use them in other languages; you can even derive from classes in a different language. But what happens when you want to call some old-school unmanaged DLL? You have to somehow translate .NET objects into the structs, char*'s, and function pointers C expects. In techno lingo, your parameters must be marshaled. Marshaling is a big topic, but luckily you don't have to know much to get the job done. To call a DLL function from C#, first you must provide a declaration, something programmers using Visual Basic have been doing for years. In C#, it's DllImport: using System.Runtime.InteropServices; // DllImport public class Win32 { [DllImport("User32.Dll")] public static extern void SetWindowText(int h, String s); } In C#, you use DllImport to tell the compiler where the entry point lives and bundle your wrapper functions inside a class. You can give this class any name you like; I chose Win32. You can even put the class inside a namespace. To compile Win32API.cs, type: csc /t:library /out:Win32API.dll Win32API.cs Now you have a Win32API.dll you can use in any C# project. using Win32API; int hwnd = // get it... String s = "I'm so cute." Win32.SetWindowText(hwnd, s); Practice sesquipedalianism! ;)

              J Offline
              J Offline
              Jerry Evans
              wrote on last edited by
              #6

              Indeed and Thanks. My question was obviously not well phrased. Given that I have a working VC++ console app I could compile it for IL instead of native code. Would this package then run on a remotely hosted .NET server along with my Web Service ? Would this be true for an unmanaged (but still compiled to IL) DLL ? I am all too familiar with marshalling etc :-)) And I must confess that I took the plunge and wrote an analogue in C# on the grounds that it would have to be done one day ! Jerry

              H 1 Reply Last reply
              0
              • H Heath Stewart

                The .NET Framework includes the base class library (BCL) and the common language runtime (CLR). The CLR just-in-time compiles (jit's) intermediate language (IL, or more specifically MSIL) and executes it. Languages that target the CLR (MC++, C#, VB.NET, J#, PERL.NET, etc.) compile to IL in the form of assemblies, which are executable files (.exe, .dll) that contain 0 or more modules (compiled code), 0 or more embedded resources, various assembly attributes, and a manifest (like a plane or boat passenger manifest) of all that stuff in the assembly. So, it doesn't matter which language you use they all compile to assemblies using IL. Make yourself a Managed DLL project for MC++ and puts some classes into it. Make a Windows Forms application (or something) in C#. If both of these projects are in VS.NET in a single solution, right-click on the Windows Forms project and click Add Reference. Click the Project tab and select your other project. Otherwise, click the .NET tab and browse for the MC++ assembly. Use classes from the MC++ assembly and compile your app. Viola'! This is - in essence - no different from library bindings in Win32 or any other programming platform. It's all in the docs! Consider yourself educated - now go out and read the docs to further your education! :rolleyes:

                -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                J Offline
                J Offline
                Jerry Evans
                wrote on last edited by
                #7

                Thanks Heath. PLease see my reply to the previous post. Jerry

                1 Reply Last reply
                0
                • J Jerry Evans

                  Indeed and Thanks. My question was obviously not well phrased. Given that I have a working VC++ console app I could compile it for IL instead of native code. Would this package then run on a remotely hosted .NET server along with my Web Service ? Would this be true for an unmanaged (but still compiled to IL) DLL ? I am all too familiar with marshalling etc :-)) And I must confess that I took the plunge and wrote an analogue in C# on the grounds that it would have to be done one day ! Jerry

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  Just because something is written "in .NET" doesn't make it remotable. It has to extend MarshalByObjectRef or be a value type and be serializable (in most cases, attributed with SerializableAttribute). Something has to host the remote object, too. For instance, just having a console app won't work. Now, a console app that registers a well-known object (WKO) either via code or a config file (latter is preferable for easy changes) and keeps itself running (waits for a quit command of sorts) would work. Clients would connect to that WKO. The documentation about .NET remoting is okay, at least if you already have some idea of what it does. If you don't, I suggest you get the book from MSPress entitled .NET Remoting (at www.microsoft.com/mspress/books/6172.asp).

                  -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                  J 1 Reply Last reply
                  0
                  • H Heath Stewart

                    Just because something is written "in .NET" doesn't make it remotable. It has to extend MarshalByObjectRef or be a value type and be serializable (in most cases, attributed with SerializableAttribute). Something has to host the remote object, too. For instance, just having a console app won't work. Now, a console app that registers a well-known object (WKO) either via code or a config file (latter is preferable for easy changes) and keeps itself running (waits for a quit command of sorts) would work. Clients would connect to that WKO. The documentation about .NET remoting is okay, at least if you already have some idea of what it does. If you don't, I suggest you get the book from MSPress entitled .NET Remoting (at www.microsoft.com/mspress/books/6172.asp).

                    -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                    J Offline
                    J Offline
                    Jerry Evans
                    wrote on last edited by
                    #9

                    Sure but I was not asking about remoting. Can a .NET service invoke (using the Process class) a process written in unmanaged C++ but compiled to IL rather than native code ? Jerry

                    H 1 Reply Last reply
                    0
                    • J Jerry Evans

                      Sure but I was not asking about remoting. Can a .NET service invoke (using the Process class) a process written in unmanaged C++ but compiled to IL rather than native code ? Jerry

                      H Offline
                      H Offline
                      Heath Stewart
                      wrote on last edited by
                      #10

                      The Process class can start any process executable, regardless of how it compiled (i.e., it doesn't matter if it is a VB executable, unmanaged C++, managed C++ or other from any other languages targeting the CLR, compiled PERL exectable, etc.). Also, any C++ application compiled to IL is managed (save the purely native functions). You can't compiled to IL and have an unmanaged executable.

                      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups