1

I have that code. and I created this. but I want to compile it without any console window. and it gives me:

unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)"

all subsystems changed to /SUBSYSTEM:WINDOWS*

long x;
long y;
#include <Windows.h>

float hz = rand() % 800;  // input how many hertz you need
long marcos;
void drawSomething() {
    marcos = 1000;
    HDC hd = GetDC(NULL);
    BitBlt(hd, 0, 0, 1000, 1000, hd, rand() % 3000 - rand() % 100, rand() % 3000 - rand() % 100, SRCCOPY);
    StretchBlt(hd, 0, 0, rand() % 3000 - rand() % 100, rand() % 3000 - rand() % 100, hd, rand() % 3000 - rand() % 100, rand() % 3000 - rand() % 100, rand() % 3000 - rand() % 100, rand() % 3000 - rand() % 100, SRCCOPY);
}
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) // oh shit of fu-
{
    while (true) {
        drawSomething();
    }
    return 0;
}
Ðаn
  • 10,934
  • 11
  • 59
  • 95
  • 2
    Check your linker settings are you set to subsystem console and not subsystem windows? If you're set to the former you'll see this issue. – Mgetz Sep 21 '21 at 13:20
  • 2
    Does this answer your question? [Error LNK2019 unresolved external symbol \_main referenced in function "int \_\_cdecl invoke\_main(void)" (?invoke\_main@@YAHXZ)](https://stackoverflow.com/questions/33400777/error-lnk2019-unresolved-external-symbol-main-referenced-in-function-int-cde) – Mgetz Sep 21 '21 at 13:21
  • @Mgetz what version of visual studio required for win32 application? just im new at c++ and vs. –  Sep 21 '21 at 13:27
  • 1
    Any works, you just need the right subsystem in the linker. That should have been set for you if you installed the win32 project type (in the VS installer ensure you have windows desktop development checked as an option for C++) – Mgetz Sep 21 '21 at 13:33
  • i hope this link helps [link](https://learn.microsoft.com/en-us/cpp/windows/walkthrough-creating-windows-desktop-applications-cpp?view=msvc-160#:~:text=To%20create%20a%20Windows%20desktop%20project%20in%20Visual%20Studio%202015&text=then%20choose%20Project.-,In%20the%20New%20Project%20dialog%20box%2C%20in%20the%20left%20pane,Choose%20OK.) – dorKKnight Sep 21 '21 at 13:44
  • 1
    any version of visual studio ( VS 2013, VS 2017, vs 2019 etc. ) can be used to create a win32 application. its just that you have to select the right project settings while creating the project. Please, have a look at the link in above comment. – dorKKnight Sep 21 '21 at 13:47
  • ***all subsystems changed to /SUBSYSTEM:WINDOWS*** Are you sure you did that for all configurations? – drescherjm Sep 21 '21 at 14:39

1 Answers1

0

I had the same problem and the fix was that I forgot to add

int main() {

}

Silly mistake but this is the solution for me

Saddish
  • 17
  • 4