none
Using MemoryMappedFile from a C++/CLR project RRS feed

  • Question

  • Hi

    I am trying to use MemoryMappedFile .NET class from System.IO.MemoryMappedFiles namespace. While this can be easily done from C#, I cannot find any way of using it from a C++ application. Is there a way or an equivalent API for accessing the same memory mapped file in C++ ?

    thanks

    Bogdan


    bogdan


    Wednesday, September 11, 2013 10:41 AM

Answers

  • You need to add a reference to the System.Core assembly, it's not present by default.
    • Marked as answer by Bogdan Cristea Thursday, September 12, 2013 8:01 AM
    Wednesday, September 11, 2013 8:01 PM
    Moderator

All replies

  • What kind of C++ application? You should have no problem using that class in C++/CLI application. If you have problems like compilation errors then please specify.

    On the other hand, if your application is a native C++ application then you need to use the corresponding Win32 functions: CreateFileMapping & MapViewOfFile.

    Wednesday, September 11, 2013 11:49 AM
    Moderator
  • It'a a CLR Console Application. The MemoryMappedFile class cannot be found. Also System::IO::MemoryMappedFiles namespace is not found.

    Here is a snippet:

    // TestSharedMemory.cpp : main project file.
    
    #include "stdafx.h"
    
    using namespace System;
    using namespace System::IO;
    using namespace System::IO::MemoryMappedFiles;
    
    int main(array<System::String ^> ^args)
    {
        try
        {
            MemoryMappedFile ^mmf;
        }
        catch (FileNotFoundException)
        {
        }
        Console::WriteLine(L"Hello World");
        return 0;
    }
    


    bogdan

    Wednesday, September 11, 2013 7:51 PM
  • You need to add a reference to the System.Core assembly, it's not present by default.
    • Marked as answer by Bogdan Cristea Thursday, September 12, 2013 8:01 AM
    Wednesday, September 11, 2013 8:01 PM
    Moderator
  • Which reference should i add?and where can i downlod this reference?thanks
    Friday, June 17, 2016 10:36 AM