Including atlbase.h to use CComBSTR - c++-cli

I have a .NET library for which I'm writing a C++/CLI wrapper to expose the public members to native world. One of the requirement is to make use of CComBSTR for strings and avoid the std namespace altogether.
For this purpose, I included the atlbase.h header file to use CComBSTR. Everything worked fine as far as the wrapper or its unit tests were concerned. But when I tried using the wrapper headers and libs in an existing project, I noticed a high number of compilation errors all originating from files that don't directly belong to the project I'm compiling. I'm posting a few of them below:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(560): error C2039: 'vt' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(561): error C2039: 'vt' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(932): error C2039: 'vt' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(933): error C2039: 'bstrVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(935): error C2039: 'bstrVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1798): error C2039: 'cVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1798): error C2065: 'cVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1808): error C2039: 'bVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1808): error C2065: 'bVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1818): error C2039: 'pcVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1818): error C2065: 'pcVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1828): error C2039: 'pbVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1828): error C2065: 'pbVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1838): error C2039: 'iVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1838): error C2065: 'iVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1848): error C2039: 'piVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1848): error C2065: 'piVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1858): error C2039: 'uiVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1858): error C2065: 'uiVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1869): error C2039: 'puiVal' : is not a member of 'tagVARIANT'
c:\program files (x86)\microsoft visual studio 12.0\vc\include\oaidl.h(455) : see declaration of 'tagVARIANT'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1869): error C2065: 'puiVal' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlcomcli.h(1880): error C2039: 'intVal' : is not a member of 'tagVARIANT'
I tried a couple of suggestions like the one in https://answers.unrealengine.com/questions/56125/problems-with-including-atlbase-in-ue4-onlyproblem.html but it didn't help. I would prefer not having to make any changes to application project but instead do something in the wrapper project itself that resolves these compilation errors.

Related

"Restore failed" for Rider's Template Project

I have a problem with my brand new instance of JetBrains Rider. After downloading it and creating the template project "ASP .NET Web Application" I get the following error message when trying to download NuGet packages:
Restore failed
Restore failed for 14 packages in 1 project
The log is
[Notification][Restore] Restore failed
Restore failed for 14 packages in 1 project
The packages/ folder does not exist.
I installed a couple of other programms (like the .NET Framework and even Visual Studio), I downloaded the nuget.exe and put it in the PATH environment variable. I moved the project around the hard drive because maybe Rider needs special permissions and even created the folder. Nothing helped so far.
When I type nuget restore manually, I get the following essage:
nuget : Errors in packages.config projects
At line:1 char:1
+ nuget restore
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Errors in packages.config projects:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Unable to find version '3.5.0.2' of package 'Antlr'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Antlr.3.5.0.2' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '1.17.0' of package 'jQuery.Validation'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'jQuery.Validation.1.17.0' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '3.3.1' of package 'jQuery'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'jQuery.3.3.1' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '3.4.1' of package 'bootstrap'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'bootstrap.3.4.1' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '1.1.3' of package 'Microsoft.AspNet.Web.Optimization'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Microsoft.AspNet.Web.Optimization.1.1.3' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '5.2.7' of package 'Microsoft.AspNet.Mvc'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Microsoft.AspNet.Mvc.5.2.7' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '3.2.7' of package 'Microsoft.AspNet.Razor'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Microsoft.AspNet.Razor.3.2.7' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '3.2.7' of package 'Microsoft.AspNet.WebPages'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Microsoft.AspNet.WebPages.3.2.7' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '2.8.3' of package 'Modernizr'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Modernizr.2.8.3' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '1.0.0' of package 'Microsoft.Web.Infrastructure'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Microsoft.Web.Infrastructure.1.0.0' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '1.6.0' of package 'WebGrease'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'WebGrease.1.6.0' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '3.2.11' of package 'Microsoft.jQuery.Unobtrusive.Validation'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Microsoft.jQuery.Unobtrusive.Validation.3.2.11' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '2.0.0' of package 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
Unable to find version '11.0.1' of package 'Newtonsoft.Json'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Newtonsoft.Json.11.0.1' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
How can I fix this error message and download NuGet packages in Rider?
It seems downloading the nuget.exe and putting it in the PATH environment variable was correct. Additional, I had to add this to C:\Users<username>\AppData\NuGet\NuGet.config:
<configuration>
<!-- stuff -->
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<!-- other stuff -->
</packageSources>
</configuration>
Then I called nuget restore and the 14 packages were successfully downloaded. I haven't found a manual detailing this steps yet, so I'm not sure if more is missing.

MSBuild returns non-zero errorlevel in CMD and Visual Studio Developer Command Prompt, but not PowerShell

