ProGuard fails with ArrayIndexOutOfBoundsException - java-me

I'm using ProGuard during the build of a J2ME application. ProGruard fails during optimization with ArrayIndexOutOfBoundsException exception (see (1)).
The code that cause the failure is 'straintforward' : it is a method that copies 23 fields from one POJO to another (see (2)). In addition, when I comment some get/set statements, ProGruad doesn't fail (see (3)).
(1) ProGruard logs
[proguard] ProGuard, version 4.3
[proguard] Reading input...
[proguard] Reading program jar [...] (filtered)
[proguard] Reading library jar [.../WTK2.5.2/lib/midpapi21.jar]
[proguard] Reading library jar [.../WTK2.5.2/lib/cldcapi11.jar]
[proguard] Reading library jar [.../WTK2.5.2/lib/wma20.jar]
[proguard] Initializing...
[proguard] Ignoring unused library classes...
[proguard] Original number of library classes: 947
[proguard] Final number of library classes: 87
[proguard] Printing kept classes, fields, and methods...
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard] Original number of program classes: 223
[proguard] Final number of program classes: 189
[proguard] Inlining subroutines...
[proguard] Optimizing...
[proguard] Unexpected error while merging classes:
[proguard] Class = [.../TransactionEntityBuilder]
[proguard] Target class = [.../TransactionEntity]
[proguard] Exception = [java.lang.ArrayIndexOutOfBoundsException] (3113)
[proguard] java.lang.ArrayIndexOutOfBoundsException: 3113
[proguard] at proguard.classfile.editor.CodeAttributeComposer.appendInstruction(CodeAttributeComposer.java:184)
[proguard] at proguard.classfile.editor.InstructionAdder.visitConstantInstruction(InstructionAdder.java:74)
[proguard] at proguard.classfile.instruction.ConstantInstruction.accept(ConstantInstruction.java:161)
[proguard] at proguard.classfile.attribute.CodeAttribute.instructionsAccept(CodeAttribute.java:138)
[proguard] at proguard.classfile.attribute.CodeAttribute.instructionsAccept(CodeAttribute.java:110)
[proguard] at proguard.classfile.editor.AttributeAdder.visitCodeAttribute(AttributeAdder.java:262)
[proguard] at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
[proguard] at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
[proguard] at proguard.classfile.editor.MemberAdder.visitProgramMethod(MemberAdder.java:234)
[proguard] at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
[proguard] at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:439)
[proguard] at proguard.optimize.peephole.ClassMerger.visitProgramClass0(ClassMerger.java:259)
[proguard] at proguard.optimize.peephole.ClassMerger.visitProgramClass(ClassMerger.java:116)
[proguard] at proguard.classfile.visitor.ProgramClassFilter.visitProgramClass(ProgramClassFilter.java:52)
[proguard] at proguard.classfile.ProgramClass.accept(ProgramClass.java:281)
[proguard] at proguard.classfile.LibraryClass.subclassesAccept(LibraryClass.java:370)
[proguard] at proguard.classfile.visitor.SubclassTraveler.visitLibraryClass(SubclassTraveler.java:58)
[proguard] at proguard.classfile.LibraryClass.accept(LibraryClass.java:248)
[proguard] at proguard.classfile.constant.ClassConstant.referencedClassAccept(ClassConstant.java:102)
[proguard] at proguard.classfile.visitor.ReferencedClassVisitor.visitClassConstant(ReferencedClassVisitor.java:128)
[proguard] at proguard.classfile.constant.ClassConstant.accept(ClassConstant.java:91)
[proguard] at proguard.classfile.ProgramClass.superClassConstantAccept(ProgramClass.java:402)
[proguard] at proguard.optimize.peephole.HorizontalClassMerger.visitProgramClass(HorizontalClassMerger.java:82)
[proguard] at proguard.classfile.ProgramClass.accept(ProgramClass.java:281)
[proguard] at proguard.classfile.ClassPool.classesAccept(ClassPool.java:114)
[proguard] at proguard.optimize.Optimizer.execute(Optimizer.java:301)
[proguard] at proguard.ProGuard.optimize(ProGuard.java:325)
[proguard] at proguard.ProGuard.execute(ProGuard.java:114)
[proguard] at proguard.ProGuard.main(ProGuard.java:499)
(2) The method that fail
public static TransactionEntityShadow convertFromLegacy(TransactionEntity legacy) {
TransactionEntityShadow result = new TransactionEntityShadow(legacy.getService(), legacy.getAliasCode());
result.setAliasCode (legacy.getAliasCode());
result.setAmount (legacy.getAmount());
result.setBeneficiaryAccountNumber (legacy.getBeneficiaryAccountNumber());
result.setBeneficiaryId (legacy.getBeneficiaryId());
result.setBeneficiaryIdTypeId (legacy.getBeneficiaryIdTypeId());
result.setBeneficiaryMSISDN (legacy.getBeneficiaryMSISDN());
result.setBeneficiaryName (legacy.getBeneficiaryName());
result.setBeta (legacy.getBeta());
result.setBillContractNumber (legacy.getBillContractNumber());
result.setBillNumber (legacy.getBillNumber());
result.setBillSecretCode (legacy.getBillSecretCode());
result.setContractBeta (legacy.getContractBeta());
result.setCustomerKey (legacy.getCustomerKey());
result.setFeesAmount (legacy.getFeesAmount());
result.setFreeByte1 (legacy.getFreeByte1());
result.setFreeByte2 (legacy.getFreeByte2());
result.setLanguageIndex (legacy.getLanguageIndex());
result.setMerchantCode (legacy.getMerchantCode());
result.setMerchantServiceCode (legacy.getMerchantServiceCode());
result.setPinDigest (legacy.getPinDigest());
result.setService (legacy.getService());
result.setSessionKey (legacy.getSessionKey());
result.setTransactionDate (legacy.getTransactionDate());
return result;
}
(3) Commenting some lines of the method will make ProGruad not to fail
public static TransactionEntityShadow convertFromLegacy(TransactionEntity legacy) {
TransactionEntityShadow result = new TransactionEntityShadow(legacy.getService(), legacy.getAliasCode());
result.setAliasCode (legacy.getAliasCode());
result.setAmount (legacy.getAmount());
result.setBeneficiaryAccountNumber (legacy.getBeneficiaryAccountNumber());
result.setBeneficiaryId (legacy.getBeneficiaryId());
result.setBeneficiaryIdTypeId (legacy.getBeneficiaryIdTypeId());
result.setBeneficiaryMSISDN (legacy.getBeneficiaryMSISDN());
// result.setBeneficiaryName (legacy.getBeneficiaryName());
// result.setBeta (legacy.getBeta());
// result.setBillContractNumber (legacy.getBillContractNumber());
// result.setBillNumber (legacy.getBillNumber());
// result.setBillSecretCode (legacy.getBillSecretCode());
// result.setContractBeta (legacy.getContractBeta());
result.setCustomerKey (legacy.getCustomerKey());
result.setFeesAmount (legacy.getFeesAmount());
result.setFreeByte1 (legacy.getFreeByte1());
result.setFreeByte2 (legacy.getFreeByte2());
result.setLanguageIndex (legacy.getLanguageIndex());
result.setMerchantCode (legacy.getMerchantCode());
result.setMerchantServiceCode (legacy.getMerchantServiceCode());
result.setPinDigest (legacy.getPinDigest());
result.setService (legacy.getService());
result.setSessionKey (legacy.getSessionKey());
result.setTransactionDate (legacy.getTransactionDate());
return result;
}

