July 4th, 2013, 07:55 PM
Permission to access file from program!
Hi There! How are you?
I have a program that I must load a certain image depending of certain conditions. This image can not be built into resources file, it must be separated from the program and it is actually residing in the same directory as the .exe file.
So, my code is really simple and tries to access the image file from the disk:
It works fine, but the problem is that unless it is executed with Administrator privileges, windows denies the access and the program crashes. I'd like that to run without administrator privileges, so I won't have to explain to every customer how to do it. How could I possibly work around this problem?
if(tabPage8->Size.Width > 996)
fs = gcnew FileStream("fundo_tp8_zoom2.png", FileMode::Open); //Opens the file
fs = gcnew FileStream("fundo_tp8.png", FileMode::Open); //Opens the file
unsigned int tamanho = safe_cast<unsigned int>(fs->Length); //Gets the file size
array<unsigned char>^ file_array = gcnew array<unsigned char>(tamanho); //Creates an array with the same size
fs->Read(file_array,0, tamanho); //Reads file into the array
fs->Close(); //Closes file
MemoryStream^ ms = gcnew MemoryStream(file_array); //Creates a memory stream from the array
Bitmap^ MyImage = gcnew Bitmap(ms); //Converts stream into bitmap
tabPage8->BackgroundImage = MyImage; //Changes the background image
Click Here to Expand Forum to Full Width