I'm having an issue where when I try to run builds using MSBuild, I get a non-zero errorlevel (-1073741819). While researching this issue, I noticed I got this error level if I ran msbuild in the Command Prompt or VS2017 Developer Command Prompt, but not in PowerShell.
In PowerShell, if I run msbuild /? I get the normal usage information. However, in Command Prompt or VS2017 Develper Command Prompt, msbuild /? produced the same error code as above with no output. For example, in the Visual Studio Developer Command Prompt I see:
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.7.5
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
C:\Windows\System32>msbuild /?
C:\Windows\System32>echo %errorlevel%
-1073741819
However, in PowerShell I see this:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\WINDOWS\system32> msbuild /?
Microsoft (R) Build Engine version 15.7.180.61344 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
<<... Detailed flag options displayed here ...>>
According to PowerShell Get-Command, it's using msbuild.exe from C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe. Setting the /verbosity: flag doesn't seem to change the output.
In the event log, I'm seeing the error with the error: Exception code: 0xc0000005.
My Path:
C:\tools\ruby23\bin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\windows\system32
C:\windows
C:\windows\System32\Wbem
C:\windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\
C:\Program Files\Microsoft SQL Server\130\DTS\Binn\
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\
C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps
C:\Program Files (x86)\NuGet
C:\Program Files\Microsoft\Web Platform Installer\
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\dotnet\
C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\
C:\ProgramData\chocolatey\bin
C:\Program Files\Git\cmd
C:\Program Files\OpenSSH-Win64
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools\Best Practices Analyzer\
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools\Best Practices Analyzer\
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin
C:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps
C:\Users\MyUserName\AppData\Local\atom\bin
C:\Program Files\Collaborator Client
MSBuild returns non-zero errorlevel in CMD and Visual Studio Developer Command Prompt, but not PowerShell
It seems your Visual Studio Developer Command Prompt has not been initialized successfully. You can try to execute VsDevCmd.bat in the Visual Studio Developer Command Prompt:
Location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools
If this .bat can not be executed successfully, you can try to repair or reinstall the Visual Studio.
Update:
I'm seeing an exception code for msbuild in the Event log: Exception
code: 0xc0000005. Google hasn't produced much unfortunately
It seems the exception code 0xc0000005 is related to access violation. When you execute your command can you switch to use admin privilege? You may need to check the permission of your account. And you also need to check if Virus scanner is disabled.
Hope this helps.

MSBuild.exe 15.0 calls cl.exe and link.exe from wrong Visual Studio directory

I have two Visual Studio installed on my system: VS 2015 and VS 2017.
I run msbuild explicitly from the VS 2017 location:
"C:\Program Files (x86)\Microsoft Visual Studio"\2017\WDExpress\MSBuild\15.0\Bin\amd64\msbuild.exe build/binding.sln /p:Configuration=Release;Platform=x64
Since I call msbuild from the VS 2017 I expect it to take the tools from VS 2017 as well, but it does not work!
The "normal" Verbosity level shows that msbuild calls C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\cl.exe and C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\link.exe, so it takes them from the older VS 2015 that is wrong.
If I use even more verbose level (/clp:Verbosity=diagnostic) I see that msbuild takes the properties file from the wrong location as well. The message is:
Property reassignment: $(VCInstallDir_140)="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\" (previous value: "") at C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Common.props (55,5)
The indeed properties file is located at C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\MSBuild\15.0\Microsoft.Cpp.Common.props.
The PATH variable is correct and does not contain anything that points to the older VS 2015. The variable VS140COMNTOOLS is unset.
Is it the expected behaviour and how can I tell msbuild to use the tools from VS 2017?
MSBuild.exe 15.0 calls cl.exe and link.exe from wrong Visual Studio directory
Please try to call the MSBuild from:
C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\MSBuild\15.0\Bin
and add the parameter /p:VisualStudioVersion=15.0 in the command line, like:
msbuild.exe build/binding.sln /p:Configuration=Release;Platform=x64 /p:VisualStudioVersion=15.0
I have tried the option /p:VisualStudioVersion=15.0, but it did not take effect.
Later I found what was the reason of that behaviour: my *.vcxproj file has the tag
<PlatformToolset>v140</PlatformToolset>
Once I changed it to v141 the msbuild started to take compiler and linker properly. So, it turned that msbuild first of all respects this parameter and only then probably command line options or/and PATH variable.

FAKE MSBuild step can't resolve references

