Search code examples
c#pinvokemarshallinginteropservices

How to marshall as the I8 type with PInvoke?


I have a UInt32 value I want to pass to an external dll using InterOpServices.

The prototype for the unmanaged code is:

[DllImport("svr.dll")]
public static extern UInt32  CreateTag (
    [MarshalAs(UnmanagedType.LPStr)] String Name,
    Object Value,
    UInt16 InitialQuality,
    bool IsWritable);

The calling code is:

int myValue = Convert.ToInt32(item); //How to marshal as I8 type
tagNumber = (UInt32)svr_DLL.CreateTag(
    DeviceName + "." + el.tagName,
    myValue, // <-- this argument
    192,
    Convert.ToBoolean(el.tagEditable));

I want to pass to the Object Value "myValue" as I8 type.

How can this be done?


Solution

  • You need to specify that on the parameter declaration: [MarshalAs(UnmanagedType.I8)]