猿问

为什么我把程序作为一个单独的函数加入到我的工程后,就一直无法打开文件。

这是我在spacesimulator上下载的导入3ds文件的程序,但是我把程序作为一个单独的函数加入到我的工程后,就一直无法打开文件。
调用时的写法是:object.id_texture=LoadBitmap("spaceshiptexture.bmp"); 
并且在messagebox弹窗显示的也确实是spaceshiptexture.bmp,望高人指点迷津!
char Load3DS (obj_type_ptr p_object, const char *p_filename)
{
int i; //Index variable

/* handle file stream */
FILE *l_file; //File pointer

unsigned short l_chunk_id; //Chunk identifier
unsigned int l_chunk_lenght; //Chunk lenght

unsigned char l_char; //Char variable
unsigned short l_qty; //Number of elements in each chunk

unsigned short l_face_flags; //Flag that stores some face information

/* fopen() "rb" means open a binary files & only read it */
if ((l_file=fopen (p_filename, "rb"))== NULL)
{
MessageBox(NULL,"model open failed", "Zetadeck",MB_OK | MB_ICONERROR);
return 0; //Open the file
}

...
}

蝴蝶不菲
浏览 79回答 1
1回答

繁花如伊

没看懂你的问题,调用时的写法是:object.id_texture=LoadBitmap("spaceshiptexture.bmp");与Load3DS有什么关系?不过文件打开失败后会设置errno,你可以检查下errno的值来看是什么问题。常见的一些问题包括给的是文件相对路径而不是全路径,有时候路径问题会影响。或者是文件在其他地方被打开并且deny read。比如这个文件本身是你的程序写出来的,但是你的程序忘了close这个文件。
随时随地看视频慕课网APP
我要回答