I have a FAKE build script which will run perfectly fine if I build the project once using VisualStudio, but if I try and do a fresh build then it throws errors saying it can't find the namespace of both a number of nuget packages and my dependant visual studio projects.
I'm using FAKE's MSBuildRelease and passing in the .sln file like so:
Target "BuildWindowsProject" (fun _ ->
MSBuildRelease
""
"Build"
[ "./Source/My.Project.sln" ]
|> Log "Windows-Build: "
)
It's giving out a number of errors such as below, but these include both projects within the solution and external nuget packages.
The type or namespace name 'Caliburn' could not be found (are you missing a using directive or an assembly reference?)
I did notice that back in 2011 this was posted - MSBuild cannot find a reference but it's quite old and I can't find any more recent occurrences of the issue online.
It works just fine if I do a visual studio build first and then run my build script but this doesn't solve the problem for a build server. What am I doing wrong?
You have to perform deep diagnostic by yourself, because the question under consideration requires the source code to be published here. It also can depend on the environment where the script is running, in order to get you the right answer.
You have an option on MSBuild utility to pass verbosity level of output. Use the following switch value to get detailed information about how the references are resolved during the build:
msbuild ./Source/My.Project.sln /t:Build /v:d
Using this command, you can navigate to the steps called ResolveAssemblyReference and ResolveProjectReference. You can see all the paths, where it will search for assemblies, and if it is succeded:
4> Primary reference "System.Runtime.Remoting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
4> Resolved file path is "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Runtime.Remoting.dll".
4> Reference found at search path location "{TargetFrameworkDirectory}".
4> For SearchPath "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\lib\amd64".
4> Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\lib\amd64\System.Runtime.Remoting.winmd", but it didn't exist.
4> Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\lib\amd64\System.Runtime.Remoting.dll", but it didn't exist.
4> Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\lib\amd64\System.Runtime.Remoting.exe", but it didn't exist.
4> For SearchPath "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64".
4> Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64\System.Runtime.Remoting.winmd", but it didn't exist.
4> Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64\System.Runtime.Remoting.dll", but it didn't exist.
4> Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64\System.Runtime.Remoting.exe", but it didn't exist.
4> For SearchPath "{TargetFrameworkDirectory}".
4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Runtime.Remoting.winmd", but it didn't exist.
4> This reference is not "CopyLocal" because it's a prerequisite file.
4> The ImageRuntimeVersion for this reference is "v4.0.30319".
You also can examine which references were passed to the compiler if you look at commandline, which was generated by MSBuild and find out if there is a reference you are required in.
For cl:
4> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\CL.exe
...
/AI"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
...
/FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll"
/FUE:\YourProj\bin\Debug\Your.Proj.dll
/FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll"
...
/errorReport:prompt
YourSourceCodeFiles.cpp
/clr:nostdlib
For csc:
2> C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe
...
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll"
/reference:E:\svn\PRM\trunk\PRM30\bin\Debug\Prm.Base.dll
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Configuration.dll"
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll"
...
(most of parameters were omited for simplicity)

Building 32-bit Detours library

I'm using Detours library from microsoft, and I was using the 32bit version (which is free). I'm now on a 64-bit installation of windows 7 and I can't seem to compile Detours with nmake.
Here is the error:
Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
cd "C:\Program Files (x86)\Microsoft Research\Detours Express 2.1\src"
Building for 64-bit X64.
if not exist "..\include" mkdir "..\include"
if not exist "..\lib" mkdir "..\lib"
if not exist "..\bin" mkdir "..\bin"
cl /LD /nologo /W4 /WX /Zi /MTd /Gy /Gm- /Zl /O1 /DWIN32_LEAN_AND_MEAN /
D_WIN32_WINNT=0x403 /D_WIN64 /DDETOURS_X64=1 /D_AMD64_ /Wp64 /Fe..\bin\detoured.
dll /Fd..\bin\detoured.pdb detoured.cpp /link /release /machine:amd64 /base:0xf
000000 /incremental:no /subsystem:console /entry:DllMain /implib:..\lib\detoure
d.lib /export:Detoured kernel32.lib detoured.res
cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be
removed in a future release
detoured.cpp
c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourc
eannotations.h(17) : error C2371: 'size_t' : redefinition; different basic types
detoured.cpp : see declaration of 'size_t'
C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\basetsd.h(305) : warning C
4311: 'type cast' : pointer truncation from 'const void *' to 'unsigned long'
C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\basetsd.h(314) : warning C
4311: 'type cast' : pointer truncation from 'const void *' to 'long'
C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\basetsd.h(323) : warning C
4312: 'type cast' : conversion from 'unsigned long' to 'void *' of greater size
C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winnt.h(12935) : error C38
61: '__readfsdword': identifier not found
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\nmake.exe"' : return code '0x2'
Stop.
As you see, it's trying to compile for 64-bit. How can I force nmake to build for 32bits?
Thanks,
Dave
Next time, simply set the DETOURS_TARGET_PROCESSOR environment variable. Valid values are x86, AMD64 and IA64. (The Express version of Detours only supports x86.)
I needed windows SDK to compile. Simply google windfows SDK, download & install, run the Windows SDK console in admin mode and compile!
If installing SDK on windows 7 gives errors, here is the solution:
http://support.microsoft.com/kb/2717426/de
This issue occurs when you install the Windows 7 SDK on a computer that has a newer version of the Visual C++ 2010 Redistributable installed. The Windows 7 SDK installs version 10.0.30319 of the Visual C++ 2010 Redistributable.
To resolve this issue, you must uninstall all versions of the Visual C++ 2010 Redistributable before installing the Windows 7 SDK. You may have one or more of the following products installed:
Microsoft Visual C++ 2010 x86 Redistributable
Microsoft Visual C++ 2010 x64 Redistributable