Prev: Requires stdole Version 7.0.33 be installed in GAC ClickOnce deployment
Next: GPRS Signal Strength
From: Willy Denoyette [MVP] on 8 Mar 2007 18:36 "Rymfax" <cwalker(a)bigbangllc.com> wrote in message news:1173392770.192339.247990(a)8g2000cwh.googlegroups.com... On Mar 8, 3:50 pm, "Willy Denoyette [MVP]" <willy.denoye...(a)telenet.be> wrote: > "Rymfax" <cwal...(a)bigbangllc.com> wrote in message > > news:1173384460.483366.285820(a)p10g2000cwp.googlegroups.com... > > > Your struct should look like this (partly): > > [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Unicode)] <-----1 > public struct SP_DRVINFO_DATA > { > public int cbSize; > public int DriverType; > public IntPtr Reserved; > ... > > read more �- Hide quoted text - > > - Show quoted text - Willy, You are a GOD among men!!!! Do you think you could explain to me what the Pack = 4 does and why I need it for this structure but not any of my others? The problem is with this: public System.Runtime.InteropServices.ComTypes.FILETIME DriverDate; public ulong DriverVersion; } DriverDate, being a long (8 bytes) will be aligned at its natural boundary with the default packing (Pack = 0), that means that it will be stored at a address which is a multiple of 8. However, if you look at the preceeding fields, DriverDate would not end on such an address, so, the lay-out manager will pad the preceeding field with 4 bytes (the fixed char array), and as such render the struct incompatible (both in length and some field addresses) with what the function is expecting. When setting the Packing to 4 (the same as used in the header file) , no such padding is done and the struct length corresponds to what the function expects. Thanks! Would you like my first born? He's yours! :) Wow, but thanks, too much honor really ;-). Willy.
From: Rymfax on 8 Mar 2007 18:41 Willy, Would love your help one more time please! I'm now trying to get SetupDiGetDriverInfoDetail to work. I'm getting the same 1784L error. I was hoping you could take a look again. My struct/invoke/ code is below. The new snippet of code is just being run insde the while loop of the previous code. Thanks! Oh, and FYI, I tried this struct with and without the Pack=4. [StructLayout(LayoutKind.Sequential, Pack=4, CharSet = CharSet.Unicode)] public struct SP_DRVINFO_DETAIL_DATA { public int cbSize; public System.Runtime.InteropServices.ComTypes.FILETIME InfDate; public int CompatIDsOffset; public int CompatIDsLength; public ulong Reserved; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string SectionName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string InfFileName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string DrvDescription; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string HardwareID; } [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern bool SetupDiGetDriverInfoDetail(IntPtr DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, ref SP_DRVINFO_DATA DriverInfoData, ref SP_DRVINFO_DETAIL_DATA DriverInfoDetailData, int DriverInfoDetailDataSize, ref int RequiredSize); // New Code Snipped string infPath = ""; int drvRank = 0; SP_DRVINSTALL_PARAMS drvParams = new SP_DRVINSTALL_PARAMS(); drvParams.cbSize = Marshal.SizeOf(typeof(SP_DRVINSTALL_PARAMS)); if (SetupDiGetDriverInstallParams(devInfoSet, ref devInfoData, ref drvData, ref drvParams)) { drvRank = drvParams.Rank; } int dataSize = 2048; SP_DRVINFO_DETAIL_DATA drvInfDetail = new SP_DRVINFO_DETAIL_DATA(); drvInfDetail.cbSize = Marshal.SizeOf(typeof(SP_DRVINFO_DETAIL_DATA)); if (!SetupDiGetDriverInfoDetail(devInfoSet, ref devInfoData, ref drvData, ref drvInfDetail, dataSize, ref dataSize)) { int didErr = Marshal.GetLastWin32Error(); infPath = "blah"; } memIndex++; enumResult = SetupDiEnumDriverInfo(devInfoSet, ref devInfoData, SPDIT_COMPATDRIVER, memIndex, ref drvData);
From: Willy Denoyette [MVP] on 8 Mar 2007 19:12 "Rymfax" <cwalker(a)bigbangllc.com> wrote in message news:1173397264.560680.9230(a)30g2000cwc.googlegroups.com... > Willy, > > Would love your help one more time please! I'm now trying to get > SetupDiGetDriverInfoDetail to work. I'm getting the same 1784L > error. I was hoping you could take a look again. My struct/invoke/ > code is below. The new snippet of code is just being run insde the > while loop of the previous code. Thanks! Oh, and FYI, I tried this > struct with and without the Pack=4. > > > [StructLayout(LayoutKind.Sequential, Pack=4, CharSet = > CharSet.Unicode)] > public struct SP_DRVINFO_DETAIL_DATA > { > public int cbSize; > public System.Runtime.InteropServices.ComTypes.FILETIME > InfDate; > public int CompatIDsOffset; > public int CompatIDsLength; > public ulong Reserved; public IntPtr Reserved; Note, as I said previously, I didn't check the other structs for packing issues and the like. You really have to check the header files before defining your interop stucts (or stay with C++ :-)). Willy.
First
|
Prev
|
Pages: 1 2 Prev: Requires stdole Version 7.0.33 be installed in GAC ClickOnce deployment Next: GPRS Signal Strength |