Code Monkey home page Code Monkey logo

files.dll's Introduction

Files

Files is a DLL that help you to manipulate files.

Installation

To install files.dll, you have to put it in your project. Do put it as project reference in C# because it isn't a COM component.

Usage

files.dll is very simple to use. You only need memory allocation and destruction.

// C#

#region Manipulation of memory

public static IntPtr[] AllocateString(params string[] strings)
{
    IEnumerable<IntPtr> ptrs = new List<IntPtr>();

    foreach (string str in strings)
    {
        ptrs = ptrs.Append(Marshal.StringToHGlobalAnsi(str));
    }

    return ptrs.ToArray();
}

public static void Free(params IntPtr[] ptrs)
{
    foreach (IntPtr ptr in ptrs)
    {
        Marshal.FreeHGlobal(ptr);
    }
}

#endregion

#region Import DLL functions

#region Write to file

[DllImport("path_to_files.dll")]
public static extern IntPtr read_file(IntPtr path);

[DllImport("path_to_files.dll")]
public static extern void write_file(IntPtr path, IntPtr text);

#endregion

#region Use the functions

string filePath = @"path\to\file";
string fileContent = $"thing to write in file";

// we' allocating all the memory we need for these strings
IntPtr[] ptrAllocated = AllocateString(filePath, fileContent);

// Because it's an array we can get our pointers
IntPtr filePathPtr = ptrAllocated[0];
IntPtr fileContentPtr = ptrAllocated[1];

// We write to the desired file the desired content
write_file(filePathPtr, fileContentPtr);

// We're freeing the memory allocated before
Free(filePathPtr, fileContentPtr);
#endregion

#region Read the file

// Replace with the desired file path
string filePath = @"E:\Dev\Rust\dll\test.txt";

IntPtr valueInFile = read_file(filePathPtr);

Free(valueInFile);

#endregion

#endregion

files.dll's People

Contributors

itsmeviiper avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.