dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Extension DLL callback function used for a Windows service and write to file

  1. #1
    Join Date
    Oct 2014
    Posts
    2

    Post Extension DLL callback function used for a Windows service and write to file

    Hello, I have a problem with an extension DLL that has an exported function. The function is being exported ok, it is called by a Windows service. The Windows service is using the exported function, and everything works. I am trying to create a file with:

    ofstream file;
    file.open("C:\dir\to\file", ios:ut);
    file << "text";

    But nothing happnes however. There are no errors, the file is just not created.
    Also, if i try to call MessageBox() in the exported function, nothing happens as well . I have a .h file which exports the function with __declspec(dllexport) DWORD WINAPI functionName(), and also a .cpp file with the function definition. There is no main().

    I appreciate help and suggestions about what I'm doing wrong.


    oldejr.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,227

    Re: Extension DLL callback function used for a Windows service and write to file

    Does the account the windows service is running under have write permissions to the folder?

  3. #3
    Join Date
    Oct 2014
    Posts
    2

    Re: Extension DLL callback function used for a Windows service and write to file

    Yes i think it's running as system account, but the folder has everyone permissions. And the MessageBox function is not being displayed when I try to call it in the exported function. I need that for debug messages.

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,001

    Re: Extension DLL callback function used for a Windows service and write to file

    You need to use two backslashes in a string when one is required. Try
    Code:
    file.open("C:\\dir\\to\\file", ios:out);
    See http://msdn.microsoft.com/en-us/library/6aw8xdf2.aspx
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.4.5)

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,227

    Re: Extension DLL callback function used for a Windows service and write to file

    Quote Originally Posted by oldejr View Post
    Yes i think it's running as system account, but the folder has everyone permissions. And the MessageBox function is not being displayed when I try to call it in the exported function. I need that for debug messages.
    You need to check for errors and log them (try logging them to the event viewer). Lastly, you aren't going to see any MessageBox popups with a service by default - with services you need to use a different error reporting mechanism other than message boxes.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)