It seems you're still encountering some issues regarding GUID usage and precompiled headers. Let's address both issues step by step.
1. Fixing the GUID Conversion Issue
The error about the GUID conversion typically comes from how the GUID type is used with the Windows Audio Session API (WASAPI). Ensure you are passing the correct type to the functions that require a GUID.
Correcting the GUID Usage:
When calling methods that expect a GUID argument (like SetMasterVolumeLevel), you should prepare a GUID as needed or simply pass GUID_NULL, which is a predefined constant.
2. Handling Precompiled Header Issues
The precompiled header error means that your project may be expecting a precompiled header but the source file does not include it at the top of the file. If you intend to use precompiled headers, you’ll need to include the pch.h header file at the very top (before any other #include statements). Alternatively, if you want to avoid using precompiled headers altogether, you can disable the use of the precompiled header in the project settings.
Complete Code Example with Corrections
Here's the complete code with consideration for GUID types and a precompiled header.
Ensure Precompiled Header is Set Up Correctly
If you are going to use a precompiled header, make sure to include it appropriately:
#include "pch.h" // Include precompiled header if your project uses it
You should place this line at the beginning of your code. If you don't have a pch.h, you can disable precompiled headers in Visual Studio:
- Go to Project Properties -> C/C++ -> Precompiled Headers -> choose "Not Using Precompiled Headers".
Updated Full Code
#include <windows.h>
#include <commctrl.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <initguid.h>
#include <math.h>
// Include this if using precompiled headers
//#include "pch.h"
// GUID definitions for MMDeviceEnumerator and IAudioEndpointVolume
DEFINE_GUID(IID_MMDeviceEnumerator, 0xa95664d2, 0x9614, 0x4f35, 0x9f, 0x9c, 0x67, 0x56, 0x9e, 0x19, 0x78, 0xf0);
DEFINE_GUID(IID_IAudioEndpointVolume, 0x5cdf2c80, 0x2219, 0x11d0, 0x8f, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00);
// Global variables
HINSTANCE hInst;
HWND hWndSlider;
// Function to set microphone volume
void SetMicrophoneVolume(float decibels) {
CoInitialize(nullptr);
// Create MMDeviceEnumerator
IMMDeviceEnumerator* pEnumerator = nullptr;
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pEnumerator));
if (SUCCEEDED(hr)) {
// Get default audio endpoint (mic)
IMMDevice* pDevice = nullptr;
hr = pEnumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, &pDevice);
if (SUCCEEDED(hr)) {
// Activate audio endpoint volume interface
IAudioEndpointVolume* pVolume = nullptr;
hr = pDevice->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, nullptr, (void**)&pVolume);
if (SUCCEEDED(hr)) {
// Convert decibels to a level between 0.0 and 1.0
float newVolume = powf(10.0f, decibels / 20.0f);
pVolume->SetMasterVolumeLevelScalar(newVolume, GUID_NULL); // Set master volume
// Clean up
pVolume->Release();
}
pDevice->Release();
}
pEnumerator->Release();
}
CoUninitialize();
}
// Window procedure to handle messages
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE:
hWndSlider = CreateWindowEx(0, TRACKBAR_CLASS, L"",
WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS,
10, 10, 300, 30, hwnd,
(HMENU)1, hInst, nullptr);
SendMessage(hWndSlider, TBM_SETRANGE, TRUE, MAKELPARAM(0, 100)); // Set range to 0-100
break;
case WM_HSCROLL:
if ((HWND)lParam == hWndSlider) {
int pos = SendMessage(hWndSlider, TBM_GETPOS, 0, 0);
float decibelValue = pos - 100; // Map slider output to -100 to 0 dB
SetMicrophoneVolume(decibelValue);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
// DLL Entry Point
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
hInst = hModule;
// Registering the window class
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInst;
wc.lpszClassName = L"JakacordHookWndClass";
RegisterClass(&wc);
// Create the window
CreateWindowEx(0, L"JakacordHookWndClass", L"Jakacord Hook",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
350, 100, NULL, NULL, hInst, NULL);
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Explanation of Key Parts
#include "pch.h": (Commented out above) If you're using precompiled headers, this line should be uncommented and included at the top of your source file.
- Correct Use of
IID_PPV_ARGS: ensures proper type safety when getting interface pointers from COM.
- Use of
HRESULT: Your audio control functions should handle HRESULT to check for success.
Building and Running the DLL
- Check your project settings to ensure that precompiled headers are either utilized appropriately or disabled.
- Build the DLL in Visual Studio.
- Inject the DLL into Discord via a suitable DLL injector for testing.
Conclusion
With these adjustments, you should be able to compile your DLL without the previous issues regarding GUIDs or precompiled headers. If you encounter further issues, please let me know!