473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Access violation error inVC++

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<windows.h>
#define WIDTH 16
#define TOPBIT (1<<15)





USHORT bytewisecrc(DWORD framesize,DWORD *recvbuf[])
{
USHORT table[] = { 0X0000,0X1021,0X2042,0X3063,0X4084,0X50A5,0X60C6,0 X70E7,
0X8108,0X9129,0XA14A,0XB16B,0XC18C,0XD1AD,0XE1CE,0 XF1EF,
0X1231,0X0210,0X3273,0X2252,0X52B5,0X4294,0X72F7,0 X62D6,
0X9339,0X8318,0XB37B,0XA35A,0XD3BD,0XC39C,0XF3FF,0 XE3DE,
0X2462,0X3443,0X0420,0X1401,0X64E6,0X74C7,0X44A4,0 X5485,
0XA56A,0XB54B,0X8528,0X9509,0XE5EE,0XF5CF,0XC5AC,0 XD58D,
0X3653,0X2672,0X1611,0X0630,0X76D7,0X66F6,0X5695,0 X46B4,
0XB75B,0XA77A,0X9719,0X8738,0XF7DF,0XE7FE,0XD79D,0 XC7BC,
0X48C4,0X58E5,0X6886,0X78A7,0X0840,0X1861,0X2802,0 X3823,
0XC9CC,0XD9ED,0XE98E,0XF9AF,0X8948,0X9969,0XA90A,0 XB92B,
0X5AF5,0X4AD4,0X7AB7,0X6A96,0X1A71,0X0A50,0X3A33,0 X2A12,
0XDBFD,0XCBDC,0XFBBF,0XEB9E,0X9B79,0X8B58,0XBB3B,0 XAB1A,
0X6CA6,0X7C87,0X4CE4,0X5CC5,0X2C22,0X3C03,0X0C60,0 X1C41,
0XEDAE,0XFD8F,0XCDEC,0XDDCD,0XAD2A,0XBD0B,0X8D68,0 X9D49,
0X7E97,0X6EB6,0X5ED5,0X4EF4,0X3E13,0X2E32,0X1E51,0 X0E70,
0XFF9F,0XEFBE,0XDFDD,0XCFFC,0XBF1B,0XAF3A,0X9F59,0 X8F78,
0X9188,0X81A9,0XB1CA,0XA1EB,0XD10C,0XC12D,0XF14E,0 XE16F,
0X1080,0X00A1,0X30C2,0X20E3,0X5004,0X4025,0X7046,0 X6067,
0X83B9,0X9398,0XA3FB,0XB3DA,0XC33D,0XD31C,0XE37F,0 XF35E,
0X02B1,0X1290,0X22F3,0X32D2,0X4235,0X5214,0X6277,0 X7256,
0XB5EA,0XA5CB,0X95A8,0X8589,0XF56E,0XE54F,0XD52C,0 XC50D,
0X34E2,0X24C3,0X14A0,0X0481,0X7466,0X6447,0X5424,0 X4405,
0XA7DB,0XB7FA,0X8799,0X97B8,0XE75F,0XF77E,0XC71D,0 XD73C,
0X26D3,0X36F2,0X0691,0X16B0,0X6657,0X7676,0X4615,0 X5634,
0XD94C,0XC96D,0XF90E,0XE92F,0X99C8,0X89E9,0XB98A,0 XA9AB,
0X5844,0X4865,0X7806,0X6827,0X18C0,0X08E1,0X3882,0 X28A3,
0XCB7D,0XDB5C,0XEB3F,0XFB1E,0X8BF9,0X9BD8,0XABBB,0 XBB9A,
0X4A75,0X5A54,0X6A37,0X7A16,0X0AF1,0X1AD0,0X2AB3,0 X3A92,
0XFD2E,0XED0F,0XDD6C,0XCD4D,0XBDAA,0XAD8B,0X9DE8,0 X8DC9,
0X7C26,0X6C07,0X5C64,0X4C45,0X3CA2,0X2C83,0X1CE0,0 X0CC1,
0XEF1F,0XFF3E,0XCF5D,0XDF7C,0XAF9B,0XBFBA,0X8FD9,0 X9FF8,
0X6E17,0X7E36,0X4E55,0X5E74,0X2E93,0X3EB2,0X0ED1,0 X1EF0};

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(framesize,recvbuf[framesize]);

there is a access violation error while running the program.
Oct 15 '07 #1
1 1842
RRick
463 Expert 256MB
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
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...
0
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...
7
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...
0
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...
1
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++...
2
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...
0
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...
2
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...
39
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.