Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / August 2006

Tip: Looking for answers? Try searching our database.

Marshaling for setupapi.dll

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bullshark@gmail.com - 27 Jul 2006 20:23 GMT
We have:
[StructLayout(LayoutKind.Sequential, CharSet= CharSet.Ansi)]
public unsafe struct SP_DEVICE_INTERFACE_DETAIL_DATA {
  public int  cbSize;
  [MarshalAs(UnmanagedType.ByValArray, SizeConst=84)]
  public char[] DevicePath;
}

The setupapi.dll method SetupDiGetDeviceInterfaceDetail requires us to
call it once to find the size of the output buffer "DevicePath", and
then to call it again, after allocating the char[] to fetch the
details.

The code above is kludged to marshal a fixed size. It works fine. What
I can't seem to figure is how to accomplish this without the kludging
to a pre-determined size.

Is there no way to do this without a C library as a go-between?

This idiom occurs so often in Win32 that I find it hard to believe that
theres not a simple solution. I tried manual marshalling with
Marshal.AllocHGlobal, which was successfully used to retrieve the
details, but then extracting "DevicePath" from an IntPtr was
problematic. Marshal.PtrToStructure doesn't work on valueTypes and I
couldn't figure a way to get from (coerce) the IntPtr into a char[] for
Marshal.copy.

Thanks in advance for any ideas,

bullshark
Winista - 02 Aug 2006 16:43 GMT
See if this helps..

http://www.netomatix.com/Development/EmbedStruct.aspx

> We have:
> [StructLayout(LayoutKind.Sequential, CharSet= CharSet.Ansi)]
[quoted text clipped - 26 lines]
>
> bullshark

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.