Red Gate forums :: View topic - PInvoke SetupVerifyInfFile() C#
Return to RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net forum

PInvoke SetupVerifyInfFile() C#

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message

Joined: 03 Feb 2013
Posts: 1

PostPosted: Sun Feb 03, 2013 9:30 pm    Post subject: PInvoke SetupVerifyInfFile() C# Reply with quote

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


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:

BOOL SetupVerifyInfFile(
  __in   PCWSTR InfName,
  __in   PSP_ALTPLATFORM_FORM AltPlatformInfo,
  __out  PSP_INF_SIGNER_INFO_W InfFileName

Thanks in advance!
Back to top
View user's profile Send private message
Brian Donahue

Joined: 23 Aug 2004
Posts: 6678

PostPosted: Tue Feb 05, 2013 1:32 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group