×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Borland C++ Builder 3 - Memory access below 0x00010000

Borland C++ Builder 3 - Memory access below 0x00010000

Borland C++ Builder 3 - Memory access below 0x00010000

(OP)
When I try to access memory locations below 0x00010000 (bios memory area) using Borland C++ Builder 3 I receive a EAccess Violation exception. Could anybody explain how to access this area of memory without a exception being thrown? In anticipation, thank you.

RE: Borland C++ Builder 3 - Memory access below 0x00010000

First some questions:

Under what OS are you trying to do this?? (Windows is really fussy about direct memory access)
What methods are you using to access the memory?
Are you trying to read or write to the memory?
Finnally, could you post the code if it isn't too long or a snippet if it's bulky...


Kim_Christensen@telus.net
Home Page

RE: Borland C++ Builder 3 - Memory access below 0x00010000

(OP)
Dear Kim,
thank you for responding to my question.

I am using Windows NT 4.0 with Service Pack 6a and I am initially trying to read address 0x400 (COM port location). My console program code is as follows:


#pragma hdrstop
#include <condefs.h>
#include <stdio.h>
#include <dos.h>

//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char **argv)
{
 unsigned int *ptraddr;  /* Pointer to location of Port Addresses */
 unsigned int address;       /* Address of Port */
 int a;

 ptraddr=(unsigned int *)0x00000400;

 for (a = 0; a <  4; a++)
   {
    address = *ptraddr; //**** error! ****
    if (address == 0)
                printf("No port found for COM%d \n",a+1);
    else
                printf("Address assigned to COM%d is %Xh\n",a+1,address);
    *ptraddr++;
   }

}


This code generates an EAccessViolation error message at the line marked **** error! ****. If you could help it would be really appreciated. Once again, in anticpation, thank you.

RE: Borland C++ Builder 3 - Memory access below 0x00010000

I 've tried this code but it was running fine. Can you have a look over it ?







                          #pragma hdrstop
//                          #include <condefs.h>
                          #include <stdio.h>
                          #include <dos.h>

                          //---------------------------------------------------------------------------
#pragma argsused
                          int main(int argc, char **argv)
                          {
                           unsigned int *ptraddr;  /* Pointer to location of Port Addresses */
unsigned int *address1;       
                           int a;
  ptraddr=(unsigned int *)0x00000400;
                         //  ptraddr=(unsigned int *)0x00000400;

                           for (a = 0; a <  4; a++)
                             {
                              address1 = ptraddr; //**** error! ****
                              if (address1 == 0x00000000)
                                          printf("No port found for COM%d \n",a+1);
                              else
                                          printf("Address assigned to COM%d is %Xh\n",a+1,address1);
                              *ptraddr++;
                             }
return 0;
                          }

RE: Borland C++ Builder 3 - Memory access below 0x00010000

(OP)
Dear Ssing,
firstly thank you for attempting to answer my question. Unfortunately, whilst your code runs without error, it does not read the contents of the memory location (0x400) as no indirection operator is used with 'ptraddr'.
If you could look at the problem again, or anybody else has an answer to the problem, it would be most appreciated.

RE: Borland C++ Builder 3 - Memory access below 0x00010000

I'm no expert on WinNt programming, but can't you use the SetCommState & CreateFile functions etc to deal with the com ports? Below is an excerpt from a Win32 help file:

The SetCommState function configures a communications device according to the specifications in a device-control block (a DCB structure). The function reinitializes all hardware and control settings, but it does not empty output or input queues.

BOOL SetCommState(

    HANDLE hFile, // handle of communications device
    LPDCB lpDCB // address of device-control block structure
   );
Parameters

hFile

Identifies the communications device. The CreateFile function returns this handle.

lpDCB

Points to a DCB structure containing the configuration information for the specified communications device.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The SetCommState function uses a DCB structure to specify the desired configuration. The GetCommState function returns the current configuration.
To set only a few members of the DCB structure, you should modify a DCB structure that has been filled in by a call to GetCommState. This ensures that the other members of the DCB structure have appropriate values.
The SetCommState function fails if the XonChar member of the DCB structure is equal to the XoffChar member.

When SetCommState is used to configure the 8250, the following restrictions apply to the values for the DCB structure’s ByteSize and StopBits members:

· The number of data bits must be 5 to 8 bits.
· The use of 5 data bits with 2 stop bits is an invalid combination, as are 6, 7, or 8 data bits with 1.5 stop bits.


Kim_Christensen@telus.net
Home Page

RE: Borland C++ Builder 3 - Memory access below 0x00010000

Dear BailSoft,
 I 've tried for  all the possible permutation and combination. But this line
 address = *ptraddr; //**** error! ****

is giving error for all the memory areas.

PLEASE let me know if for any memory section this line runs properly.

AWAITING for your answer

Thanx
Siddhartha Singh
ssingh@aztecsoft.com

RE: Borland C++ Builder 3 - Memory access below 0x00010000

(OP)
Dear Kim,
thanks for your help. As you suggested I am going to use the SetCommState & CreateFile functions.

Dear Siddhartha,
thanks for you help. In answer to your question the line of code 'address = *ptraddr;' runs OK on my machine for memory addresses equal to greater than 0x10000.

RE: Borland C++ Builder 3 - Memory access below 0x00010000

Bailsoft,
    You may want to look at BCBDEV's Site ( www.bcbdev.com ). They have some components that work with the serial ports. Look under components for PORTS and TCommPort.

James P. Cottingham
main@ivcusa.com
International Veneer Co., Inc.
All opinions are mine alone and do not necessarily reflect those of my employer.

RE: Borland C++ Builder 3 - Memory access below 0x00010000

(OP)
Thanks 2ffat, I'll check it out now!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close