can I use .NET classes in native code


I know C++ from the linux world, yet I'm having to do a project in VS (2010) and I'm just learning that I don't want to have anything to do with CLI. However, I'm not sure how to use some of the classes like FileSystemWatcher that seem to be part of the .NET Framework. I had it working with CLI on, but now I've turned CLI off and would just like to work with native C++.

Here is the class I'm trying to implement.

My problem is that I can't read this page in the way I'd normally read man pages. Is the .NET Framework only for CLI? Normally I'd just include a header for this class, but I see no header files, so now I'm wondering if I can even use the FileSystemWatcher class w/o CLI. Am I looking at the wrong reference pages for native classes? Its a bit confusing.

Any help much appreciated.
The major dichotomy in coding now is managed code verses unmanaged code. Unmanaged code is usually referred to as native code. I've got a book on .NET and COM interoperability (Andrew Troelsen), but never read much of it. So I can't answer your question, although you've picked a hard topic, I'll say that!

I think most of the folks here are mostly into native code, either Win32 or using some non .NET class framework, such as MFC, wxWidgets, or QT. A lot of Win32 types like myself (and I'm sure others here too) take a fairly dim view of .NET.

Folks into using the .NET framework generally use C#, VB.NET, or C++/CLI.

I think there are ways to do it though. If you are going to try it though I will say it does help if you are a genuis. The following person is who runs this forum and posted this ...

... but unfortunately for you, he uses PowerBASIC and not C++. The post shows how to host the .NET runtime using Win32 code. It would be translatable to C++ though, as everything in PowerBASIC is.

Normally I'd just include a header for this class, but I see no header files,

There's more to it than that. The .NET runtime has to be started, as well as instances of the objects within it created. It would involve considerably more than linking with *.obj or *.lib files and calling functions within them of which you have header definitions.
If you manage to install the windows libraries and actually build it to a win32 target .exe, You can deal with the runtime requirements by using wine for testing.
If you plan to stick with C++, then avoid .NET or CLI and use something like this, it has no depedencies:

Every .NET class has a winapi equivalent after all.
Last edited on
Topic archived. No new replies allowed.