0

While compiling below code I am getting missing type specifier error. Any way I can solve this issue? I have been trying for few days now and couldnt make any progress. Done almost everything that was suggested for this similar issue but cant seem to get through

CPP

#include "MemoryProtection.h"
#include "Resources.h"
#include "stdafx.h"


pWriteProcessMemory pfnWriteProcessMemory = NULL;
pReadProcessMemory pfnReadProcessMemory = NULL;

HEADER

#pragma once

#include <Windows.h>
#include "3rd\detours.h"
#include <Psapi.h>
#include <atlstr.h>

#pragma comment(lib, "Detours.lib")

typedef LONG NTSTATUS;

#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)


LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);

typedef BOOL(WINAPI* pReadProcessMemory) (HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesRead);
typedef BOOL(WINAPI* pWriteProcessMemory) (HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesWritten);

ERROR

Severity    Code    Description Project File    Line    Suppression State
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int        6   
Error   C2146   syntax error: missing ';' before identifier 'pfnWriteProcessMemory'     6   
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int        7   
Error   C2146   syntax error: missing ';' before identifier 'pfnReadProcessMemory'      7   
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int        8   
M. Yal
  • 53
  • 5
  • 2
    You think that `pWriteProcessMemory` is a type, but the compiler disagrees. Either you misspelled it or forgot to include the header where it is declared. – nwp Dec 04 '17 at 13:54
  • 4
    If you're using pre-compiled headers you need `#include "stdafx.h"` as first pre-processor line. Otherwise all previous includes are overwritten – Mihayl Dec 04 '17 at 13:55
  • @A.A that did solve the issue.. stupid me.. Thank you a lot. – M. Yal Dec 04 '17 at 13:59

1 Answers1

1

If you're using pre-compiled headers #include "stdafx.h" should be the first pre-processor line. Otherwise all previous includes are overwritten.

/Yu (Use Precompiled Header File)

The compiler treats all code occurring before the .h file as precompiled. It skips to just beyond the #include directive associated with the .h file, uses the code contained in the .pch file, and then compiles all code after filename. -- https://msdn.microsoft.com/en-us/library/z0atkd6c.aspx

See also What's the use for “stdafx.h” in Visual Studio? and StdAfx.h for Novices on cplusplus.com.

Mihayl
  • 3,821
  • 2
  • 13
  • 32
  • 2
    Also note that almost everyone that has such errors probably meant to create an "empty" project in visual studio instead, which won't use precompiled headers by default and does not require a stdafx include. – AndyG Dec 04 '17 at 14:12
  • You can also use the [/FI (Name Forced Include)](https://learn.microsoft.com/en-us/cpp/build/reference/fi-name-forced-include-file) compiler option, to have the compiler automatically include the pre-compiled header file. This is particularly helpful when you are compiling code you cannot change (e.g. libraries) and still want to use pre-compiled headers. – IInspectable Feb 04 '18 at 16:56