C++ unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)"

Filip 831 Reputation points
2021-04-10T20:52:33.943+00:00

Hello Everybody.
I had error. What must i do to fixing the problem?
Thanks for help.

#include <stdio.h>  
#include <windows.h>  
#include <mmdeviceapi.h>  
#include <endpointvolume.h>  
  
void Usage()  
{  
    printf("Usage: \n");  
    printf(" SetVolume [Reports the current volume]\n");  
    printf(" SetVolume -d <new volume in decibels> [Sets the current default render device volume to the new volume]\n");  
    printf(" SetVolume -f <new volume as an amplitude scalar> [Sets the current default render device volume to the new volume]\n");  
  
}  
  
int _tmain(int argc, char* argv[])  
{  
    HRESULT hr;  
    bool decibels = false;  
    bool scalar = false;  
    double newVolume;  
    if (argc != 3 && argc != 1)  
    {  
        Usage();  
        return -1;  
    }  
    if (argc == 3)  
    {  
        if (argv[1][0] == '-')  
        {  
            if (argv[1][1] == 'f')  
            {  
                scalar = true;  
            }  
            else if (argv[1][1] == 'd')  
            {  
                decibels = true;  
            }  
        }  
        else  
        {  
            Usage();  
            return -1;  
        }  
  
        newVolume = atof(argv[2]);  
    }  
  
    // -------------------------  
    CoInitialize(NULL);  
    IMMDeviceEnumerator* deviceEnumerator = NULL;  
    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID*)&deviceEnumerator);  
    IMMDevice* defaultDevice = NULL;  
  
    hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);  
    deviceEnumerator->Release();  
    deviceEnumerator = NULL;  
  
    IAudioEndpointVolume* endpointVolume = NULL;  
    hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&endpointVolume);  
    defaultDevice->Release();  
    defaultDevice = NULL;  
  
    // -------------------------  
    float currentVolume = 0;  
    endpointVolume->GetMasterVolumeLevel(&currentVolume);  
    printf("Current volume in dB is: %f\n", currentVolume);  
  
    hr = endpointVolume->GetMasterVolumeLevelScalar(&currentVolume);  
    printf("Current volume as a scalar is: %f\n", currentVolume);  
    if (decibels)  
    {  
        hr = endpointVolume->SetMasterVolumeLevel((float)newVolume, NULL);  
    }  
    else if (scalar)  
    {  
        hr = endpointVolume->SetMasterVolumeLevelScalar((float)newVolume, NULL);  
    }  
    endpointVolume->Release();  
  
    CoUninitialize();  
    return 0;  
}  

86553-a.png

Developer technologies | C++
{count} votes

2 answers

Sort by: Most helpful
  1. WayneAKing 4,931 Reputation points
    2021-04-11T02:37:33.717+00:00

    What type of project did you create?

    How did you create it?

    Which project template did you use?

    In the project properties what is the linker setting
    under System for the Subsystem property?

    Is it set to this?

    Console (/SUBSYSTEM:CONSOLE)

    • Wayne
    0 comments No comments

  2. WayneAKing 4,931 Reputation points
    2021-04-11T02:42:24.633+00:00

    If you want to use _tmain you must have this:

    #include <tchar.h>
    
    • Wayne
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.