Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:56:47+00:00 2026-06-15T06:56:47+00:00

My system: Microsoft Windows XP Professional 32-bit IDE/Compiler: Microsoft Visual C++ 2010 Express Edition

  • 0

My system: Microsoft Windows XP Professional 32-bit

IDE/Compiler: Microsoft Visual C++ 2010 Express Edition

Library: Detours 3.0 Express

Target: Write simple packet logger.

My code:

mydll.cpp

#include <cstdio>
#include <windows.h>
#include <detours.h>

#pragma comment(lib,"detours.lib")
#pragma comment(lib,"ws2_32.lib")

int (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send;
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags);
int (WINAPI *pRecv)(SOCKET s, char* buf, int len, int flags) = recv;
int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags);

FILE* pSendLogFile;
FILE* pRecvLogFile;

int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
{
    fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
    fprintf(pSendLogFile, "%s\n", buf);
    fclose(pSendLogFile);
    return pSend(s, buf, len, flags);
}

int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags)
{
    fopen_s(&pRecvLogFile, "C:\\RecvLog.txt", "a+");
    fprintf(pRecvLogFile, "%s\n", buf);
    fclose(pRecvLogFile);
    return pRecv(s, buf, len, flags);
}

BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
    if (DetourIsHelperProcess()) {
        return TRUE;
    }

    if (dwReason == DLL_PROCESS_ATTACH) {
        DetourRestoreAfterWith();

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourAttach(&(PVOID&)pRecv, MyRecv);
        DetourTransactionCommit();

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourAttach(&(PVOID&)pSend, MySend);
        DetourTransactionCommit();

    }
    else if (dwReason == DLL_PROCESS_DETACH) {
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourDetach(&(PVOID&)pRecv, MyRecv);
        DetourTransactionCommit();

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourDetach(&(PVOID&)pSend, MySend);
        DetourTransactionCommit();

    }
    return TRUE;
}

injector.cpp

#include <windows.h>
#include <detours.h>

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

int main(int argc, char *argv[])
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory(&si, sizeof(si));
    ZeroMemory(&pi, sizeof(pi));
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_SHOW;

    if(!DetourCreateProcessWithDllEx("C:\\Program Files\\Internet Explorer\\iexplore.exe", 
                                        NULL, NULL, NULL, TRUE, 
                                        CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED,
                                        NULL, NULL, &si, &pi, 
                                        "C:\\Documents and Settings\\Dawid\\Pulpit\\detours_test\\Detours_test\\Release\\Detours_test.dll", NULL))
        MessageBox(0, "failed", 0, 0);
    else
        MessageBox(0, "success", 0, 0);

    ResumeThread(pi.hThread);

    WaitForSingleObject(pi.hProcess, INFINITE);

    CloseHandle(&si);
    CloseHandle(&pi);

    return EXIT_SUCCESS;
}

Error message:

(iexplore.exe) The application

Question:
What’s wrong with my code? Why I get this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:56:49+00:00Added an answer on June 15, 2026 at 6:56 am

    SOLVED

    I removed function:

    DetourRestoreAfterWith();
    

    from DLL and add to DLL function:

    extern "C" __declspec(dllexport) void dummy(void){
        return;
    }
    

    Now, it works!

    mydll.cpp

    #include <cstdio>
    #include <windows.h>
    #include <detours.h>
    
    #pragma comment(lib,"detours.lib")
    #pragma comment(lib,"ws2_32.lib")
    
    int (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send;
    int WINAPI MySend(SOCKET s, const char* buf, int len, int flags);
    int (WINAPI *pRecv)(SOCKET s, char* buf, int len, int flags) = recv;
    int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags);
    
    FILE* pSendLogFile;
    FILE* pRecvLogFile;
    
    int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
    {
        fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
        fprintf(pSendLogFile, "%s\n", buf);
        fclose(pSendLogFile);
        return pSend(s, buf, len, flags);
    }
    
    int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags)
    {
        fopen_s(&pRecvLogFile, "C:\\RecvLog.txt", "a+");
        fprintf(pRecvLogFile, "%s\n", buf);
        fclose(pRecvLogFile);
        return pRecv(s, buf, len, flags);
    }
    
    extern "C" __declspec(dllexport) void dummy(void){
        return;
    }
    
    BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
    {
        if (DetourIsHelperProcess()) {
            return TRUE;
        }
    
        if (dwReason == DLL_PROCESS_ATTACH) {
            //DetourRestoreAfterWith();
    
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(&(PVOID&)pSend, MySend);
            DetourTransactionCommit();
    
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(&(PVOID&)pRecv, MyRecv);
            DetourTransactionCommit();
        }
        else if (dwReason == DLL_PROCESS_DETACH) {
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourDetach(&(PVOID&)pSend, MySend);
            DetourTransactionCommit();
    
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourDetach(&(PVOID&)pRecv, MyRecv);
            DetourTransactionCommit();
        }
        return TRUE;
    }
    

    injector.cpp

    #include <windows.h>
    #include <detours.h>
    
    #pragma comment(lib,"detours.lib")
    
    int main(int argc, char *argv[])
    {
        STARTUPINFO si;
        PROCESS_INFORMATION pi;
    
        ZeroMemory(&si, sizeof(si));
        ZeroMemory(&pi, sizeof(pi));
        si.cb = sizeof(si);
        si.dwFlags = STARTF_USESHOWWINDOW;
        si.wShowWindow = SW_SHOW;
    
        if(!DetourCreateProcessWithDllEx("C:\\client.exe", 
                                            NULL, NULL, NULL, TRUE, 
                                            CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED,
                                            NULL, NULL, &si, &pi, 
                                            "C:\\Documents and Settings\\Dawid\\Pulpit\\detours_test\\Detours_test\\Release\\Detours_test.dll", NULL))
            MessageBox(0, "failed", 0, 0);
        else
            MessageBox(0, "success", 0, 0);
    
        ResumeThread(pi.hThread);
    
        WaitForSingleObject(pi.hProcess, INFINITE);
    
        CloseHandle(&si);
        CloseHandle(&pi);
    
        return EXIT_SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Setup: Windows 7 64-bit Office 2010 Professional 64-bit Visual Studio 2010 Professional Using Connection
I am using Visual Studio 2010 Professional Edition, and Windows Vista. Firstly, I have
I am running Windows 7 Professional 64-bit with visual Studio 2010. I have installed
Context Language: C# Platform Version: Microsoft .Net Framework 4.0 Operating System: Windows 7 Professional
According to MSDN ( http://msdn.microsoft.com/en-us/library/system.windows.forms.label.autosize.aspx ), there's a note about Label 's AutoSize property:
Regardless of whether my machines's root web config (the one in Windows/Microsoft.NET/...) contains system.web/pages/namespaces/add
I have the following LINQ query: List<string> Types = (List<string>)Directory.GetFiles(@C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727) .Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains(Microsoft)) .ToList<string>();
Microsoft has a handy reference of the various controls in the System.Windows.Controls namespace and
Background I use JScript (Microsoft's ECMAScript implementation) for a lot of Windows system administration
I'm trying to debug .NET Framework's source code using Visual Studio 2010 Professional. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.