PInvoke SetupVerifyInfFile() C#

Announcements and discussion for PInvoke

Moderators: Luke Jefferson, Robert

PInvoke SetupVerifyInfFile() C#

Postby tttony » Sun Feb 03, 2013 9:30 pm

Hi everybody

I'm having problems with SetupVerifyInfFile() in C#, on pinvoke.net 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:

Code: Select all
       [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)
{
    SP_ALTPLATFORM_INFO_V2 pinfo = new SP_ALTPLATFORM_INFO_V2();
    pinfo.cbSize =(uint)Marshal.SizeOf(pinfo);
    //pinfo.Platform = VER_PLATFORM_WIN32_NT;


    SP_INF_SIGNER_INFO pfname = new SP_INF_SIGNER_INFO();
    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

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Code: Select all
typedef struct _SP_ALTPLATFORM_INFO_V2 {
  DWORD cbSize;
  DWORD Platform;
  DWORD MajorVersion;
  DWORD MinorVersion;
  WORD  ProcessorArchitecture;
  WORD  Flags;
  DWORD FirstValidatedMajorVersion;
  DWORD FirstValidatedMinorVersion;
} SP_ALTPLATFORM_INFO_V2, *PSP_ALTPLATFORM_INFO_V2;


And the SetupVerifyInfFile() in C language:

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Code: Select all
BOOL SetupVerifyInfFile(
  __in   PCWSTR InfName,
  __in   PSP_ALTPLATFORM_FORM AltPlatformInfo,
  __out  PSP_INF_SIGNER_INFO_W InfFileName
);


Thanks in advance!
tttony
 
Posts: 1
Joined: Sun Feb 03, 2013 9:07 pm

Postby Brian Donahue » Tue Feb 05, 2013 1:32 pm

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
Code: Select all
[StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct UNICODE_STRING...

And trying to force Marshal to use certain unmanaged datatypes like this:
Code: Select all
void DefineDocument([MarshalAs(UnmanagedType.LPWStr)] String url,
...
                                 [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedDocumentWriter RetVal);


Good luck!
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am


Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests