BeErikk/VSUtilities

Visual Studio 2008 w/ 2019 platform tools - VCProjectEngine.dll.config

Opened this issue · 8 comments

Hi Erik,

So sorry for opening an issue for this kind of unrelated question, but found no other way to contact you.

Anyway, the thing is, I'm using VS 2008 for C and C++ development, and I would like to use the platform tools (build tools) for fx Visual Studio 2019, and I found this answer written by you: https://stackoverflow.com/a/60653147

I can't quite seem to get it to work, so I wanted to ask if you'd be so kind to provide your config files for Visual Studio 2008. Mainly <VS2008PATH>/VC/vcpackages/VCProjectEngine.dll.config and <VS2008PATH>/VC/vcpackages/AMD64.VCPlatform.config, maybe with some instructions on how to make it play nicely with multiple configurations (fx using mklink, if that is how you do).

Thank you so much in advance.

Hi Mewgood,

Pleased to help.
I copied my current version AMD64.VCPlatform.config för x64 in
my gist AMD64.VCPlatform.config

I have a directory outside of the system disk för Visual Studio settings I wish to keep, so when it is time for a new clean install of Windows I don't have to worry about losing things I care about. Then I just make symbolic links to the Visual Studio 2008 directory. I have an old not very clever CMD script to do it, here are the relevant parts:

@set CURDIR=%CD%
@set BACKUP=%random%
@if %install%==1 (@echo Setting links to Visual C++ config files >> %CURDIR%\install.log)
@set CONFIGX86=%VCINSTALLDIR%\vcpackages\VCProjectEngine.dll.config
@set CONFIGX64=%VCINSTALLDIR%\vcpackages\AMD64.VCPlatform.config
@if %install%==1 ( @if exist %CONFIGX86% (@rename %CONFIGX86% VCProjectEngine.dll.config.%BACKUP%) )
@if %install%==1 ( @if exist %CONFIGX64% (@rename %CONFIGX64% AMD64.VCPlatform.config.%BACKUP%) )
@if not exist %CONFIGX86% (@mklink %CONFIGX86% "%CURDIR%\vcpackages\VCProject.x86.%1.config" >> %CURDIR%\install.log 2>&1)
@if not exist %CONFIGX64% (@mklink %CONFIGX64% "%CURDIR%\vcpackages\VCProject.x64.%1.config" >> %CURDIR%\install.log 2>&1)
@exit /B 0

The script is executed in the directory of saved settings (current dir) with a subdirectory vcpackages containing different config files, for example, VCProject.x64.9.0.config which corresponds to AMD64.VCPlatform.config in Visual Studio 2008.

Hope it works out för you!

all the best Erik

Hi again Erik,
Do you have an email I can contact you on? I never really got it to work - unfortunately. It looks like it is expecting the path "../VC/Tools/MSVC" for the VS build tools, but my VS 2019 installation bdoesn't seem to have this path.

Hi again Erik, Do you have an email I can contact you on? I never really got it to work - unfortunately. It looks like it is expecting the path "../VC/Tools/MSVC" for the VS build tools, but my VS 2019 installation bdoesn't seem to have this path.

You need to assign the environment variables with proper current values.
See my gist AMD64.VCPlatform.config and to some extent my gist mscompiler script.

My current values right now are:
CurrentKits=C:\Program Files (x86)\Windows Kits\
CurrentUCRT=10.0.19041.0
CurrentVCTools=14.30.30705
CurrentVS=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\

You can send me emails through github or just continue asking here.

Yay! Somewhat got it working. My environment variable for CurrentVS was incorrect.

The environment variables CodeLibraries and WindowsSource, are these set automatically by installing some third-party add-on? I see you have wtl installed in the CodeLibraries dir.

What should the value for these two be?

Yay! Somewhat got it working. My environment variable for CurrentVS was incorrect.

The environment variables CodeLibraries and WindowsSource, are these set automatically by installing some third-party add-on? I see you have wtl installed in the CodeLibraries dir.

What should the value for these two be?

Great!
The custom CodeLibraries is the directory where I install third party headers and libraries, kind of like vcpkg but my own compiles and flavours. Usually, it is a collection symlinks to GitHub repositories. You should replace it with vcpkg I think. WindowsSource is a remnant from my Interix days where you would target the ntdll library. It's more still there to get IntelliSense support than anything else, PEB and TEB etc.

