problem opening executable file while inside executable

Inside a given a program c:\program.exe, I have the following code:

filebuf *fb=new filebuf;
int mode=ios::binary | ios::in | ios::nocreate;
fb->open("c:\program.exe",mode);
if (!fb->is_open())
  and this test always fails

Is the operating system blocking me on this?  Is there some way to copy the executable to another file and open that?

Thanks
AshurbanipalAsked:
Who is Participating?
 
AlexNekConnect With a Mentor Commented:
I already realized master-slave architecture with one Exe. I have no problem with this line:
FILE*     fp = fopen(ModuleName, "rb");
0
 
jkrCommented:
Try

fb->open("c:\\program.exe",mode); // note the double backslash!
0
 
AshurbanipalAuthor Commented:
actually the code looks more like:

std::string file=GetCommandLine();
fb->open(file.c_str(),mode);

When I look at the contents of "file" there doesn't seem to be any problem.  I'm opening other files with no problem and am just having a problem with the executable.
0
 
AlexNekCommented:
I already realized master-slave architecture with one Exe. I have no problem with this line:
FILE*     fp = fopen(ModuleName, "rb");
0
 
AlexNekCommented:
I already realized master-slave architecture with one Exe. I have no problem with this line:
FILE*     fp = fopen(ModuleName, "rb");
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.