PInvoke SetupVerifyInfFile() C#

tttonytttony Posts: 2
edited February 5, 2013 7:32AM in PInvoke.Net
Hi everybody

I'm having problems with SetupVerifyInfFile() in C#, on there are no examples so I'm here looking for some light

The function raises an exception PInvokeStackImbalance, after of a deep research on internet the exception it's raised because the Type of the variables

This is the C# code:
       [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct SP_ALTPLATFORM_INFO_V2
            public uint cbSize;

            public uint Platform;
            public uint MajorVersion;
            public uint MinorVersion;

            public uint ProcessorArchitecture;
            public uint Flags;

            public uint FirstValidatedMajorVersion;
            public uint FirstValidatedMinorVersion;

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct SP_INF_SIGNER_INFO
            public Int32 cbSize;
            public string CatalogFile;
            public string DigitalSigner;
            public string DigitalSignerVersion;
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupVerifyInfFile([MarshalAs(UnmanagedType.LPTStr)] string InfName, 
                                                    SP_ALTPLATFORM_INFO_V2 AltPlatformInfo, 
                                                    out SP_INF_SIGNER_INFO InfFileName);

static void Main(string[] args)
    pinfo.cbSize =(uint)Marshal.SizeOf(pinfo);
    //pinfo.Platform = VER_PLATFORM_WIN32_NT;

    pfname.cbSize = Marshal.SizeOf(pfname);

    if (SetupVerifyInfFile(@"C:\WINDOWS\INF\OEM12.INF", pinfo, out pfname)) // <-- The exception PInvokeStackImbalance it's raised here!

The problem is in SP_ALTPLATFORM_INFO_V2 struct, if I comment all the inside variables it does not raise the exception so the SP_INF_SIGNER_INFO struct it's fine but obviously the function return FALSE

I have changed the variables types to uint, int, Int16, Int32, Int64... but without good results

Here is the C language code of the SP_ALTPLATFORM_INFO_V2 struct ... 85%29.aspx
typedef struct _SP_ALTPLATFORM_INFO_V2 {
  DWORD cbSize;
  DWORD Platform;
  DWORD MajorVersion;
  DWORD MinorVersion;
  WORD  ProcessorArchitecture;
  WORD  Flags;
  DWORD FirstValidatedMajorVersion;
  DWORD FirstValidatedMinorVersion;

And the SetupVerifyInfFile() in C language: ... 85%29.aspx
BOOL SetupVerifyInfFile(
  __in   PCWSTR InfName,
  __in   PSP_ALTPLATFORM_FORM AltPlatformInfo,
  __out  PSP_INF_SIGNER_INFO_W InfFileName

Thanks in advance!


  • Brian DonahueBrian Donahue Posts: 6,590 New member
    The PInvoke forum is to ask for or comment on content of the PInvoke website, and does not offer any code help. Probably Stack Overflow is a better place to ask this sort of question.

    In my experience, you have to be careful with structs and make sure the data length adds up. I've also used a lot of attributes that seem to help sometimes like
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
            public struct UNICODE_STRING...
    And trying to force Marshal to use certain unmanaged datatypes like this:
    void DefineDocument([MarshalAs(UnmanagedType.LPWStr)] String url,
                                     [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedDocumentWriter RetVal);

    Good luck!
Sign In or Register to comment.