From: santapanda on
Hello again,

My problem with SP_DEVINFO_DATA cbSize was resolved. But then I attempted
to apply the same logic to a SP_DEVINFO_LIST_DETAIL_DATA structure and I'm
getting the same "The supplied user buffer is not valid for the requested
operation." after using the object in a SetupDixx method.

That error is generated when I tried the following struct definitions and
setting for cbSize:

*****
[StructLayout(LayoutKind.Sequential)]
public struct SP_DEVINFO_LIST_DETAIL_DATA
{
public UInt32 cbSize;
public System.Guid classGuid;
public IntPtr remoteMachineHandle;
public string RemoteMachineName;
}

SP_DEVINFO_LIST_DETAIL_DATA dList = new SP_DEVINFO_LIST_DETAIL_DATA();

dList.cbSize = (UInt32) Marshal.SizeOf(dList);

***********

Per a suggestion from another forum poster, I tried this struct definition:

***************
public const int MAX_PATH = 260;
public const int SP_MAX_MACHINENAME_LENGTH = (MAX_PATH + 3);

[StructLayout(LayoutKind.Sequential)]
public struct SP_DEVINFO_LIST_DETAIL_DATA
{
[MarshalAs(UnmanagedType.U4)]
public UInt32 cbSize;

[MarshalAs(UnmanagedType.Struct)]
public System.Guid classGuid;

[MarshalAs(UnmanagedType.SysInt)]
public IntPtr remoteMachineHandle;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = SP_MAX_MACHINENAME_LENGTH]
public char[] RemoteMachineName;
}
*****************
This still produced the same error. However, since I'm developing on a
64-bit machine, I changed "UnmanagedType.U4" to "UnmanagedType.U8", and got a
different error:

"Type SP_DEVINFO_LIST_DETAIL_DATA cannot be marshaled as an unmanaged
structure; no meaningful size or offset can be computed."

I can't seem to find others using this structure in P/Invoke examples. Does
anyone have any other ideas?

Thanks!

From: Doron Holan [MSFT] on
are you just blindly trying to brute force this?

this is the native definition

typedef struct _SP_DEVINFO_LIST_DETAIL_DATA_W {
DWORD cbSize;
GUID ClassGuid;
HANDLE RemoteMachineHandle;
WCHAR RemoteMachineName[SP_MAX_MACHINENAME_LENGTH];
} SP_DEVINFO_LIST_DETAIL_DATA_W, *PSP_DEVINFO_LIST_DETAIL_DATA_W;


the marshaller has no idea that string RemoteMachineName must be
1) inline in the marshalled structure vs a pinned pointer
2) as an inlined field, a fixed size

d
--

This posting is provided "AS IS" with no warranties, and confers no rights.


