I have several methods imported from native.dll using the following syntax:
internal static class DllClass {
[DllImport("Example.dll", EntryPoint = "ExampleFunction")]
public static extern int ExampleFunction([Out] ExampleStruct param);
}
Now, since I indicated paramhow [Out], I would expect at least one of the following snippets to be valid:
ExampleStruct s;
DllCass.ExampleFunction(s);
ExampleStruct s;
DllCass.ExampleFunction([Out] s);
ExampleStruct s;
DllCass.ExampleFunction(out s);
However, none of them work. The only way I worked with is to initialize s.
ExampleStruct s = new ExampleStruct();
DllCass.ExampleFunction(s);
I managed to fix this by rewriting the first code snippet to the following code, but that seems redundant.
internal static class DllClass {
[DllImport("Example.dll", EntryPoint = "ExampleFunction")]
public static extern int ExampleFunction([Out] out ExampleClass param);
}
I read. What is the difference between [Out] and out in C #? And because the accepted answer says that [Out]and outare equivalent in the context, he left me puzzled why it did not work for me, and if my "solution" approach.
? out? [Out]?