Hack Forums
[C] CreateNamedPipe identifier not found? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] CreateNamedPipe identifier not found? (/showthread.php?tid=5215434)



CreateNamedPipe identifier not found? - Chickendipper - Mar 25, 2016

Code:
Code
#include "pch.h" //windows.h
#include <stdio.h>
#include <iostream>

using namespace std;

DWORD WINAPI hook(LPVOID lpParam);
BOOL startsWith(const char *needle, const char *haystack);
void externalCall(const char *called);

BOOL WINAPI APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        threadHandle = CreateThread(NULL, 0, hook, 0, 0, NULL);
        break;
    case DLL_THREAD_ATTACH: break;
    case DLL_THREAD_DETACH: break;
    case DLL_PROCESS_DETACH:
        //TerminateThread(threadHandle, 0);
        //CloseHandle(threadHandle);
        break;
    }
    return TRUE;
}

DWORD WINAPI hook(LPVOID lpParam) {
    HANDLE pipeHandle;
    char buffer[1024];
    DWORD dwRead;

    pipeHandle = CreateNamedPipe(TEXT("\\\\.\\pipe\\OmniBotPipe"), PIPE_ACCESS_DUPLEX | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, PIPE_WAIT, 1, (1024 * 16), (1024 * 16), NMPWAIT_USE_DEFAULT_WAIT, NULL);
    while (pipeHandle != NULL) {
        if (ConnectNamedPipe(pipeHandle, NULL) != FALSE) {
            while (ReadFile(pipeHandle, buffer, sizeof(buffer), &dwRead, NULL) != FALSE) {
                externalCall(buffer);
            }
        }
    }
    DisconnectNamedPipe(pipeHandle);
}

void externalCall(const char *called) {
    if (startsWith("char", called)) {
        //todo
    }
}

BOOL startsWith(const char *needle, const char *haystack) {
    return (strncmp(haystack, needle, strlen(needle)) == 0);
}

In short, it tells me that CreateNamedPipe, ConnectNamedPipe and DisconnectNamedPipe are not found even though they're in WinBase.h (which is included in Windows.h) - is there any reason for this?


* - Dam Son - Mar 25, 2016

You have to use either the ASCII or Unicode version of it, so either CreateNamedPipeW or CreateNamedPipeA.
Same for the other APIs


* - Chickendipper - Mar 25, 2016

(Mar 25, 2016 06:01 PM)Dam Son Wrote:  You have to use either the ASCII or Unicode version of it, so either CreateNamedPipeW or CreateNamedPipeA.
Same for the other APIs

Same problem when trying to use W/A versions.


* - Dam Son - Mar 25, 2016

(Mar 25, 2016 06:07 PM)Chickendipper Wrote:  Same problem when trying to use W/A versions.

Are you using a non-standard build config? (whats up with the pch.h)


* - excr4sh - Mar 25, 2016

make sure you include windows.h in your project.


* - Chickendipper - Mar 26, 2016

(Mar 25, 2016 06:29 PM)Dam Son Wrote:  Are you using a non-standard build config? (whats up with the pch.h)

I literally just opened up VS2015, made a new Universal DLL and put in that code. I think pch is just a precompiled header which I already include windows.h in

(Mar 25, 2016 07:52 PM)excr4sh Wrote:  make sure you include windows.h in your project.

It's in pch.h


* - excr4sh - Mar 26, 2016

(Mar 26, 2016 03:26 AM)Chickendipper Wrote:  It's in pch.h
Define it in your C/CPP file, there is nothing wrong with that and as a recommendation, I suggest you switch to VS2013. VS2015 is unstable and overloads the CPU on large projects.


* - Chickendipper - Mar 30, 2016

(Mar 26, 2016 03:38 AM)excr4sh Wrote:  Define it in your C/CPP file, there is nothing wrong with that and as a recommendation, I suggest you switch to VS2013. VS2015 is unstable and overloads the CPU on large projects.

Exact same code, switched to VS2013, and no errors. Amazing.

Thanks :D