Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I downloaded code about how to encry file by des,the souce code is build by VC6,and i transfer it to VS2010. then it happened some question about fopen function.

C#
bool songDES::Read_Keys(unsigned char * keyfile,bool bIsDES3)
{
	FILE * file;
	if((file = fopen((const char *)keyfile,"r"))== NULL)
	{
		printf("file_key open failed!\n");
		return false;
	}
}

keyfile value equal NcStudiooooo,when run in vc6,fopen can successed,but run in VS2010 it will printf file_key open failed.
i don't know why,please help me to solve this question.
thanks everybody.

the vc6 source code can be downloaded as below,if you want to test in VS2010,you must convert some types or head file. i'm confuse,why in vc6,fopen function can read character but no file path?

[^]

What I have tried:

In VC6,i key F12 go to definition about fopen,the function declare as below:
_CRTIMP FILE * __cdecl fopen(const char *, const char *);

In Vs2010,i key F12 go to definition about fopen,the function declare as below:
_Check_return_ _CRT_INSECURE_DEPRECATE(fopen_s) _CRTIMP FILE * __cdecl fopen(_In_z_ const char * _Filename, _In_z_ const char * _Mode);

they are all use stdio.h head file,but declare is different,maybe it's important or not.
Posted
Updated 25-May-16 21:19pm
v3
Comments
Richard MacCutchan 26-May-16 3:40am    
The fopen function works exactly the same in all versions of C/C++ code. There must be something else that you are not showing us.

Also, your link to the code is incorrect.

1 solution

Prototype difference doesn't matter in your case.
Probably you're getting the error because the OS cannot open the requested file (do your program have the permissions to access it?). On Windows you could try to use CreateFile[^] instead of fopen in order to obtain more detailed info about the occurring error.
 
Share this answer
 
Comments
xuyunhai 26-May-16 2:57am    
but i'm confuse,why fopen in vc6 tool can read character but not file path

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900