|
-
Aug 22nd, 2002, 08:45 AM
#1
Thread Starter
Fanatic Member
dll memory access error
Code:
int _stdcall writeppm(BSTR filename, BSTR filepath, int framerate){
int iCount;
long lItemNum;
BYTE *pnOutBuf=new BYTE;
WORD OutPicWidth, OutPicHeight;
FILE *pfFile=new FILE;
int start;
char *name=new char[255];
char *name1=new char[255];
for(int i=0;i<=1800;i++){
start = i * 60 + framerate;
//set the filename
if(start<10){
strcpy(name,"f000000");
} else if(start<1000){
strcpy(name,"f00000");
} else if(start<10000){
strcpy(name,"f0000");
} else if(start<100000){
strcpy(name,"f000");
} else if(start<1000000){
strcpy(name,"f00");
} else {
strcpy(name,"f0");
}
//set the name
char *buffer=new char[11];
strcpy(name1,(LPCSTR)filepath);
strcat(name1,(LPCSTR)filename);
strcat(name1,name);
strcat(name1,itoa(start,buffer,10));
strcat(name1,".ppm");
for (iCount=0;iCount<=1800;iCount++) {
if (deco.GetCurFrameNum(&lResult)!=MDC_SUCCESS)
return -2; //failed
if (deco.DecodePicture()<0)
return -3; //failed
lItemNum=deco.GetCurFrame(pnOutBuf,&OutPicWidth,&OutPicHeight,PPM);
if (lItemNum>0) {
MessageBox(NULL,"fopen","openfile",MB_OK); //debug
if((pfFile = fopen(name1,"w+")) == NULL)
return -4; //open file failed
it crashes on the fopen statement, first it says it cant write to the memory, then read. im calling the dll from VB, the calling etc works fine, and other functions work fine. it just crashes the vb ide and the program, with the error. ive narrowed it down to that line
ive tried different things for the file, like
FILE *pfFile = new FILE;
FILE *pfFile = NULL;
FILE *pfFile;
etc, any ideas?
oh yeah, i also did a MessageBox output for name1, that is fine.
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Aug 22nd, 2002, 10:16 AM
#2
It should be FILE *pfFile = NULL;
but I don't know what your error is, sorry
Are you sure you call fclose for every fopen? The loop you have executes a full 1800² (= 3 240 000) times - are you sure this is necessary?
You don't call delete on "buffer", for example. After 1800 iterations it may well be that new fails, returns NULL and itoa creates an access violation.
It's better to declare buffer at the beginning of the function as
char buffer[11];
Does it crash on the first iteration?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|