Asking for assistance building HotkeyHandler beta feature from source(VS 2019)

Discussion in 'Rivatuner Statistics Server (RTSS) Forum' started by Skewjo, Aug 6, 2020.

  1. Skewjo

    Skewjo Member

    Messages:
    34
    Likes Received:
    0
    GPU:
    GTX 1060 3GB
    I've been banging my head against getting the HotkeyHandler dll built for about 6 hours today(I'm very inexperienced with Visual Studio and especially Visual C++), and I would greatly appreciate some help with it.

    I've not yet made any (purposeful)modifications to the source, as I wanted to complete a local build and use the resulting dll to ensure that RTSS could still operate.

    I've tried several different troubleshooting steps as I've run into different issues, but the order of the steps seems to matter tremendously, so I've taken to uninstalling and reinstalling RTSS basically every build attempt in the hope that I do it correctly one time.

    I've outlined below, the process I can follow to get the dll built, but it fails when I attempt to replace the dll in the "\Plugins\Client\" folder.

    1. Upgrade the project to build in VS 2019 - all looks normal here as far as I can tell.
    upload_2020-8-5_18-47-29.png

    2. Re-target the solution to run on my current version of Windows. A troubleshooting step I found online earlier in the day(for a different issue I can't even remember now) told me to do this, so I keep doing it.

    upload_2020-8-5_18-8-4.png


    3. Perform the following step to change the linker directory as found in the link below: "Right click the project in solution explorer, select properties, in the pop-up: configuration properties, linker, general. Select Output file on the right, this gives a drop-down, select inherent from parent or project defaults. Click apply. This gives the default linker setting: $(OutDir)$(TargetName)$(TargetExt). Re-build the project and the warning should no longer appear."

    https://stackoverflow.com/questions...re-that-outdir-targetname-and-targetext-prope

    4. Finally once I've got the dll built and in place, this is the error I get when I run RTSS(if hotkey handler is enabled). I had some different build issues with the "mfc140d.dll" earlier in the day, but I thought I had them resolved by installing several different MFC packages from the VS installer(and possibly disabling spectre mitigations at some point?).

    upload_2020-8-5_19-2-8.png

    If it matters, here's the version of Windows I'm on, in addition to the version of Visual Studio

    upload_2020-8-5_18-42-31.png
    upload_2020-8-5_19-3-24.png


    Sorry for the long post... I hope I haven't missed a "how to get the program to build in Visual Studio" readme somewhere...
     
  2. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,926
    Likes Received:
    8,232
    GPU:
    GF RTX 2070 Super
    Have you tried to build your dll in Release configuration?
     
    Unwinder likes this.
  3. Unwinder

    Unwinder Moderator Staff Member

    Messages:
    15,410
    Likes Received:
    2,679
    This. Mixing debug and release DLLs in MFC projects is frequently not the best idea and may lead to issues like that.
     
  4. Skewjo

    Skewjo Member

    Messages:
    34
    Likes Received:
    0
    GPU:
    GTX 1060 3GB
    Woot! Thank you! That (mostly)fixed it, thank you. DLL size went down from ~291 kb to 108 kb(original was 102 kb).

    The DLL builds without issue now, and the program isn't crashing, but it seems to just not function now...

    I don't seem to get any errors and I'm not sure if there's a better way of testing the DLL than dropping it in place and attempting the function every time. Got any hints for me on that one?

    Also, any tips for a beginner trying to get better at Windows C++ development? It feels like I'm going to constantly be running into issues like this one if I keep at it.
     

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,926
    Likes Received:
    8,232
    GPU:
    GF RTX 2070 Super
    That was not a crush. Since you built your libraries in Debug configuration your code was dependent on debug versions of MFC libraries. And that dialog with debug assertion failure is just means to notify a programmer about some unexpected/unwanted/non-standard situation in the code. MFC programmers instrumented their code with debug assertions - to be able to catch strange situations in their code in debug mode. When you build your code in Release configuration (and your code becomes dependent on release versions of MFC (ad other) libraries) debug assertions are not triggered because they are not included in release code.



    You should debug your code by building it in Debug configuration. When MFC debug assertions pop-up you can just ignore them (by pressing the button "Ignore") - if you are sure that they are not triggered by your code.

    MFC is not a Windows C++ development. MFC is GUI framework. You can use other frameworks for GUI, like QT, or WinForms in C++/CLI implementation.
    Or even get ultra modern with https://en.wikipedia.org/wiki/C++/WinRT,

    I used to program GUI in pure Win API. It was not that hard but the amount of code to write is staggering.

    But now I happily work in C#, WinForms, WPF. (And I don`t want to go back to C++.)

    PS
    List of books
    http://www.winprog.org/tutorial/references.html

    Some online materials
    http://zetcode.com/gui/winapi/

    https://docs.microsoft.com/en-us/windows/win32/learnwin32/learn-to-program-for-windows

    https://en.wikibooks.org/wiki/C++_Programming
     
    Last edited: Aug 7, 2020
  6. Skewjo

    Skewjo Member

    Messages:
    34
    Likes Received:
    0
    GPU:
    GTX 1060 3GB
    Hey guys, I've been continuing to work on this issue for the past week and I am still unable to get it to work.

    I've made it past the "Debug Assertion Failed" issues by loading the symbol sets from the correct locations, and I've been able to attach to the RTSS.exe process and make it to the CHotkeyListenerThread::Init(), but it still never seems to make it to reading a hotkey.

    At first the debugger was telling me that my breakpoints inside the Uninit file would never be touched(which I found a little suspicious), so a quick google search told me that turning off compiler optimizations will allow the debugger to make it to the function... but now the program just hangs constantly because it's not optimized (idfk lol).

    It looks like this might be where I'm getting stuck? Is it failing to retrieve access to my keyboard?

    upload_2020-8-13_5-51-3.png

    Has anyone else been able to build this particular project outside of the original creator? Do I need to just try and re-install Visual Studio?
    Maybe create a new virtual machine to use as a build server? Is there some piece of code intentionally left out to make me work for it?

    Any help is greatly appreciated.
     
  7. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,926
    Likes Received:
    8,232
    GPU:
    GF RTX 2070 Super
  8. Skewjo

    Skewjo Member

    Messages:
    34
    Likes Received:
    0
    GPU:
    GTX 1060 3GB
    @mbk1969

    Oh, I think that's got me onto something, thank you.
    upload_2020-8-13_8-57-8.png

    It's kind of weird that the page you linked me to contains an error value of "DIERR_INVALIDPARAM", but not "E_INVALIDARG" though... but anyways, it says the "DIERR_INVALIDPARAM" is caused when SetDataFormat isn't called properly beforehand, so I attempted to use the same method to figure out what was wrong with SetDataFormat call, but figured out it was never being reached.

    It looks like my actual problem might be with the DirectInput8Create function, but I'm now a bit over my head again with all these different types required for this function.
    upload_2020-8-13_9-16-27.png

    https://docs.microsoft.com/en-us/pr...desktop/ee416756(v=vs.85)?redirectedfrom=MSDN

    Thanks again for your help. I feel like I'm getting closer to figuring out the issue and I'm pretty happy to be learning a lot about the Visual Studio IDE and build process, but man it is frustrating.
     
  9. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,926
    Likes Received:
    8,232
    GPU:
    GF RTX 2070 Super

    The "Autos" tab shows you "E_INVALIDARG" value for "hres" variable because both "E_INVALIDARG" and "DIERR_INVALIDPARAM" have the same (binary) value - "0x80070057", and "E_INVALIDARG" is a well known HRESULT value while "DIERR_INVALIDPARAM" is a niche DirectInput value unknown to "Autos" tab (to VisualStudio actually).
     
  10. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,926
    Likes Received:
    8,232
    GPU:
    GF RTX 2070 Super
    @Skewjo

    From IDirectInputDevice8::SetCooperativeLevel description:

    Are you sure the handle you provide to SetCooperativeLevel - m_pWnd ? m_pWnd->m_hWnd : 0 - is a top-level window? Have you checked whether the handle is already created? I mean you can place the code (you posted) in your window handling code where the window is not created yet.

    Update: Try to call
    SetCooperativeLevel (NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)
     

  11. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,926
    Likes Received:
    8,232
    GPU:
    GF RTX 2070 Super
    @Skewjo

    If all you need is to get notified on key(s) pressed you can use Raw Input instead of DirectInput.

    Update: As for DirectInput8Create try to use
    DirectInput8Create(GetModuleHandle(NULL), ...)
     
    Last edited: Aug 13, 2020
  12. Unwinder

    Unwinder Moderator Staff Member

    Messages:
    15,410
    Likes Received:
    2,679
    Nobody can get it working of course. Original creator traditionally provides broken samples in SDK.
    [sarcasm mode off]

    If you’re just learning C++/MSVC development - start from your own simple “Hello world” projects, which you can debug locally, instead of trying to randomly modify plugins attached to external projects.
     
  13. Skewjo

    Skewjo Member

    Messages:
    34
    Likes Received:
    0
    GPU:
    GTX 1060 3GB
    Sorry, I didn't mean to sound offensive, but I could see how you may have wanted to obscure this functionality because it could be used for malicious scripting.
     
  14. Skewjo

    Skewjo Member

    Messages:
    34
    Likes Received:
    0
    GPU:
    GTX 1060 3GB
    Also, this modification is highly targeted(not random) and I'm hoping to share the results with you very very soon.
     
  15. Skewjo

    Skewjo Member

    Messages:
    34
    Likes Received:
    0
    GPU:
    GTX 1060 3GB
    WOOT, that's got it working. Thank you sir.

    I definitely think I was throwing some confusion in the mix(for myself as well) in trying to debug a button press outside of an actual Direct3d app(though I had tried it inside of a Direct3d app as well...). Anyways, thanks again.
     

  16. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,926
    Likes Received:
    8,232
    GPU:
    GF RTX 2070 Super
    Good.

    Ask at will. And when you finish your project I can review the full source code (should you wish that). My C++ skills are bit rusty but if the project is not a "rocket science" I can manage.
     

Share This Page