Search code examples
c#c++-cli

How to call C++/Cli function with ValueType argument from C#


I am trying to call C++ function from C#.

Here is the C++ function definition,

StartRecording(DateTime^% startTimestamp, String^ recPath)

I want to call this from C#. The definition in C# shows,

StartRecording(ref ValueType startTimestamp, string recPath);

How can I call this function. Calling like,

DateTime now = DateTime.Now;
StartRecording(ref now, "Path to file");

is not compiling, Error is,

Error   CS1503  Argument 1: cannot convert from 'ref System.DateTime' to 'ref System.ValueType'

Solution

  • I ended up calling the function as follows,

    ValueType now = DateTime.Now;
    StartRecording(ref now, "Path to file");
    

    assigning DateTime object to ValueType resolved the problem.