Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

Am trying to send a message to list box window but i got "Access Violation Error" at the location highlighted below.


MIDL
int cstrPacketHeader= packetHeader->len;

sprintf_s(Buffer, "Lenght of Packet %d", packetHeader->len);

::SendDlgItemMessageA(Ping->m_hWnd, IDC_LIST_NIC, LB_ADDSTRING, 0, (LPARAM) Buffer);



Any solution provided will be appreciated.

Thanks
Posted

Make sure packetHeader and Ping are both valid pointers.
 
Share this answer
 
Comments
Adeji 17-Oct-10 8:59am    
Thanks Nishant.

Have declared the Ping pointer but stepping through the codes using debugging, there in no value in Ping pointer and am not sure where it goes wrong or what else need to be declare.
Nish Nishant 17-Oct-10 9:00am    
Okay, so that's what's causing the access violation.

Careful debugging should tell you how you are corrupting the pointer (it could also be due to a heap corruption elsewhere in the program).
Adeji 17-Oct-10 9:15am    
Am not sure where its going wrong.
but just to be sure that am doing the right thing, i guess all i have to do to make use of "SendDlgItemMessage" is to
declare it - CWinCapTestDlg *Ping; and use it
::SendDlgItemMessage(Ping->m_hWnd, IDC_LIST_NIC, LB_ADDSTRING, 0, (LPARAM) Buffer);

is there any other thing i have to add?

Thanks.
Nish Nishant 17-Oct-10 9:17am    
Well when you just declare a pointer variable, it's usually pointing to some random location (in release mode). You need to initialize it.
Adeji 17-Oct-10 9:23am    
This may sound stupid, but pardon me for that.

How/where do i initialize it?
Check the size of "Buffer" - is there enough room?
Shouldn't you be providing the buffer size in your sprintf_s call?
MSDN sprintf_s[^]
 
Share this answer
 
Comments
Sandeep Mewara 17-Oct-10 8:05am    
Comment from OP:
Thanks for your response.

Yes, i provided the buffer size to be "char Buffer[500];" but still it doesn't work.

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