dylib | Cell 2 | set mouse position | Search

The testEdge function loads a dynamic library (005.dll) using node-api-dotnet and creates an instance of the Rosetta.Euler class from it, then calls its Main method. The function is exported as a module, making it available for use in other parts of the application.

Run example

npm run import -- "test a csharp dylib"

test a csharp dylib


const path = require('path')
const dynamicLib = path.join(__dirname, '../Resources/Projects/rosetta-euler/csharp/005/Debug/net9.0/osx-arm64/005.dll')
//const dynamicLib = path.join(__dirname, '../Resources/Projects/rosetta-euler/csharp/005/005.dll')

/*
function moveMouse(x, y) {
  open({
    library: 'mouse', // key
    path: path.join(__dirname, dynamicLib) // path
  })
  let result = load({
    library: "mouse", // path to the dynamic library file
    funcName: 'main', // the name of the function to call
    retType: DataType.BigInt, // the return value type
    paramsType: [DataType.I32, arrayConstructor({
      type: DataType.StringArray,
      length: 1
    })], // the parameter types
    paramsValue: [0, ['']] // the actual parameter values
    // freeResultMemory: true, // whether or not need to free the result of return value memory automatically, default is false
  })
  console.log(result)
  close('mouse')
  return result
}
*/

//const edge = require('edge-js');
const dotnet = require('node-api-dotnet');

async function testEdge() {
  
  dotnet.load(dynamicLib);

  /*
  const Main = edge.func({
    assemblyFile: dynamicLib,
    typeName: 'Rosetta.Euler',
    methodName: 'Calculate' // Must be a static method
  });

  console.log('it works: ', await Main([]));
  */

  console.log(dotnet)
  const Euler = dotnet.Rosetta.Euler;
  const myObject = new Euler()
  //console.log(await myObject.Calculate([]))
  Euler.Main([])
}


module.exports = testEdge

What the code could have been:

const dynamicLib = require.resolve(path.join('../Resources/Projects/rosetta-euler/csharp/005/Debug/net9.0/osx-arm64/005.dll'));
const dotnet = require('node-api-dotnet');

/**
 * Load the dynamic library and call the Main function.
 * @returns {Promise} The result of the Main function.
 */
async function testEdge() {
  try {
    // Load the dynamic library
    await dotnet.load(dynamicLib);

    // Get the Rosetta.Euler class
    const Euler = dotnet.Rosetta.Euler;

    // Create an instance of the class
    const myObject = new Euler();

    // Call the Main function
    const result = await myObject.Main([]);

    console.log('Result:', result);
  } catch (error) {
    // Handle any errors that occur
    console.error('Error:', error);
  }
}

// Export the testEdge function
module.exports = testEdge;

Code Breakdown

Dependencies and Variables

Functions

testEdge Function

Notes

Exposed Function