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

  • SEARCH
  • Home
  • 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 7820379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:16:03+00:00 2026-06-02T07:16:03+00:00

I have a C++ program that syncs files with a remote server when windows

  • 0

I have a C++ program that syncs files with a remote server when windows xp starts. A function that needs to open a public key file fails at fopen(). When I start the program myself (from within explorer) everything works fine. But when I add a startup key to the registry the function fails.

I traced the code through a debugger and everything’s fine until the call to CreateFileA(). CreateFileA returns FILE_NOT_FOUND.

I removed the call to fopen() and replaced it with a call to CreateFileA() directly. Then I changed SECURITY_ATTRIBUTES to NULL after which the call to CreateFileA() works.

The problem is that the 3rd party library I’m using for my encryption needs a FILE* object instead of just the data read from the file. How can I solve my problem?

Here’s the code I’m currently using:

if( !GetModuleFileNameA(NULL, Path, MAX_PATH) ){
    delete [] buf;
    delete [] Path;
    return strerror( errno );
}

rPath = Path;

delete [] Path;

ret = rPath.find_last_of( '\\' );

if( ret == string::npos ){
    delete [] buf;
    return strerror( errno );
}

ret++;

rPath.erase( rPath.begin() + ret, rPath.begin() + rPath.size() - ret );

rPath += "rsa_pub.txt";

if( ( f = fopen( rPath.c_str(), "rb" ) ) == NULL ){  // fails when started from registry
    delete [] buf;
    return strerror( errno );
}

EDIT:

I found a hackery solution to the problem: if I free the runtime library and then reload it the problem goes away. However this isn’t a very elegant solution. Is it perhaps possible to reset the runtime withouth removing and reloading the dll?

  • 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-02T07:16:04+00:00Added an answer on June 2, 2026 at 7:16 am

    Your rPath.erase call doesn’t seem to make much sense

    rPath.erase( rPath.begin() + ret, rPath.begin() + rPath.size() - ret );
    

    What is that supposed to do?

    Here you are using the (iterator, iterator) version of erase here. I beleve you are trying to erase the tail portion of the string beginning from the position ret. In that case I would expect it to look as

    rPath.erase( rPath.begin() + ret, rPath.end() );
    

    If you wanted to use the (position, length) version of erase, then it would look as

    rPath.erase( ret, rPath.size() - ret );
    

    But your specific usage looks like a weird hybrid of the two. What are you trying to do by that call?

    The GetModuleFileNameA probably returns different strings, depending on how you start your program, which is why your code might appear to “work” in some cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that creates lists and needs any assigned values to be
I have a program that needs two integers to be entered to set up
I have a program that creates a Windows user account using the NetUserAdd() API
i have the following batch file, which terminates the iTunes program so, that if
I have an old Fortran77 program that calls a C++ function and passes several
Is there anyway to have a client side small database that syncs with server
In gEDA , we have a helper program that needs to create a subprocess
I have a perl script that prepares files for input to a binary program
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of

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.