dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 45

Thread: [RESOLVED] Re: How to learn c#

  1. #16
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,573

    Re: How to learn c#

    Quote Originally Posted by Arjay View Post
    There seems to be some confusion. A .NET Framework app is not cross platform and only runs on Windows

    [...]

    Does publishing a .NET Core console app as self-contained with a target of osx-x64 generat files that run on osx? If so, you are done for .NET Core
    Yes - .NET Core works fine now on both Windows + OS-X (although I took the route of installing .NET Core on my Mac, rather than trying the self-contained option).

    BUT... if I try to publish a .NET Framework app (for Windows) it gives me an error now in the latest VS2019. Previously it was successfully generating a setup.exe file.


    [Edit...]

    I needed to follow the 7-step solution here but it now seems to be working again....
    Last edited by John E; October 20th, 2019 at 07:45 AM.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  2. #17
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,573

    Re: How to learn c#

    Okay, dumb question coming up... I've read in various places that a C# project can somehow incorporate C++/CLI modules - but how does it do that?? Can the source modules be used directly within the C# project? Or is it just that a C# project can link to pre-built C++/CLI libraries?
    "A problem well stated is a problem half solved. - Charles F. Kettering

  3. #18
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,147

    Re: How to learn c#

    .NET is implemeted with assemblies, which have a standard interface definition. The language you choose to implenent the assembly is up to you (e.g. C#, VB.Net, C++/CLI, F#, etc.). A .NET program can use assemblies written in different languages. In .NET you don't link to an assembly per se, instead you reference it.

  4. #19
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,573

    Re: How to learn c#

    Okay - there's something I'm still not understanding... here are the properties I see for a C# app:-

    Name:  Capture5.jpg
Views: 26
Size:  26.4 KB

    At the RHS I can see those references and at the LHS I can see that it'll be building a .NET app. But here's what I see for a C++/CLI app:-

    Name:  Capture6.jpg
Views: 26
Size:  20.9 KB

    At the RHS I still see some references - but to me, the LHS just looks like a conventional C++ app (there's nothing to indicate that I'll be building for .NET).

    [Edit...] I guess this might be relevant - if I open VS2019 and list the sample projects which support .NET Core, the only languages it lists are C#, F# and Visual Basic. What about C++/CLI? Does it maybe support .NET Framework rather than .NET Core?
    Last edited by John E; October 23rd, 2019 at 03:37 AM.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  5. #20
    Join Date
    Oct 2019
    Posts
    3

    Re: How to learn c#

    Hello,
    You can use tutorial websites for learning purposes. They also provide the try now editor for the same. So, you can apply your logic and get the instant output. You also have the Microsoft official website for the c# tutorials and other help.

  6. #21
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,573

    Re: How to learn c#

    Thanks ishan_shah. I've just ordered a book from Amazon so I'll probably be reading furiously over the next week or so! Here's what I've picked up with a bit of help from CodeGuru and Wikipedia:-

    1) C++/CLI can support both managed and unmanaged code
    2) Managed code uses Assemblies (which seem to be a special kind of link lib)
    3) Managed code is the type needed for .NET
    4) .NET comes in several flavours. There's .NET Core / .NET Framework / ASP.NET and at least one other (which I can't remember)
    5) C# supports both .NET Core and .NET Framework (and possibly the others??)
    6) .NET Core is the type needed for cross-platform development (with Visual Studio)
    7) No-one seems sure which 'type' of .NET is supported by C++/CLI (though AFAICT it's not .NET Core)
    "A problem well stated is a problem half solved. - Charles F. Kettering

  7. #22
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,147

    Re: How to learn c#

    8) C++/CLI support seems to be going away like C++/CLR support did previously.

    A couple of comments:
    2) .Net assemblies are just dlls with a predefined interface. I don't have what this is called on the tip of my tongue, but think of is as what a COM interface was (except COM was a binary standard and .Net is not).
    3) not really, C++ aren't the droids you are looking for. Move along.
    4) yes. .NET framework is the older, Windows only framework while .NET Core is cross platform.
    6) yes
    7) since no one seems to know, it might be an indication to leave it behind. IMO, you don't need what C++/CLI offers - that is, the ability to have C++ code inside an assembly. I say this because .NET and .NET Core both offer the ability to PInvoke.

    With PInvoke you can call a native Win32 (or Win64) dll, written in C/C++, from your .NET (or .NET Core) code. That means the C/C++ code you can't live without can still be used - just put it inside a native dll and pinvoke to it from .NET. Seems like in .NET Core pinvoke is cross platform too.

  8. #23
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,573

    Re: How to learn c#

    Am I right in thinking that the functions called by PInvoke need to be 'C' functions? I haven't found any examples yet of it being used with C++ functions (not even static ones)
    Last edited by John E; October 24th, 2019 at 09:59 AM.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  9. #24
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,910

    Re: How to learn c#

    AFAIK, the body of the function can be c or c++ as Arjay says in post #22. Like any .dll interface, the calling arguments should be 'c' like - so POD and pointers, no classes etc.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

  10. #25
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,573

    Re: How to learn c#

    Quote Originally Posted by 2kaud View Post
    AFAIK, the body of the function can be c or c++
    That's the bit I'm not understanding.... a (non-static) C++ function needs an instance of the object to work on. How would a C++ object get created in a C# program??
    "A problem well stated is a problem half solved. - Charles F. Kettering

  11. #26
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,910

    Re: How to learn c#

    C++ objects can be defined and used in the .dll - so in that sense the dll is c++. The .dll to be used by PInvoke is created just like any other c/c++ dll - nothing special.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

  12. #27
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,147

    Re: How to learn c#

    Quote Originally Posted by John E View Post
    That's the bit I'm not understanding.... a (non-static) C++ function needs an instance of the object to work on. How would a C++ object get created in a C# program??
    Let's look at a native win32 dll. In Windows, all public api's that are exposed through dlls have a C-style interface, i.e. none take or return C++ classes. Largely the reason for doing this is C++ name mangling which causes the C++ compiler to add extra goo to the exported function names and parameters. This is a problem because there was no standard on the mangling so each compiler vendor mangled as they saw fit. Even worse, compiler vendors changed the mangling for different versions of the same compiler. So, if you had an application compiled for a C++ dll, recompiling that dll with a different C++ compiler may break the original application (without recompiling the app using the same version of compiler). Microsoft understood this from the get-go and that is why Win32 api dlls are C-styled dlls.

    Now that means, while the exported dll function signature needs to be C-style, the implementation underneath does not. Therefore inside the dll, it is certainly possible for classes to be used, instances of classes, or a class singleton internally in the dll getting the work done. The public dll may expose a function that allows a user to create an abstract object and gets back a handle, but internally a singleton may be used to store a dictionary of objects where the key is the handle and the value is a class object. If the 'object' is to be updated, a dll update function is defined that takes a handle and the list of parameters (or a struct*) to update. Internally the handle is used as the key to the dictionary and the object within the dictionary is located and updated. In this scenario, internally the dll is entirely responsible for creating and cleaning up any C++ objects (as the caller of the dll has no idea that C++ is used internally).

    Back to your question, similar to the reasons why the Win32 api set does not support dll functions that pass C++ objects, PInvoke does not support it either (but if the dll uses C++ internally, that's okay).

    That's the long winded way of saying PInvoke only supports simple data types.
    Last edited by Arjay; October 24th, 2019 at 05:43 PM.

  13. #28
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,910

    Re: How to learn c#

    PInvoke does not support it either (but if the dll uses C++ internally, that's okay).

    That's the long winded way of saying PInvoke only supports simple data types.
    One implication, of course, is that you can't have several .dll functions that differ only by argument types as c-style linkage is used (name only).
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

  14. #29
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,147

    Re: How to learn c#

    Quote Originally Posted by 2kaud View Post
    One implication, of course, is that you can't have several .dll functions that differ only by argument types as c-style linkage is used (name only).
    Depends on how the dll exports its functions (for example, using a def file will support exporting multiple functions with the same signature).

  15. #30
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,910

    Re: How to learn c#

    Quote Originally Posted by Arjay View Post
    Depends on how the dll exports its functions (for example, using a def file will support exporting multiple functions with the same signature).
    Yeah. I'd forgotten about def files. I haven't used them since about oh windows 3.11
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)