DLLImport and <[In](), Out()>

ehelin

Well-known member
Joined
Oct 11, 2005
Messages
48
Hi:

Can anyone shed any light on the <[In](), Out()> tags sometimes associated with DLL calls?

For example, look at the hypothetical call below...in many of the examples I see on the internet, I see these in/out tags. I know that they specify the direction of the variable, but how do you determine whether the argument for a dll is in/out or some variation of both?

<DllImport("file.dll", EntryPoint:="#1")> _
Private Shared Function DSMparent(<[In](), Out()> _
ByVal arg1 As String, _
ByVal arg2 As String, _
ByVal arg3 As String, _
<[In](), Out()> ByVal arg4 As String) As String
End Function

A real example is

<DllImport("gdiplus.dll", ExactSpelling:=True, CharSet:=CharSet.Unicode)>
Friend Shared Function GdipSaveImageToFile(
ByVal image As IntPtr,
ByVal filename As String,
<[In]()> ByRef clsid As Guid,
ByVal encparams As IntPtr)
As Integer
End Function
 
if you look on msdn at the way apis are made up, you may get a better insight

[In] would be a pointer , string , int32 etc.. you are injecting in to the api call
[Out] would be a pointer etc... that you are receiving
[In] [Out] would work as both

eg: take a look at the FindWindow Api ( for C++ ) on msdn, the description of the Parameters specifies you are injecting a value in to the call.

HWND FindWindow(

LPCTSTR lpClassName, LPCTSTR lpWindowName);​
Parameters

lpClassName [in] Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.

If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.

lpWindowName [in] Pointer to a null-terminated string that specifies the window name (the windows title). If this parameter is NULL, all window names match.​
where as, the GetWindowText api holds an [Out] value, where it receives a string...
int GetWindowText(

HWND hWnd, LPTSTR lpString, int nMaxCount);​
Parameters

hWnd [in] Handle to the window or control containing the text. lpString [out] Pointer to the buffer that will receive the text. If the string is as long or longer than the buffer, the string is truncated and terminated with a NULL character. nMaxCount [in] Specifies the maximum number of characters to copy to the buffer, including the NULL character. If the text exceeds this limit, it is truncated.​
 
Back
Top