'Problem with attaching a file with the .asm extension to a project in Visual studio

I have a little problem, I'm writing an assembly function in x64 mode. Every time I have to write a function declaration (Extern "C" ...) in a .cpp source file it is a bit tiresome when the file already has a lot of lines. Is it possible to attach a file with the .asm extension to the project? Attaching .cpp or .h files works fine. The problem occurs when I want to add a .asm file (#include "sample.asm"). The strange thing is that something like this works (#include "sample2.h" or #include "samble3.cpp" ).

Every time I have to write a function declaration in a .cpp source file, but I would like to include the finished file ( #indluce "sample.asm") immediately, without having to declare it each time.

Of course, it uses microsoft visual studio

File source.cpp

#include <iostream>
#include <windows.h>
#include "sample2.h" // it can be...
#include "sample3.cpp" // it can be..
#include "sample.asm" //causes an error 
using namespace std;

//extern "C" INT64 sum(INT64 a, INT64 b);  it always works

int main()
{
    return 0;
}

File sample.asm

.CODE


sum PROC

add rcx, rdx
mov rax, rcx

ret

sum  ENDP

END

Errors I get when sample.asm wants to attach. It is E0169- declaration was expected and C2059- syntax error: "."



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source