It looks like it is a bug/limitation in version 4.3 of ProGuard. I have moved to version 4.4 and the problem is solved.

Use -dontoptimize in your proguard

Related

Gradle : Skipping task ':groovydoc' as it has no source files and no previous output files

I'm trying to create groovydoc using gradle. I have created the below task :
The groovy classes are present in - src/integration-test/groovy/com/x/folders/*.groovy
This is my sourcesets :
sourceSets {
integrationTestCompile {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDirs = ['src/integration-test/groovy']
}
resources.srcDir file('src/integration-test/resources')
}
}
groovydoc {
source = sourceSets.integrationTestCompile.java.srcDirs
classpath = configurations.compile
include '**/com/x/common/controllers/*'
}
I get the below message :
> Task :groovydoc NO-SOURCE
Skipping task ':groovydoc' as it has no source files and no previous output files.
I may have wrongly entered the sourcesets, but I have tried different ways but still getting the very same error message.

Importing class from the root folder from a class in a package: unable to resolve class

I have the following directory/package structure in my groovy project:
src
+ progressManagers (package)
| |
| + LoadSensitiveProgressManager.groovy
+ TemporaryRegistry.groovy
Contents of TemporaryRegistry.groovy
// here is no package definition set
public class TemporaryRegistry {}
Contents of LoadSensitiveProgressManager.groovy
package progressManagers
// this gets marked red in my IDE (Intellij Idea)
import TemporaryRegistry
class LoadSensitiveProgressManager implements GenericProgressManager {
}
When i run my code in Scriptrunner for Jira Server the class is not found:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/data/atlassian/application-data/jira/scripts/progressManagers/LoadSensitiveProgressManager.groovy: 7: unable to resolve class TemporaryRegistry
# line 7, column 1.
import TemporaryRegistry
^
1 error
Why is that?
I can "import TemporaryRegistry" from every groovy file in the src folder.
Thanks in advance
Jens

Access a managed C++ lib from regular C++

I am trying to call a method in a managed C++ library from a regular (unmamanged) C++ file. I'm working from the example here (which is really good except for this little issue).
My managed C++ code is:
__declspec(dllexport) void ShowMessageBox(int *value)
{
AutoTagManagedBridge::Class1 work;
work.ShowCSharpMessageBox(value);
}
My unmanaged C++ code is:
_declspec(dllexport) void ShowMessageBox(int *value);
// ...
ACCB1 void ACCB2 MyPluginCommand(void *clientData)
{
int val = 5;
int *result = &val;
ShowMessageBox(result);
// ...
In the unmanaged C++ project, I set the managed C++ project as a reference. However, when I compile I get:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "void __cdecl
ShowMessageBox(int *)" (?ShowMessageBox##YAXPAH#Z) referenced in
function "void __cdecl MyPluginCommand(void *)"
(?MyPluginCommand##YAXPAX#Z) BasicPlugin C:\src\AdobePlugin\win32\BasicPlugin.obj 1
And when I look at the link command the managed C++ module (AutoTagManagedBridge.lib) is not listed:
/OUT:"Debug/BasicPlugin.api" /MANIFEST /NXCOMPAT
/PDB:".\Debug/BasicPlugin.pdb" /DYNAMICBASE "odbc32.lib"
"odbccp32.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib"
"comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib"
"uuid.lib" /IMPLIB:".\Debug/BasicPlugin.lib" /DEBUG /DLL /MACHINE:X86
/SAFESEH /INCREMENTAL /PGD:".\Debug\BasicPlugin.pgd"
/SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/ManifestFile:".\Debug\BasicPlugin.api.intermediate.manifest"
/ERRORREPORT:PROMPT /NOLOGO /TLBID:1
What else do I need to do?
Found the answer. In order for VisualStudio to recognize a .lib file from the Managed C++, you need to set on your UnManaged project right click and Properties -> ConfigurationProperties -> Linker -> Input ->
Additional Dependencies - > "$(SolutionDir)$(Configuration)\ManagedDll.lib".

nebula-test fails to load the project plugin class when using IntegrationSpec class

I'm in the process of writing and testing a Gradle plugin. When I try to test the plugin I get an error indicating the plugin class can't be found? If I use the plugin id I get: Plugin with id <> not found. If I use the plugin class name I get: Could not find property 'com' on root project.
Below is the build.gradle, ExamplePlugin class and the Test Spec.
build.gradle
apply plugin: 'idea'
apply plugin: 'groovy'
apply plugin: 'maven'
group = 'com.sas'
version = '0.1.0'
description = "Project to test with nebula plugin."
task wrapper(type: Wrapper) {
gradleVersion = '2.6' //version required
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile localGroovy()
compile gradleApi()
testCompile 'org.spockframework:spock-core:1.0-groovy-2.3'
testCompile 'com.netflix.nebula:nebula-test:3.1.0'
}
plugin class
package com.sas.gradle.plugins.example
import org.gradle.api.Plugin
import org.gradle.api.Project
class ExamplePlugin implements Plugin<Project> {
#Override
void apply(Project project) {
project.logger.debug("ExamplePlugin: Running...")
}
}
test class spec
package com.sas.gradle.plugins.example
import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult
class ExamplePluginIntegSpec extends IntegrationSpec {
def 'setup and display the buildscript classpath'() {
writeHelloWorld('example.hello')
buildFile << '''
apply plugin: 'java'
apply plugin: com.sas.gradle.plugins.example.ExamplePlugin
task show << {
buildscript.configurations.classpath.each { println it }
}
'''.stripIndent()
when:
ExecutionResult result = runTasksSuccessfully('show')
then:
result.standardOutput.contains(':show')
}
}
It appears when using the IntegrationSpec it creates build scripts build.gradle and settings.gradle in build/test/package/spec location. Also, I see .gradle, .gradle-test-kit, src directories at the same location. I was wondering how the .classpath is setup for running the tests and noticed an init.gradle script in the .gradle-test-kit; then in it I found a allprojects->buildscript->dependencies>classpath DSL.
Then I noticed my plugin class (compiled to build/classes/main) wasn’t in the list? I’d have thought nebula-test IntegrationSpec class would have done this? By adding this DSL:
buildscript {
dependencies {
classpath files('../../../../build/classes/main')
}
}
Thanks in advance for any help,
Jim
Lastly here's the exception I get:
Class com.sas.gradle.plugins.example.ExamplePluginIntegSpec
all > com.sas.gradle.plugins.example > ExamplePluginIntegSpec
1
tests
1
failures
0
ignored
3.173s
duration
0%
successful
Failed tests
Tests
Standard output
Standard error
setup and display the buildscript classpath
org.gradle.api.GradleException: Build aborted because of an internal error.
at nebula.test.functional.internal.DefaultExecutionResult.rethrowFailure(DefaultExecutionResult.groovy:97)
at nebula.test.IntegrationSpec.runTasksSuccessfully(IntegrationSpec.groovy:265)
at com.sas.gradle.plugins.example.ExamplePluginIntegSpec.setup and display the buildscript classpath(ExamplePluginIntegSpec.groovy:19)
Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'C:\Users\japoli\IdeaProjects\nebula-test-example-master\build\test\com.sas.gradle.plugins.example.ExamplePluginIntegSpec\setup-and-display-the-buildscript-classpath\build.gradle' line: 4
A problem occurred evaluating root project 'setup-and-display-the-buildscript-classpath'.
at org.gradle.initialization.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:74)
at org.gradle.initialization.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
at org.gradle.initialization.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:30)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:105)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:97)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:97)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:102)
at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:46)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:58)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:77)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:47)
at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:52)
at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:35)
at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:63)
at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:35)
at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:124)
at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:100)
at org.gradle.tooling.internal.provider.DefaultConnection.getModel(DefaultConnection.java:167)
at org.gradle.tooling.internal.consumer.connection.CancellableModelBuilderBackedModelProducer.produceModel(CancellableModelBuilderBackedModelProducer.java:58)
at org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection.run(AbstractConsumerConnection.java:58)
at org.gradle.tooling.internal.consumer.DefaultBuildLauncher$1.run(DefaultBuildLauncher.java:84)
at org.gradle.tooling.internal.consumer.DefaultBuildLauncher$1.run(DefaultBuildLauncher.java:78)
at org.gradle.tooling.internal.consumer.connection.LazyConsumerActionExecutor.run(LazyConsumerActionExecutor.java:83)
at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConsumerActionExecutor.run(ProgressLoggingConsumerActionExecutor.java:58)
at org.gradle.tooling.internal.consumer.connection.RethrowingErrorsConsumerActionExecutor.run(RethrowingErrorsConsumerActionExecutor.java:38)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:55)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'setup-and-display-the-buildscript-classpath'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$1.run(DefaultScriptPluginFactory.java:148)
at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:72)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:153)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:495)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:89)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLauncher.java:129)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:126)
at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:36)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:103)
... 31 more
Caused by: groovy.lang.MissingPropertyException: Could not find property 'com' on root project 'setup-and-display-the-buildscript-classpath'.
at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(AbstractDynamicObject.java:43)
at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:35)
at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:97)
at org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.java:66)
at build_3ap3e1c6wmmpxvu497fssx7g9.run(C:\Users\japoli\IdeaProjects\nebula-test-example-master\build\test\com.sas.gradle.plugins.example.ExamplePluginIntegSpec\setup-and-display-the-buildscript-classpath\build.gradle:4)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
... 49 more
Wrap lines
Generated by Gradle 2.6 at Jan 13, 2016 10:01:59 AM
Have you taken a look at Gradle TestKit (the functional replacement for Nebula test)? Take a look at the specific section about placing the code under test on the classpath.

Export struct defined in winbase.h with ATL's IDL

This is my method defined in IDL:
[id(3), helpstring("method GetBatteryStatus")]
HRESULT GetBatteryStatus([out,retval] SYSTEM_POWER_STATUS_EX2* batteryStatus);
The SYSTEM_POWER_STATUS_EX2 is a struct defined in winbase.h, and this project is a ATLSmartPhone Project, the winbase.h is from Microsoft's SDK.
When I compile the project the error are :
error MIDL2025 : syntax error : expecting a type specification near "SYSTEM_POWER_STATUS_EX2"
If I add import "winbase.h" to the top of the IDL file, the error will be:
error MIDL2003 : redefinition : size_t; error MIDL2003 : redefinition : _LARGE_INTEGER;.....
Then if I add the typedef in in IDL:
typedef[public,uuid(37DE998A-6787-415a-A191-861C315D1248),helpstring("Power Status")]
struct _SYSTEM_POWER_STATUS_EX2 {
...
...
} SYSTEM_POWER_STATUS_EX2;
The error will be:
error C2011: '_SYSTEM_POWER_STATUS_EX2' : 'struct' type redefinition.
So how can I export the SYSTEM_POWER_STATUS_EX2 struct which was defined in winbase.h with IDL?
You can write the IDL version of the SYSTEM_POWER_STATUS_EX2 in the separate IDL file and import it for MIDL only:
cpp_quote("#if 0")
import "fake.idl";
cpp_quote("#else")
cpp_quote("#include <orginial_header>")
cpp_quote("#endif")

Resources