0

I have a C# executable that makes an interop call to a C++ library:

[DllImport(DLL_NAME, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int Check(string name, string version, bool debug);

In the C++ code, I redirect std::cout to a file:

std::streambuf* psbuf, * backup;
std::ofstream filestr;

...

if (debug)
{
    filestr.open("debug.txt");
    backup = std::cout.rdbuf();
    psbuf = filestr.rdbuf();
    std::cout.rdbuf(psbuf);

    std::cout << "some debug message" << std::endl; 

    std::cout.rdbuf(backup);
    filestr.close();
}

This works fine when I run the C# executable as a console program, but when I run it as a Windows Service, the file is not created by the C++ code.

What would account for this difference?

1 Answer 1

1

The file actually is being created, but the working directory when running as a service is different: as explained here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.