Intermixing C/C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc

    Intermixing C/C++

    Is there a way to mix in regular C or C++ code with C# code? If they can't
    be in the same file, then is there a way to use code in a .c or .cpp file in
    your Visual C# project and have it correctly compile into the program?

    Thanks,
    Marc


  • Chris Tacke, eMVP

    #2
    Re: Intermixing C/C++

    Whoops, I was thinking Compact Framework - for the full framework I'm not
    sure, so sorry if I threw out a red herring there.

    --
    Chris Tacke, eMVP
    Advisory Board Member

    ---
    Windows CE Product Manager
    Applied Data Systems


    "Marc" <macfreak2000@h otmail.com> wrote in message
    news:uiza11BjDH A.2564@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Is there a way to mix in regular C or C++ code with C# code? If they can't
    > be in the same file, then is there a way to use code in a .c or .cpp file[/color]
    in[color=blue]
    > your Visual C# project and have it correctly compile into the program?
    >
    > Thanks,
    > Marc
    >
    >[/color]


    Comment

    • Chris Tacke, eMVP

      #3
      Re: Intermixing C/C++

      Nope. The best you can do is to P/Invoke publicly exported C functions from
      a DLL.

      --
      Chris Tacke, eMVP
      Advisory Board Member

      ---
      Windows CE Product Manager
      Applied Data Systems


      "Marc" <macfreak2000@h otmail.com> wrote in message
      news:uiza11BjDH A.2564@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Is there a way to mix in regular C or C++ code with C# code? If they can't
      > be in the same file, then is there a way to use code in a .c or .cpp file[/color]
      in[color=blue]
      > your Visual C# project and have it correctly compile into the program?
      >
      > Thanks,
      > Marc
      >
      >[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Intermixing C/C++

        Chris Tacke, eMVP <ctacke@spamfre e-opennetcf.org> wrote:[color=blue]
        > Whoops, I was thinking Compact Framework - for the full framework I'm not
        > sure, so sorry if I threw out a red herring there.[/color]

        Nope, you were still completely right - a C# project in VS.NET can only
        contain C#. An assembly linked from the command line can contain
        modules created in C#, VB.NET or MC++ (or anything else that can
        produce modules, I guess!) but VS.NET doesn't allow you to do that (and
        I'd generally agree that it's something to avoid).

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Stu Smith

          #5
          Re: Intermixing C/C++

          Out of interest.... why should I want to avoid it?
          I'd love to be able to merge assemblies written in different languages, and
          even include unmanaged code, if (for instance) it were called from MC++.
          I'm writing in C#, but occasionally I want to do something unmanaged, and
          it's so much easier to go via MC++ than P/Invoke.

          "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
          news:MPG.19ebac 6db68bb6009897f 5@msnews.micros oft.com...[color=blue]
          > Chris Tacke, eMVP <ctacke@spamfre e-opennetcf.org> wrote:[color=green]
          > > Whoops, I was thinking Compact Framework - for the full framework I'm[/color][/color]
          not[color=blue][color=green]
          > > sure, so sorry if I threw out a red herring there.[/color]
          >
          > Nope, you were still completely right - a C# project in VS.NET can only
          > contain C#. An assembly linked from the command line can contain
          > modules created in C#, VB.NET or MC++ (or anything else that can
          > produce modules, I guess!) but VS.NET doesn't allow you to do that (and
          > I'd generally agree that it's something to avoid).
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: Intermixing C/C++

            Stu Smith <stuarts@remove .digita.com> wrote:[color=blue]
            > Out of interest.... why should I want to avoid it?[/color]

            Just for reasons of maintainability , I'd say. My guess is that
            different bits of VS.NET will want different project options, for
            instance - so do you show all the options on a mixed project?

            I'm sure there are ways round these questions, but I suspect they would
            cause more problems (at least for MS support) than they'd solve.
            [color=blue]
            > I'd love to be able to merge assemblies written in different languages, and
            > even include unmanaged code, if (for instance) it were called from MC++.
            > I'm writing in C#, but occasionally I want to do something unmanaged, and
            > it's so much easier to go via MC++ than P/Invoke.[/color]

            Fair enough. I've never actually looked at how MC++ works in terms of
            unmanaged code - does it still go in the same PE file?

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • Frecklefoot

              #7
              Re: Intermixing C/C++

              "Marc" <macfreak2000@h otmail.com> wrote in message news:<uiza11BjD HA.2564@TK2MSFT NGP12.phx.gbl>. ..[color=blue]
              > Is there a way to mix in regular C or C++ code with C# code? If they can't
              > be in the same file, then is there a way to use code in a .c or .cpp file in
              > your Visual C# project and have it correctly compile into the program?[/color]

              Your C# and C++ can't be in the same project, but they can be in the
              same solution (you can have several projects in one solution). How you
              hook them up after than is up to you, but MC++ would be any easy way
              to bridge the languages. We've done it several times at my company.

              If the C# is main app logic, the C++ compiles into a DLL which you
              deploy with your .exe.

              Comment

              Working...