本文介绍了关于fopen函数,.NET和VC6之间有一些不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我下载了关于如何通过des加密文件的代码,源代码由VC6构建,并将其传输到VS2010。然后它发生了一些关于fopen功能的问题。 bool songDES: :Read_Keys(unsigned char * keyfile, bool bIsDES3) { FILE *文件; if ((file = fopen(( const char *)keyfile, r))== NULL) { printf( file_key open failed!\ n); return false ; } } 密钥文件值等于NcStudiooooo,当在vc6中运行时,fopen可以成功,但在VS2010中运行会使printf file_key打开失败。 i不知道为什么,请帮我解决这个问题。 谢谢大家。 vc6源代码可以如下下载,如果你想在VS2010中测试,你必须转换一些类型或头文件。我很困惑,为什么在vc6中,fopen函数可以读取字符但没有文件路径? [ ^ ] 我尝试过: 在VC6中,我键F12转到定义关于fopen,函数声明如下: _CRTIMP FILE * __cdecl fopen(const char *,const char *); 在Vs2010中,我键F12去定义fopen,函数声明如下: _Check_return_ _CRT_INSECURE_DEPRECATE(fopen_s)_CRTIMP FILE * __cdecl fopen(_In_z_ const char * _Filename,_In_z_ const char * _Mode); 他们都使用stdio.h头文件,但声明是不同的,也许它很重要。解决方案 在您的情况下,原型差异无关紧要。 可能你收到错误是因为 OS 无法打开请求的文件(你的程序是否有权访问它?)。在Windows上,您可以尝试使用 CreateFile [ ^ ]而不是 fopen ,以获取有关发生错误的更详细信息。 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.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. 解决方案 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. 这篇关于关于fopen函数,.NET和VC6之间有一些不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 08:58