**Developer**,
| Can't follow this. Seems to say VBByRefStr requires InOut.
That is exactly what I stated: VBByRefStr requires (can only be used for)
InOut parameters. InOut parameters are parameters that do not have an
InAttribute or an OutAttribute attached to them.
InOut parameters are parameters that are marshaled to the unmanaged world &
then marshaled back to the .NET world.
In parameters only need to be marshaled to the unmanaged world (they are
values that go into the API, are not returned.). They have the
System.Runtime.InteropServices.InAttribute attached to them.
http://msdn.microsoft.com/library/de...ClassTopic.asp
Out parameters only need to be marshaled to the .NET world (they are values
that are returned from an API). They have the
System.Runtime.InteropServices.OutAttribute attached to them.
http://msdn.microsoft.com/library/de...ClassTopic.asp
If you read the Win32 API itself, the description of the parameters indicate
if they are In, Out, or InOut.
http://msdn.microsoft.com/library/de...folderpath.asp
| Then says In or Out requires LPTStr or something similar.
Correct, as VB will attempt to put VBByRefStr if you don't include LPTStr.
VBByRefStr with InAttribute or OutAttribute is incompatible.
InAttribute & OutAttribute allow you to "optimize" the API call as they
allow you to indicate that a parameter only needs to be marshaled in a
single direction, allowing the API itself to be quicker.
In the case of SHGetFolderPath , the lpszPath is used to return a String, it
should (*should*) have the OutAttribute on it as it is a return value.
OutAttribute means you need StringBuilder as String with LPTStr is
immutable.
For an example of declaring the API see:
http://www.pinvoke.net/default.aspx/...olderPath.html
Using the Declare syntax:
Private Declare Auto Function SHGetFolderPath Lib "shell32.dll" ( _
ByVal hwndOwner As IntPtr, _
ByVal nFolder As Int32, _
ByVal hToken As IntPtr, _
ByVal dwFlags As Int32, _
<Out()> ByVal pszPath As StringBuilder _
) As Int32
InAttribute is implicit on ByVal value types. String & StringBuiler are
reference types so you need to state if they are In only or Out only,
otherwise InOut is assumed.
I find both the
www.pinvoke.net web site & Adam Nathan's book ".NET and
COM - The Complete Interoperability Guide" from SAMS press to be invaluable
when using Declare statements & P/Invoke.
Hope this helps
Jay
Hope this helps
Jay
" **Developer**" <RE*************@a-znet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
|
| > <MarshalAs(UnmanagedType.VBByRefStr)> can only be used with "InOut"
| > parameters, if you start adding InAttribute or OutAttribute to the
declare
| > statement parameters you need to give a MarshalAs with the 'regular'
| > string
| > types <MarshalAs(UnmanagedType.LPTStr)> for example, other wise you get
an
| > exception from the Marshaller.
| >
| Can't follow this. Seems to say VBByRefStr requires InOut.
| Then says In or Out requires LPTStr or something similar.
|
| What am I reading wrong?
|
|
|
| Thanks
|
|