Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is [In,Out] exactly doing in the following example?

[DllImport("DllName.dll")]
public static extern int MethodFromDll([In, Out] char[] session_file, [In, Out] char[] phrase, [In] char[] indexbuild, [In, Out] char[] result);

What I have tried:

Searched online but could not find answer
Posted
Updated 14-Mar-16 6:51am
Comments
Richard MacCutchan 14-Mar-16 9:56am    
It just means that the parameter is used to pass information to the called method, and receive inforation from it. It only has meaning to the compiler.

These attributes are used to tell the compiler what data marshaling is required across the call, from the Managed to Unmanaged code and/or back (or across COM calls).
[In] -- The InAttribute Class[^] Indicates that data should be marshaled from the caller to the callee.
[Out] -- The OutAttribute Class[^] Indicates that data should be marshaled from callee back to caller.
and [In, Out] does what you would expect; it indicates that data should be marshaled in both directions.
See the Remarks in the above links.
 
Share this answer
 
v3
These are attributes telling the operating system that the parameter following the attribute is an input as well as an output parameter. In some cases, you need only one of them; and in some other cases you need both. To decide whether you need either of these attributes, you should check MSDN for the particular function you are using.

For example, consider the
[GetWindowPlacement] function, which is declared as:
C++
BOOL WINAPI GetWindowPlacement(
  _In_    HWND            hWnd,
  _Inout_ WINDOWPLACEMENT *lpwndpl
);


So it is easy to see that the lpwndpl parameter needs to be declared in your code with both of these parameters.
 
Share this answer
 
Comments
Richard MacCutchan 14-Mar-16 12:50pm    
This is nothing to do with the operating system, they are compiler directives.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900