CodeLibraries=F:/libraries/

Good luck!

edit:
You will need Visual Assist 😌 to get Visual Studio 2008 C++ IDE shine!

Hi again Erik,

Do have Visual Assist 🙂

Anyways, I seem to have one issue with redifinitions (mainly in winnt.h, which is included by windows.h) with this setup.

Can you try reproducing it by creating a blank project, then include windows.h first and then this ntdll.h after? Curious if this happens for you too.

It did work before. It's a general issue and not related to this specific ntdll.h, but it makes it easier to reproduce. The issue also happens when I define my own _LIST_ENTRY.

https://raw.githubusercontent.com/Psionix/nwnhook/ba6486acdd3b941cbfac4708d3c702ee1e93d866/ntdll.h

Hi again Erik,

Do have Visual Assist 🙂

Anyways, I seem to have one issue with redifinitions (mainly in winnt.h, which is included by windows.h) with this setup.

Can you try reproducing it by creating a blank project, then include windows.h first and then this ntdll.h after? Curious if this happens for you too.

It did work before. It's a general issue and not related to this specific ntdll.h, but it makes it easier to reproduce. The issue also happens when I define my own _LIST_ENTRY.

https://raw.githubusercontent.com/Psionix/nwnhook/ba6486acdd3b941cbfac4708d3c702ee1e93d866/ntdll.h

Great! Visual Assist is really the crucial detail in this.

It seems to me that ntdll.h is not a known Windows SDK file but rather a homegrown attempt to collect definitions for the "native" NTDLL API which in turn is protected internal Microsoft definitions. You can not trust such user collection to be correct since it may in parts differ from one Windows version to the other. The best you can do is to make your own additions of things missing from the official Windows SDK and WDK and test them. Add them as you need them and not more than you need.

For example, to get good timer resolutions in Windows, I have this in a C++ source file:

/* -------------------------------------------------------------------------- */
// Wrap the Windows media timer functionality, timeBeginPeriod(1)/timeEndPeriod(1) 
// Beware there may be other applications using the API (e.g. chrome)

extern "C" __declspec(dllimport) NTSTATUS __stdcall
NtQueryTimerResolution(
                       _Out_ PULONG pmaximumresolution,
                       _Out_ PULONG pminimumresolution,
                       _Out_ PULONG pcurrentresolution);

extern "C" __declspec(dllimport) NTSTATUS __stdcall
NtSetTimerResolution(
                     _In_ ULONG desiredresolution,
                     _In_ BOOLEAN setresolution,
                     _Out_ PULONG pactualresolution);

class TimerResolution
{
protected:
    NTSTATUS m_status = 0;
    ULONG m_maximum = 0;
    ULONG m_minimum = 0;
    ULONG m_default = 0;
    ULONG m_actual = 0;
    int32_t m_isset = false;

public:
    TimerResolution(void) noexcept
    {
        m_status = ::NtQueryTimerResolution(&m_maximum, &m_minimum, &m_default);
    }
    ~TimerResolution(void) noexcept
    {
        ResetResolution();
    }

    bool SetResolution(void) noexcept
    {
        if (NT_SUCCESS(m_status) && (m_isset == false))
        {
            // we want the best resolution (minimum 100ns units per interrupt), 
            // default windows setting is the lowest (maximumresolution-1)
            m_status = ::NtSetTimerResolution(m_minimum, true, &m_actual);
            if (NT_SUCCESS(m_status))
                m_isset = true;
        }
        return NT_SUCCESS(m_status);
    }

    uint32_t GetResolution(void) noexcept 
    {
        return static_cast<uint32_t>(m_actual ? m_minimum : m_default);
    }

protected:
    bool ResetResolution(void) noexcept
    {
        if (NT_SUCCESS(m_status) && (m_isset != false))
        {
            // expensive, reset the resolution as soon as possible
            m_status = ::NtSetTimerResolution(m_default, false, &m_actual); 
            if (NT_SUCCESS(m_status))
                m_isset = false;
        }
        return NT_SUCCESS(m_status);
    }
};

So the only additions needed here were 2 function definitions, not more not less.

Good luck!

Yeah, Visual Assist rocks! 🤘

You are right about ntdll.h. It's just easy to add it to a project and whooptydoo, you got all the definitions you need. But then the compiler puked in the output log.

I ended up following your suggestion and got this project working. So much to avoid pasting in definitions manually 😅