"santapanda" <santapanda(a)discussions.microsoft.com> wrote in message
news:EC03E8C2-A952-4108-BC66-A457927C3083(a)microsoft.com...
> Hello again,
>
> My problem with SP_DEVINFO_DATA cbSize was resolved. But then I attempted
> to apply the same logic to a SP_DEVINFO_LIST_DETAIL_DATA structure and I'm
> getting the same "The supplied user buffer is not valid for the requested
> operation." after using the object in a SetupDixx method.
>
> That error is generated when I tried the following struct definitions and
> setting for cbSize:
>
> *****
> [StructLayout(LayoutKind.Sequential)]
> public struct SP_DEVINFO_LIST_DETAIL_DATA
> {
> public UInt32 cbSize;
> public System.Guid classGuid;
> public IntPtr remoteMachineHandle;
> public string RemoteMachineName;
> }
>
> SP_DEVINFO_LIST_DETAIL_DATA dList = new SP_DEVINFO_LIST_DETAIL_DATA();
>
> dList.cbSize = (UInt32) Marshal.SizeOf(dList);
>
> ***********
>
> Per a suggestion from another forum poster, I tried this struct
> definition:
>
> ***************
> public const int MAX_PATH = 260;
> public const int SP_MAX_MACHINENAME_LENGTH = (MAX_PATH + 3);
>
> [StructLayout(LayoutKind.Sequential)]
> public struct SP_DEVINFO_LIST_DETAIL_DATA
> {
> [MarshalAs(UnmanagedType.U4)]
> public UInt32 cbSize;
>
> [MarshalAs(UnmanagedType.Struct)]
> public System.Guid classGuid;
>
> [MarshalAs(UnmanagedType.SysInt)]
> public IntPtr remoteMachineHandle;
>
> [MarshalAs(UnmanagedType.ByValArray, SizeConst =
> SP_MAX_MACHINENAME_LENGTH]
> public char[] RemoteMachineName;
> }
> *****************
> This still produced the same error. However, since I'm developing on a
> 64-bit machine, I changed "UnmanagedType.U4" to "UnmanagedType.U8", and
> got a
> different error:
>
> "Type SP_DEVINFO_LIST_DETAIL_DATA cannot be marshaled as an unmanaged
> structure; no meaningful size or offset can be computed."
>
> I can't seem to find others using this structure in P/Invoke examples.
> Does
> anyone have any other ideas?
>
> Thanks!
>
From: Philip Ries [MSFT] on
Try using "string" type again and set the MarshalAs property to
UnmanagedType.ByValTStr or similar (keep the SizeConst part). Brute
force might answer the size question faster: try some nearby values for
cbSize, for non-Unicode 64-bit it might be around 295.

santapanda wrote:
> Hello again,
>
> My problem with SP_DEVINFO_DATA cbSize was resolved. But then I attempted
> to apply the same logic to a SP_DEVINFO_LIST_DETAIL_DATA structure and I'm
> getting the same "The supplied user buffer is not valid for the requested
> operation." after using the object in a SetupDixx method.
>
> That error is generated when I tried the following struct definitions and
> setting for cbSize:
>
> *****
> [StructLayout(LayoutKind.Sequential)]
> public struct SP_DEVINFO_LIST_DETAIL_DATA
> {
> public UInt32 cbSize;
> public System.Guid classGuid;
> public IntPtr remoteMachineHandle;
> public string RemoteMachineName;
> }
>
> SP_DEVINFO_LIST_DETAIL_DATA dList = new SP_DEVINFO_LIST_DETAIL_DATA();
>
> dList.cbSize = (UInt32) Marshal.SizeOf(dList);
>
> ***********
>
> Per a suggestion from another forum poster, I tried this struct definition:
>
> ***************
> public const int MAX_PATH = 260;
> public const int SP_MAX_MACHINENAME_LENGTH = (MAX_PATH + 3);
>
> [StructLayout(LayoutKind.Sequential)]
> public struct SP_DEVINFO_LIST_DETAIL_DATA
> {
> [MarshalAs(UnmanagedType.U4)]
> public UInt32 cbSize;
>
> [MarshalAs(UnmanagedType.Struct)]
> public System.Guid classGuid;
>
> [MarshalAs(UnmanagedType.SysInt)]
> public IntPtr remoteMachineHandle;
>
> [MarshalAs(UnmanagedType.ByValArray, SizeConst = SP_MAX_MACHINENAME_LENGTH]
> public char[] RemoteMachineName;
> }
> *****************
> This still produced the same error. However, since I'm developing on a
> 64-bit machine, I changed "UnmanagedType.U4" to "UnmanagedType.U8", and got a
> different error:
>
> "Type SP_DEVINFO_LIST_DETAIL_DATA cannot be marshaled as an unmanaged
> structure; no meaningful size or offset can be computed."
>
> I can't seem to find others using this structure in P/Invoke examples. Does
> anyone have any other ideas?
>
> Thanks!
>
From: santapanda on
Doron,

I don't have C++ experience, and, as a beginner C# programmer, I'm trying to
use these structures in a C# application. So I'm new to the Interop and
Platform Invoke technologies; I'm picking up on what others have done and I'm
trying to understand it as I go.

That being said, I don't understand your response. Are you saying the
problem is not with cbSize, but with the RemoteMachineName variable?

"Doron Holan [MSFT]" wrote:

> are you just blindly trying to brute force this?
>
> this is the native definition
>
> typedef struct _SP_DEVINFO_LIST_DETAIL_DATA_W {
> DWORD cbSize;
> GUID ClassGuid;
> HANDLE RemoteMachineHandle;
> WCHAR RemoteMachineName[SP_MAX_MACHINENAME_LENGTH];
> } SP_DEVINFO_LIST_DETAIL_DATA_W, *PSP_DEVINFO_LIST_DETAIL_DATA_W;
>
>
> the marshaller has no idea that string RemoteMachineName must be
> 1) inline in the marshalled structure vs a pinned pointer
> 2) as an inlined field, a fixed size
>
> d
> --
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> "santapanda" <santapanda(a)discussions.microsoft.com> wrote in message
> news:EC03E8C2-A952-4108-BC66-A457927C3083(a)microsoft.com...
> > Hello again,
> >
> > My problem with SP_DEVINFO_DATA cbSize was resolved. But then I attempted
> > to apply the same logic to a SP_DEVINFO_LIST_DETAIL_DATA structure and I'm
> > getting the same "The supplied user buffer is not valid for the requested
> > operation." after using the object in a SetupDixx method.
> >
> > That error is generated when I tried the following struct definitions and
> > setting for cbSize:
> >
> > *****
> > [StructLayout(LayoutKind.Sequential)]
> > public struct SP_DEVINFO_LIST_DETAIL_DATA
> > {
> > public UInt32 cbSize;
> > public System.Guid classGuid;
> > public IntPtr remoteMachineHandle;
> > public string RemoteMachineName;
> > }
> >
> > SP_DEVINFO_LIST_DETAIL_DATA dList = new SP_DEVINFO_LIST_DETAIL_DATA();
> >
> > dList.cbSize = (UInt32) Marshal.SizeOf(dList);
> >
> > ***********
> >
> > Per a suggestion from another forum poster, I tried this struct
> > definition:
> >
> > ***************
> > public const int MAX_PATH = 260;
> > public const int SP_MAX_MACHINENAME_LENGTH = (MAX_PATH + 3);
> >
> > [StructLayout(LayoutKind.Sequential)]
> > public struct SP_DEVINFO_LIST_DETAIL_DATA
> > {
> > [MarshalAs(UnmanagedType.U4)]
> > public UInt32 cbSize;
> >
> > [MarshalAs(UnmanagedType.Struct)]
> > public System.Guid classGuid;
> >
> > [MarshalAs(UnmanagedType.SysInt)]
> > public IntPtr remoteMachineHandle;
> >
> > [MarshalAs(UnmanagedType.ByValArray, SizeConst =
> > SP_MAX_MACHINENAME_LENGTH]
> > public char[] RemoteMachineName;
> > }
> > *****************
> > This still produced the same error. However, since I'm developing on a
> > 64-bit machine, I changed "UnmanagedType.U4" to "UnmanagedType.U8", and
> > got a
> > different error:
> >
> > "Type SP_DEVINFO_LIST_DETAIL_DATA cannot be marshaled as an unmanaged
> > structure; no meaningful size or offset can be computed."
> >
> > I can't seem to find others using this structure in P/Invoke examples.
> > Does
> > anyone have any other ideas?
> >
> > Thanks!
> >
> .
>
From: Doron Holan [MSFT] on
see philip's response

d

--

This posting is provided "AS IS" with no warranties, and confers no rights.


"santapanda" <santapanda(a)discussions.microsoft.com> wrote in message
news:3BBFF335-9C34-4545-A49C-1014774ED3BA(a)microsoft.com...
> Doron,
>
> I don't have C++ experience, and, as a beginner C# programmer, I'm trying
> to
> use these structures in a C# application. So I'm new to the Interop and
> Platform Invoke technologies; I'm picking up on what others have done and
> I'm
> trying to understand it as I go.
>
> That being said, I don't understand your response. Are you saying the
> problem is not with cbSize, but with the RemoteMachineName variable?
>
> "Doron Holan [MSFT]" wrote:
>
>> are you just blindly trying to brute force this?
>>
>> this is the native definition
>>
>> typedef struct _SP_DEVINFO_LIST_DETAIL_DATA_W {
>> DWORD cbSize;
>> GUID ClassGuid;
>> HANDLE RemoteMachineHandle;
>> WCHAR RemoteMachineName[SP_MAX_MACHINENAME_LENGTH];
>> } SP_DEVINFO_LIST_DETAIL_DATA_W, *PSP_DEVINFO_LIST_DETAIL_DATA_W;
>>
>>
>> the marshaller has no idea that string RemoteMachineName must be
>> 1) inline in the marshalled structure vs a pinned pointer
>> 2) as an inlined field, a fixed size
>>
>> d
>> --
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>> "santapanda" <santapanda(a)discussions.microsoft.com> wrote in message
>> news:EC03E8C2-A952-4108-BC66-A457927C3083(a)microsoft.com...
>> > Hello again,
>> >
>> > My problem with SP_DEVINFO_DATA cbSize was resolved. But then I
>> > attempted
>> > to apply the same logic to a SP_DEVINFO_LIST_DETAIL_DATA structure and
>> > I'm
>> > getting the same "The supplied user buffer is not valid for the
>> > requested
>> > operation." after using the object in a SetupDixx method.
>> >
>> > That error is generated when I tried the following struct definitions
>> > and
>> > setting for cbSize:
>> >
>> > *****
>> > [StructLayout(LayoutKind.Sequential)]
>> > public struct SP_DEVINFO_LIST_DETAIL_DATA
>> > {
>> > public UInt32 cbSize;
>> > public System.Guid classGuid;
>> > public IntPtr remoteMachineHandle;
>> > public string RemoteMachineName;
>> > }
>> >
>> > SP_DEVINFO_LIST_DETAIL_DATA dList = new SP_DEVINFO_LIST_DETAIL_DATA();
>> >
>> > dList.cbSize = (UInt32) Marshal.SizeOf(dList);
>> >
>> > ***********
>> >
>> > Per a suggestion from another forum poster, I tried this struct
>> > definition:
>> >
>> > ***************
>> > public const int MAX_PATH = 260;
>> > public const int SP_MAX_MACHINENAME_LENGTH = (MAX_PATH + 3);
>> >
>> > [StructLayout(LayoutKind.Sequential)]
>> > public struct SP_DEVINFO_LIST_DETAIL_DATA
>> > {
>> > [MarshalAs(UnmanagedType.U4)]
>> > public UInt32 cbSize;
>> >
>> > [MarshalAs(UnmanagedType.Struct)]
>> > public System.Guid classGuid;
>> >
>> > [MarshalAs(UnmanagedType.SysInt)]
>> > public IntPtr remoteMachineHandle;
>> >
>> > [MarshalAs(UnmanagedType.ByValArray, SizeConst =
>> > SP_MAX_MACHINENAME_LENGTH]
>> > public char[] RemoteMachineName;
>> > }
>> > *****************
>> > This still produced the same error. However, since I'm developing on a
>> > 64-bit machine, I changed "UnmanagedType.U4" to "UnmanagedType.U8", and
>> > got a
>> > different error:
>> >
>> > "Type SP_DEVINFO_LIST_DETAIL_DATA cannot be marshaled as an unmanaged
>> > structure; no meaningful size or offset can be computed."
>> >
>> > I can't seem to find others using this structure in P/Invoke examples.
>> > Does
>> > anyone have any other ideas?
>> >
>> > Thanks!
>> >
>> .
>>