473,770 Members | 6,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access violation error inVC++

62 New Member
i have a program to calculate the CRC for a group of array values.
SO i have program in a different file and i am passing the length and the array to the function and i am getting a access voilation error. couldnt understand why? plz help,
here is my code

crc file code

#include<stdio. h>
#include<window s.h>
#define WIDTH 16
#define TOPBIT (1<<15)





USHORT bytewisecrc(DWO RD framesize,DWORD *recvbuf[])
{
USHORT table[] = { 0X0000,0X1021,0 X2042,0X3063,0X 4084,0X50A5,0X6 0C6,0X70E7,
0X8108,0X9129,0 XA14A,0XB16B,0X C18C,0XD1AD,0XE 1CE,0XF1EF,
0X1231,0X0210,0 X3273,0X2252,0X 52B5,0X4294,0X7 2F7,0X62D6,
0X9339,0X8318,0 XB37B,0XA35A,0X D3BD,0XC39C,0XF 3FF,0XE3DE,
0X2462,0X3443,0 X0420,0X1401,0X 64E6,0X74C7,0X4 4A4,0X5485,
0XA56A,0XB54B,0 X8528,0X9509,0X E5EE,0XF5CF,0XC 5AC,0XD58D,
0X3653,0X2672,0 X1611,0X0630,0X 76D7,0X66F6,0X5 695,0X46B4,
0XB75B,0XA77A,0 X9719,0X8738,0X F7DF,0XE7FE,0XD 79D,0XC7BC,
0X48C4,0X58E5,0 X6886,0X78A7,0X 0840,0X1861,0X2 802,0X3823,
0XC9CC,0XD9ED,0 XE98E,0XF9AF,0X 8948,0X9969,0XA 90A,0XB92B,
0X5AF5,0X4AD4,0 X7AB7,0X6A96,0X 1A71,0X0A50,0X3 A33,0X2A12,
0XDBFD,0XCBDC,0 XFBBF,0XEB9E,0X 9B79,0X8B58,0XB B3B,0XAB1A,
0X6CA6,0X7C87,0 X4CE4,0X5CC5,0X 2C22,0X3C03,0X0 C60,0X1C41,
0XEDAE,0XFD8F,0 XCDEC,0XDDCD,0X AD2A,0XBD0B,0X8 D68,0X9D49,
0X7E97,0X6EB6,0 X5ED5,0X4EF4,0X 3E13,0X2E32,0X1 E51,0X0E70,
0XFF9F,0XEFBE,0 XDFDD,0XCFFC,0X BF1B,0XAF3A,0X9 F59,0X8F78,
0X9188,0X81A9,0 XB1CA,0XA1EB,0X D10C,0XC12D,0XF 14E,0XE16F,
0X1080,0X00A1,0 X30C2,0X20E3,0X 5004,0X4025,0X7 046,0X6067,
0X83B9,0X9398,0 XA3FB,0XB3DA,0X C33D,0XD31C,0XE 37F,0XF35E,
0X02B1,0X1290,0 X22F3,0X32D2,0X 4235,0X5214,0X6 277,0X7256,
0XB5EA,0XA5CB,0 X95A8,0X8589,0X F56E,0XE54F,0XD 52C,0XC50D,
0X34E2,0X24C3,0 X14A0,0X0481,0X 7466,0X6447,0X5 424,0X4405,
0XA7DB,0XB7FA,0 X8799,0X97B8,0X E75F,0XF77E,0XC 71D,0XD73C,
0X26D3,0X36F2,0 X0691,0X16B0,0X 6657,0X7676,0X4 615,0X5634,
0XD94C,0XC96D,0 XF90E,0XE92F,0X 99C8,0X89E9,0XB 98A,0XA9AB,
0X5844,0X4865,0 X7806,0X6827,0X 18C0,0X08E1,0X3 882,0X28A3,
0XCB7D,0XDB5C,0 XEB3F,0XFB1E,0X 8BF9,0X9BD8,0XA BBB,0XBB9A,
0X4A75,0X5A54,0 X6A37,0X7A16,0X 0AF1,0X1AD0,0X2 AB3,0X3A92,
0XFD2E,0XED0F,0 XDD6C,0XCD4D,0X BDAA,0XAD8B,0X9 DE8,0X8DC9,
0X7C26,0X6C07,0 X5C64,0X4C45,0X 3CA2,0X2C83,0X1 CE0,0X0CC1,
0XEF1F,0XFF3E,0 XCF5D,0XDF7C,0X AF9B,0XBFBA,0X8 FD9,0X9FF8,
0X6E17,0X7E36,0 X4E55,0X5E74,0X 2E93,0X3EB2,0X0 ED1,0X1EF0};

USHORT data;
USHORT crc;
int byt;
USHORT remainder = 0Xffff;

for ( byt = 0; byt <framesize; ++byt)
{
data = (USHORT)recvbuf[byt] ^ (remainder >> (WIDTH - 8));

remainder = table[data] ^ (remainder << 8);
crc = remainder;
}
return (crc);
}



