Using windows.h in C++/CLI project

Hi jedediah!
What do I have to do to include windows.h in a CLI project and be able to make Win32 API calls
If I simply include windows.h, I get a lot of errors like these:
1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(636) : error C3641: 'Int64ShllMod32' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(637) : warning C4793: '__asm' : causes native code generation for function 'ULONGLONG Int64ShllMod32(ULONGLONG,DWORD)' 
 
This only happens if you switch to "/clr:safe"!

If you want to develop pure and verifiable assemblies then you must not use unmaged code or any unverifiable data-type!
Please switch either to "/clr" or "/clr:pure".
-- 
Greetings
 Jochen Kalmbach
 Microsoft MVP VC++

  My blog about Win32 and .NET
  http://blog.kalmbachnet.de/
  
PS: Please mark an answer as "answered" if it helped!!!


Answer this question

Using windows.h in C++/CLI project

  • edallica

    Hi!

    I tried with VS2005 Beta2 and there is no error...
    Tomorrow I will try with VC2005 Express Beta2...

    Greetings
      Jochen

  • Jeevann

    Could it be a problem with the version of the PSDK that I downloaded It was the XP SP2 version.

  • mox_01

    Using VS Express beta 1:
    - create new windows forms project
    - add to end of stdafx.h
         #include "windows.h"
    - build project

    output:
    1>------ Build started: Project: bugger, Configuration: Debug Win32 ------
    1>Compiling...
    1>stdafx.cpp
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(636) : error C3641: 'Int64ShllMod32' : invalid calling convention '__stdcall ' for function compiled with /clrStick out tongueure or /clrTongue Tiedafe
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(637) : warning C4793: '__asm' : causes native code generation for function 'ULONGLONG Int64ShllMod32(ULONGLONG,DWORD)'
    1>        C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(606) : see declaration of 'Int64ShllMod32'
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(606) : error C3862: 'Int64ShllMod32': cannot compile an unmanaged function with /clrStick out tongueure or /clrTongue Tiedafe
    1>        The function uses inline assembler or an unsupported intrinsic function
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(652) : error C3641: 'Int64ShraMod32' : invalid calling convention '__stdcall ' for function compiled with /clrStick out tongueure or /clrTongue Tiedafe
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(653) : warning C4793: '__asm' : causes native code generation for function 'LONGLONG Int64ShraMod32(LONGLONG,DWORD)'
    1>        C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(613) : see declaration of 'Int64ShraMod32'
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(613) : error C3862: 'Int64ShraMod32': cannot compile an unmanaged function with /clrStick out tongueure or /clrTongue Tiedafe
    1>        The function uses inline assembler or an unsupported intrinsic function
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(668) : error C3641: 'Int64ShrlMod32' : invalid calling convention '__stdcall ' for function compiled with /clrStick out tongueure or /clrTongue Tiedafe
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(669) : warning C4793: '__asm' : causes native code generation for function 'ULONGLONG Int64ShrlMod32(ULONGLONG,DWORD)'
    1>        C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(620) : see declaration of 'Int64ShrlMod32'
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(620) : error C3862: 'Int64ShrlMod32': cannot compile an unmanaged function with /clrStick out tongueure or /clrTongue Tiedafe
    1>        The function uses inline assembler or an unsupported intrinsic function
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(1954) : warning C4793: '__asm' : causes native code generation for function 'PVOID GetFiberData(void)'
    1>        C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(1954) : see declaration of 'GetFiberData'
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(1954) : error C3862: 'GetFiberData': cannot compile an unmanaged function with /clrStick out tongueure or /clrTongue Tiedafe
    1>        The function uses inline assembler or an unsupported intrinsic function
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(1959) : warning C4793: '__asm' : causes native code generation for function 'PVOID GetCurrentFiber(void)'
    1>        C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(1959) : see declaration of 'GetCurrentFiber'
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(1959) : error C3862: 'GetCurrentFiber': cannot compile an unmanaged function with /clrStick out tongueure or /clrTongue Tiedafe
    1>        The function uses inline assembler or an unsupported intrinsic function
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(7573) : warning C4272: 'RtlFirstEntrySList' : is marked __declspec(dllimport); __clrcall functions cannot be exported from a dll via dllexport
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinBase.h(1205) : error C3641: '__InlineInterlockedCompareExchangePointer' : invalid calling convention '__cdecl ' for function compiled with /clrStick out tongueure or /clrTongue Tiedafe
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinUser.h(1549) : warning C4272: 'IsHungAppWindow' : is marked __declspec(dllimport); __clrcall functions cannot be exported from a dll via dllexport
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinUser.h(1556) : warning C4272: 'DisableProcessWindowsGhosting' : is marked __declspec(dllimport); __clrcall functions cannot be exported from a dll via dllexport
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinUser.h(8260) : warning C4272: 'PrivateExtractIconsA' : is marked __declspec(dllimport); __clrcall functions cannot be exported from a dll via dllexport
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinUser.h(8269) : warning C4272: 'PrivateExtractIconsW' : is marked __declspec(dllimport); __clrcall functions cannot be exported from a dll via dllexport
    1>Build log was saved at "file://c:\Documents and Settings\no\Desktop\bugger\bugger\Debug\BuildLog.htm"
    1>bugger - 9 error(s), 10 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    If I create a blank .net project and add your hello world code, I get the same thing with even more errors.

  • texwalker

    Hi jedediah!
    Could it be a problem with the version of the PSDK that I downloaded It was the XP SP2 version.
    You can try to use the newest:
    ISO: http://www.microsoft.com/downloads/details.aspx FamilyId=D8EECD75-1FC4-49E5-BC66-9DA2B03D9B92
    
    Full: http://www.microsoft.com/downloads/details.aspx FamilyId=EBA0128F-A770-45F1-86F3-7AB010B398A3
    --
    Greetings
     Jochen
     
      My blog about Win32 and .NET
      http://blog.kalmbachnet.de/

  • kaisatsu

    jedediah@discussions.microsoft.com wrote:
    I am already using /clr:pure
    Then please provide an example... for me the following works perfectly (VS2005 Beta2):

    #include <windows.h>
    using namespace System;
    int main(array<System::String ^> ^args)
    {
        ULONGLONG l = Int64ShllMod32(1, 1);
        Console::WriteLine(L"Hello World");
        return 0;
    }

    -- 
    Greetings
     Jochen Kalmbach
     Microsoft MVP VC++
    
      My blog about Win32 and .NET
      http://blog.kalmbachnet.de/
      
    PS: Please mark an answer as "answered" if it helped!!!

  • Shona Arora

    Hi jedediah!
    Could it be a problem with the version of the PSDK that I downloaded It was the XP SP2 version.
    Now I tried with VC2005 Express with the latest PSDK...
    And I works without any problem!
    -- 
    Greetings
     Jochen Kalmbach
     Microsoft MVP VC++
    
      My blog about Win32 and .NET
      http://blog.kalmbachnet.de/
      
    PS: Please mark an answer as "answered" if it helped!!!

  • Chadwick Posey

    What do I have to do to include windows.h in a CLI project and be able to make Win32 API calls

    If I simply include windows.h, I get a lot of errors like these:

    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(636) : error C3641: 'Int64ShllMod32' : invalid calling convention '__stdcall ' for function compiled with /clrStick out tongueure or /clrTongue Tiedafe
    1>C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include\WinNT.h(637) : warning C4793: '__asm' : causes native code generation for function 'ULONGLONG Int64ShllMod32(ULONGLONG,DWORD)'

  • Ahmed Mohd. Hazzaa

    I am already using /clr: pure


  • Using windows.h in C++/CLI project