|
In my case the above mentioned 4 cases will not be satisfied.
Actual reason is any other.:->
And also as per ur comments
int * p = NULL; delete p;
how the datas will be deleted from the location which is pointed by p initialy.
since u r saying to delete the pointer after asigning the pointer to null.
yours faithfully
ajeeshcv
|
|
|
|
|
Ajeesh c v wrote: int * p = NULL; delete p;
how the datas will be deleted from the location which is pointed by p initialy.
since u r saying to delete the pointer after asigning the pointer to null.
he doesn't say it is the things to do...
the cases enumerated are possible causes for a crash when deleting a pointer
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Ajeesh c v wrote: how the datas will be deleted from the location which is pointed by p initialy.
since u r saying to delete the pointer after asigning the pointer to null.
That's probably your problem. When you do this:
int* pTest;
if (pTest)
delete pTest;
You will have an excpetion because you try to delete memory that is unitianalized (you can only delete memory that has been allocated with new). So, to be sure not to delete this 'unexistant' memory, assign NULL to the pointer. This is safe.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
According to documentation (http://msdn2.microsoft.com/en-us/library/h6227113.aspx[^]), “You can [...] use delete on a pointer with the value 0”.
Therefore instead of
if( p != NULL )
{
delete p;
p = NULL;
}
you can use
delete p;
p = NULL;
However, this does not belong to original topic. I think you should put a breakpoint at the line where your block of memory is allocated and the pointer is assigned. Then investigate the pointer’s value and the content of the memory block. Then stop on the line where the pointer is deleted. Check if the pointer contains right address value. Try to use step-be-step execution during deletion. Perhaps the pointer points to an object having destructor, and the problem is within this function.
|
|
|
|
|
You need to be more specific, what do you mean by delete a pointer? I assume memory pointer, but these days it is hard to say. What compiler of language are you using?
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Can you show how to use pointer and how to declare pointer
whitesky
|
|
|
|
|
The pointer is of a dialog.
Initialization:
CMyDialog* pMyDialog;
pMyDialog = new CMyDialog;
pMyDialog->EndDialog(0);
if(pMyDialog)
{
delete pMyDialog;
pMyDialog = 0;
}
yours faithfully
ajeeshcv
|
|
|
|
|
im not sure your problem is this but
how to create dialog? and if you run your code i think you get a error in pMyDialog->EndDialog(0);
now try this and send me if you have a error
<br />
CMyDialog* pMyDialog;<br />
pMyDialog = new CMyDialog;<br />
pMyDialog->Create(IDD_TEST);
pMyDialog->EndDialog(0);<br />
delete pMyDialog ;<br />
pMyDialog = 0;<br />
whitesky
|
|
|
|
|
Hey ...
I am new inthis area. I am interested in knowing the values for the event masks used in GetCommMask and SetCommMask functions. ie., EV_BREAK = 0x????
How do i know which event is activated or received?
Any help/guide??
|
|
|
|
|
You can see these values in WinBase.h file, which is in a subfolder of Visual Studio.
|
|
|
|
|
hey... thanks for that. this winbase.h file explains lot of my other doubts.
|
|
|
|
|
See Here[^] maybe it is some helpful to you
whitesky
|
|
|
|
|
Thanks very much for the link. it s very helpful.
|
|
|
|
|
How to open vc8 project using vc7.1?
-- modified at 2:55 Wednesday 14th June, 2006
|
|
|
|
|
Hi,
In continuance with my earlier posts,I can now link this dll and am also able to call some of its functions without any problems.
AVCodecContext *avctx;<br />
AVCodec *codec;<br />
avctx = new AVCodecContext;<br />
codec = new AVCodec;<br />
HMODULE hDll = LoadLibrary("avcodec.dll");<br />
if(hDll== NULL)<br />
{<br />
CString str;<br />
int a = GetLastError();<br />
str.Format("%d",a);<br />
AfxMessageBox(str);<br />
AfxMessageBox("first");<br />
AfxMessageBox("Failed loading1");<br />
}<br />
<br />
typedef void (avcodec_init)();<br />
avcodec_init* p = (avcodec_init*)GetProcAddress(hDll, "avcodec_init");<br />
if(p==NULL)<br />
AfxMessageBox("Failed loading2");<br />
p();<br />
<br />
HMODULE hDll1a = LoadLibrary("avcodec.dll");<br />
typedef void (avcodec_register_all)();<br />
avcodec_register_all* p1a = (avcodec_register_all*)GetProcAddress(hDll1a, "avcodec_register_all");<br />
if(p1a==NULL)<br />
AfxMessageBox("Failed loading3");<br />
p1a();<br />
if(p1a==NULL)<br />
AfxMessageBox("Failed loading1.1");<br />
<br />
<br />
HMODULE hDll3 = LoadLibrary("avcodec.dll");<br />
typedef void (avcodec_find_encoder)(int CODECID);<br />
avcodec_find_encoder* p3 = (avcodec_find_encoder*)GetProcAddress(hDll3, "avcodec_find_encoder");<br />
if(p3==NULL)<br />
AfxMessageBox("Failed loading3");<br />
p3(CODEC_ID_MP2);<br />
if(p3==NULL)<br />
AfxMessageBox("Failed loading3");<br />
<br />
<br />
codec=(AVCodec *)p3;<br />
<br />
HMODULE hDll4 = LoadLibrary("avcodec.dll");<br />
typedef void (avcodec_alloc_context)();<br />
avcodec_alloc_context* p4 = (avcodec_alloc_context*)GetProcAddress(hDll4, "avcodec_alloc_context");<br />
if(p4==NULL)<br />
AfxMessageBox("Failed loading4");<br />
p4();<br />
if(p4==NULL)<br />
AfxMessageBox("Failed loading4");<br />
<br />
<br />
avctx=(AVCodecContext *)p4;<br />
if(avctx==NULL){<br />
CString str;<br />
int a = GetLastError();<br />
str.Format("%d",a);<br />
AfxMessageBox(str);}<br />
avctx->bit_rate=64000;<br />
The last line throws the error and AfxMessageBox simply displays the number 2. The HELP section has no entry for 2.
Somebody please help!!
|
|
|
|
|
First thing, it is unnecessary to call LoadLibrary multiple times. Once you get the handle, you can load as many functions as you want with the same handle. So remove the redundant LoadLibrary.
RahulOP wrote: avctx=(AVCodecContext *)p4;
if(avctx==NULL){
CString str;
int a = GetLastError();
str.Format("%d",a);
AfxMessageBox(str);}
avctx->bit_rate=64000;
And what are you trying to do here ? You are casting a function pointer into a pointer of type AVCodecContext*. That's logical that you will have some problems. You try to get a return from the function ? Then you need to put the exact function prototype in the typedef (with the return and the arguments of the function). Then, you can simply call it like another function and get the returned value.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Cedric Moonen wrote:
And what are you trying to do here ? You are casting a function pointer into a pointer of type AVCodecContext*. That's logical that you will have some problems. You try to get a return from the function ? Then you need to put the exact function prototype in the typedef (with the return and the arguments of the function). Then, you can simply call it like another function and get the returned value.
AVCodecContext is defined in avcodec.h as struct.
I am sorry but I havent understood what you've written. Its gone so over my head, if I were to look up, it'd be a tiny speck
|
|
|
|
|
RahulOP wrote: AVCodecContext is defined in avcodec.h as struct.
Yes, basically, what you have is a pointer to a function (p4) and you try to cast this pointer to a structure AVCodecContext. Which is of course totally impossible. Why are you trying to do such a thing ? I guess it is because the function you get from the dll must return a strcture of this type, right ?
So, what you need to do, is declaring your prototype this way. Instead of:
typedef void (avcodec_alloc_context)();
write:
typedef AVCodecContext* (avcodec_alloc_context)();
Then, once you get the function from your dll (p4), simply call the function like you would do for a standard function:
AVCodecContext *avctx = p4();
The function will be called and it will return your pointer.
I guess you want to do that but I'm not sure. Could you confirm this please ?
Important: your typedefs must match exactly the prototype of the function inside your dll !! So, if your func returns an int, the typedef needs to return an int also.
BTW, where is this dll coming from ? Don't you have a header file and a lib file supplied with it ? This will be much easier for you.
Another thing: I see that on the top of the code snippet, you create a new VCodecContext structure (using new) but later, you assign a new value to this pointer. So, the memory is never released and you get a memory leak.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I am using FFMPEG. Rather I built FFMPEG using MSYS and am using the dlls I got from there. Yes I got the lib files as well and trying to do the same avocdec_init(); directly gave me a lot of linker errors LNK 2019 and LNK2001.
You can see the avcodec.h file here
http://svn.mplayerhq.hu/ffmpeg/trunk/libavcodec/
There's also an apiexample.c which is what I am trying to work off from.
I was under the impression that I am supposed to use the new when I initialise.
Thank you for your help so far
|
|
|
|
|
You didn't answer my question: are you trying to do what I asked ? So, you have a function that returns a strcture (or a pointer to the struct) and you want to get it ? What is the exact prototype of the function "avcodec_alloc_context" ?
RahulOP wrote: gave me a lot of linker errors LNK 2019 and LNK2001
Did you link properly to the lib file ? So, did you add the lib in the project settings ? Instead of taking a complicated way, why don't you simply try to correct the initial errors ?
If this dll is supplied with a lib file and a header file, then you can simply implicitely load the dll (not using LoadLibrary and GetProcAddress, but simply add the header file to your project and link to the library), this is much more easier to manage.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I think he's shooting in the dark!
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
VuNic wrote: I think he's shooting in the dark!
Mostly
ffmpeg was written for LINUX. All I am trying to do is create a simple application that will encode audio/video files. Trying this with the dlls.
|
|
|
|
|
Quoting from the apiexample.c
AVCodec *codec;<br />
AVCodecContext *c= NULL;<br />
int frame_size, i, j, out_size, outbuf_size;<br />
FILE *f;<br />
short *samples;<br />
float t, tincr;<br />
uint8_t *outbuf;<br />
<br />
codec = avcodec_find_encoder(CODEC_ID_MP2);<br />
c= avcodec_alloc_context();<br />
<br />
c->bit_rate = 64000;<br />
c->sample_rate = 44100;<br />
c->channels = 2;
This is what I am trying to re-write.
This is how alloc_code_context is defined in the .h file
AVCodecContext *avcodec_alloc_context(void);
I just tried this
typedef AVCodecContext*(avcodec_alloc_context)(); and I didnt have any errors.It ran perfectly.
Though yes, there is something about memory leaks.Thank you so much for the heads-up
|
|
|
|
|
It seems that you didn't read properly everything I wrote . Or you didn't understand. Basically, it's exactly what I'm trying to say till the begining: that you have to use the exact prototype for the typedef (so, with return type and parameters).
Anyway, why don't you focus on your main problem ? Which is these link errors you get when you use the header and the lib ? Did you even try that ? Are you sure you properly linked to the library ?
Please when answering, read at least my post and answer the questions I ask (there is a reason for which I ask these, even if this is pretty obscure to you).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I am so sorry.
I tried the typedef AVCodecContext* thingy based on your post except that I didnt quote it in my reply.
I believe I am properly linked to the library files. These are the steps I followed
In the project Properties Select C/C++ General Tab
and set the path for 'Include directories' seperated by semicolon( i.e path to libavcodec, libavformat)
In the Linker Tab put the path to Lib files of ffmpeg in the option 'Additional Library Directories path' (i.e the path to avformat.lib etc)
In the Linker Tab Put the Library files names to the option 'Additional dependencies' ( avformat.lib avcodec.lib)
These are the linker errors I am getting
fflib2 error LNK2001: unresolved external symbol ___divdi3
fflib2 error LNK2001: unresolved external symbol ___divdi3
fflib2 error LNK2019: unresolved external symbol ___divdi3 referenced in function _av_reduce
fflib2 error LNK2001: unresolved external symbol ___divdi3
fflib2 error LNK2001: unresolved external symbol ___divdi3
fflib2 error LNK2001: unresolved external symbol ___divdi3
fflib2 error LNK2019: unresolved external symbol ___moddi3 referenced in function _av_reduce
fflib2 error LNK2001: unresolved external symbol ___moddi3
fflib2 error LNK2001: unresolved external symbol ___moddi3
fflib2 error LNK2001: unresolved external symbol __alloca
fflib2 error LNK2001: unresolved external symbol __alloca
fflib2 error LNK2019: unresolved external symbol __alloca referenced in function _rd8x8_c
fflib2 error LNK2001: unresolved external symbol __alloca
fflib2 error LNK2001: unresolved external symbol __alloca
fflib2 error LNK2001: unresolved external symbol __alloca
fflib2 error LNK2019: unresolved external symbol ___udivdi3 referenced in function _mpeg1_encode_sequence_header
fflib2 error LNK2019: unresolved external symbol ___udivdi3 referenced in function _MPV_common_end
fflib2 error LNK2019: unresolved external symbol ___umoddi3 referenced in function _mpeg1_encode_sequence_header
fflib2 error LNK2019: unresolved external symbol ___fixunssfdi referenced in function _ff_rate_control_init
fflib2 error LNK2019: unresolved external symbol ___fixunsdfdi referenced in function _ff_rate_estimate_qscale
p.s. Would you mind giving me your e-mail address?
|
|
|
|