문제

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