ehelin Posted October 19, 2005 Posted October 19, 2005 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 Quote
Leaders dynamic_sysop Posted October 19, 2005 Leaders Posted October 19, 2005 if you look on msdn at the way api's 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 window's 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. Quote
VagabondSW Posted October 19, 2005 Posted October 19, 2005 In Visual Basic, the Directional Attributes will determine whether you use ByRef or ByVal when defining arguments for a field or function. http://msdn.microsoft.com/library/en-us/cpguide/html/interopmarshalrules2.gif Quote "Never ascribe to malice that which can adequately be explained by incompetence." -- Napolean Bonaparte
Recommended Posts