سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

UnmanagedType is a enum, so you can try Enum.Parse method:

string value = "9";
UnmanagedType i8 = (UnmanagedType)Enum.Parse(typeof(UnmanagedType), value);

Hope this helpful to you.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top