AMS AMS - 3 months ago 21
C++ Question

C++ MSVC dll compiling error missing type specifier and redefinition

I'm using Microsoft Visual Studio Community 2015 Update 3 and im compiling a dll. I want to call the function InitPreySplitPipe i have already tried calling it with ::pr::InitPreySplitPipe and i copied the interprocess.cpp code into game_local.cpp and interprocess.hpp code into game_local.h and call it from there but that didnt work either.

I have set up a GitHub repository with all the code if some one is interested.

Thanks for reading and sorry for my bad english :/

Compiler output:

Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2371 'pr::InitPreySplitPipe': redefinition; different basic types
Error C2556 'int InitPreySplitPipe(void)': overloaded function differs only by return type from 'void pr::InitPreySplitPipe(void)'


interprocess.hpp



namespace pr
{
(...)
void InitPreySplitPipe();
(...)
}


interprocess.cpp



#include "interprocess.hpp"

namespace pr
{
(...)
void InitPreySplitPipe()
{
pipe_preysplit = CreateNamedPipe("\\\\.\\pipe\\" PREYSPLIT_PIPE_NAME,PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS, 1, 256 * 1000, 0, 0, NULL);
if (pipe_preysplit == INVALID_HANDLE_VALUE)
{
return;
}

std::memset(&overlapped, 0, sizeof(overlapped));
overlapped.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
if (overlapped.hEvent == NULL)
{
pipe_preysplit = INVALID_HANDLE_VALUE;
}
}
(...)
}


// Where the function shoud be called

game_local.cpp



(...)
#include "../PreyRun/interprocess.hpp"
pr::InitPreySplitPipe();
(...)

Answer

In game_local.cpp:

// PreyRun BEGIN
#include "../PreyRun/interprocess.hpp"
pr::InitPreySplitPipe();
// PreyRun END

You are not calling the function from within anything, so the compiler thinks it's a new function declaration. Thus the type int is assumed, of which the overloaded function int pr:InitPreySplitPipe() conflicts with your void pr::InitPreySplitPipe(). This explains all 3 error messages.