and in my main i have this code

DWORD recvbuf[] = {0XAA,0X31,0X01 ,0XC6,0X1E,0X36 ,0X44,0X85,0X27 ,0XF0,0X56,0X07 ,0X10,0X98,0X00 ,0X0F,0X42,0X40 ,0X00,0X01,0X53 ,0X74,0X61,0X74 ,0X69,0X6F,0X6E ,0X20,0X41,0X20 ,0X20,0X20,0X20 ,0X20,0X20,0X20 ,0X1E,0X36,0X00 ,0X04,0X00,0X04 ,0X00,0X03,0X00 ,0X01,0X56,0X41 ,0X20,0X20,0X20 ,0X20}


DWORD crccalculated;

crccalculated = bytewisecrc(fra mesize,recvbuf[framesize]);

there is a access violation error while running the program.
Oct 15 '07 #1
1 1890
RRick
463 Recognized Expert Contributor
I would double check the call to the subroutine.
Expand|Select|Wrap|Line Numbers
  1. crccalculated = bytewisecrc(framesize,recvbuf[framesize]);
  2.  
You are passing a recvbuf[framesize] which is supposed to be a pointer, but instead is a value from the array. This can cause an access violation.

I'm suprised this compiled. Didn't you at least get a warning from the compiler?
Oct 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
18031
by: Steven Reddie | last post by:
I understand that access violations aren't part of the standard C++ exception handling support. On Windows, a particular MSVC compiler option enables Microsoft's Structured Exception Handling (SEH) in C++ EH so that a catch (...) will catch an access violation. I don't know if other platforms support something similar. I'm wondering about how to best protect an application or library from poorly written user-defined callbacks. It...
0
2724
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access violations aren't part of the standard C++ >> exception handling support. On Windows, a particular MSVC compiler >> option enables Microsoft's Structured Exception Handling (SEH) in C++ >> EH so that a catch (...) will catch an access violation. ...
7
3140
by: Daniel | last post by:
I want to write a method to remove the last node of the linked list. But the error "Access Violation" exists and the error point to this method. What does it means by Access Violation and how can I debug it? Thanks void RemoveNode(StepNodePtr pList) { StepNodePtr preq, q; q = pList; preq = pList;
0
1814
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a TabControl to my form and placed a
1
13906
by: =?Utf-8?B?c2F0aGVlc2t1bWFy?= | last post by:
In my project i have a component named PTS Engine which is developed in VC++ ..Net 2003. And it is migrated to VC++.NET 2005 version. Initially this migration process has coded and tested in VC++ .NET 2005 Beta version. In beta version everything is working fine. When i tryied to run in .NET 2005 full version i am facing the following access violation Error. "Unhandled exception at 0x4bc0145c in Engine.exe: 0xc0000005: Access Violation...
2
2317
by: jthep | last post by:
I'm trying to get this piece of code I converted from C to work in C++ but I'm getting an access violation error. Problem occurs at line 61. Someone can help me with this? The function display(llist mylist) displays a list of choices for a record book: void display(llist mylist) { char name, address, telno, input; int yearofbirth, choice, records; yearofbirth = 0;
0
1751
by: Paavo Helde | last post by:
Shawn <sfncook@gmail.comwrote in news:6410e273-318e-44a0-9735-b922366ca1ab@w1g2000prd.googlegroups.com: I bet you have some multithreading access error. Ensure that your threads do not read or write any shared variables without proper locking. If you are not able to spot the error by the code inspection, then I suggest the Intel Thread Checker tool - it finds such kind of errors for you automatically (although not necessarily faster...
2
4294
by: =?Utf-8?B?c29jYXRvYQ==?= | last post by:
Hi, I have a DLL in VC6, when a specific function is called it will spawns a few threads and then return. The threads stay running and inside one of these threads an event is created using the win32 CreateEvent() call: Code Snippet static HANDLE hReadyEvent;
39
4291
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it just now, I am getting the subject error message (specifically: PHP has encountered an access violation at 00F76E21). The error is NOT occurring on every page request (but it is on most of them) and, when I get the error, simply pressing <F5to...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.