Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

bailsoft

Technical User
Mar 28, 2000
14
0
0
GB
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.
 
First some questions:<br><br>Under what OS are you trying to do this?? (Windows is really fussy about direct memory access)<br>What methods are you using to access the memory?<br>Are you trying to read or write to the memory?<br>Finnally, could you post the code if it isn't too long or a snippet if it's bulky...<br><br> <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
Dear Kim,<br>thank you for responding to my question.<br><br>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:<br><br><FONT FACE=monospace><br>#pragma hdrstop<br>#include &lt;condefs.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;dos.h&gt;<br><br>//---------------------------------------------------------------------------<br>#pragma argsused<br>int main(int argc, char **argv)<br>{<br>&nbsp;unsigned int *ptraddr;&nbsp;&nbsp;/* Pointer to location of Port Addresses */<br>&nbsp;unsigned int address;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Address of Port */<br>&nbsp;int a;<br><br>&nbsp;ptraddr=(unsigned int *)0x00000400;<br><br>&nbsp;for (a = 0; a &lt;&nbsp;&nbsp;4; a++)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;address = *ptraddr; <font color=red>//**** error! ****</font><br>&nbsp;&nbsp;&nbsp;&nbsp;if (address == 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;No port found for COM%d \n&quot;,a+1);<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Address assigned to COM%d is %Xh\n&quot;,a+1,address);<br>&nbsp;&nbsp;&nbsp;&nbsp;*ptraddr++;<br>&nbsp;&nbsp;&nbsp;}<br><br>}<br></font><br><br>This code generates an EAccessViolation error message at the line marked <font color=red>**** error! ****</font>. If you could help it would be really appreciated. Once again, in anticpation, thank you.<br><br>
 
I 've tried this code but it was running fine. Can you have a look over it ?<br><br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#pragma hdrstop<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;condefs.h&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;stdio.h&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;dos.h&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//---------------------------------------------------------------------------<br>#pragma argsused<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int main(int argc, char **argv)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unsigned int *ptraddr;&nbsp;&nbsp;/* Pointer to location of Port Addresses */<br> unsigned int *address1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int a;<br>&nbsp;&nbsp;ptraddr=(unsigned int *)0x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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>return 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
Dear Ssing,<br>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'.<br>If you could look at the problem again, or anybody else has an answer to the problem, it would be most appreciated.
 
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:<br><br>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. <br><br>BOOL SetCommState(<br><br>&nbsp;&nbsp;&nbsp;&nbsp;HANDLE hFile, // handle of communications device<br>&nbsp;&nbsp;&nbsp;&nbsp;LPDCB lpDCB // address of device-control block structure<br>&nbsp;&nbsp;&nbsp;); <br>Parameters<br><br>hFile<br><br>Identifies the communications device. The CreateFile function returns this handle. <br><br>lpDCB<br><br>Points to a DCB structure containing the configuration information for the specified communications device. <br><br>Return Values<br><br>If the function succeeds, the return value is nonzero.<br>If the function fails, the return value is zero. To get extended error information, call GetLastError. <br><br>Remarks<br><br>The SetCommState function uses a DCB structure to specify the desired configuration. The GetCommState function returns the current configuration. <br>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. <br>The SetCommState function fails if the XonChar member of the DCB structure is equal to the XoffChar member. <br><br>When SetCommState is used to configure the 8250, the following restrictions apply to the values for the DCB structure’s ByteSize and StopBits members: <br><br>· The number of data bits must be 5 to 8 bits. <br>· 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. <br><br> <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
Dear BailSoft,<br>&nbsp;I 've tried for&nbsp;&nbsp;all the possible permutation and combination. But this line<br>&nbsp;address = *ptraddr; //**** error! ****<br><br>is giving error for all the memory areas. <br><br>PLEASE let me know if for any memory section this line runs properly.<br><br>AWAITING for your answer<br><br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
Dear Kim,<br>thanks for your help. As you suggested I am going to use the SetCommState & CreateFile functions.<br><br>Dear Siddhartha,<br>thanks for you help. In answer to your question the line of code '<FONT FACE=monospace>address = *ptraddr;</font>' runs OK on my machine for memory addresses equal to greater than 0x10000.<br>
 
Bailsoft,<br>&nbsp;&nbsp;&nbsp;&nbsp;You may want to look at BCBDEV's Site ( <A HREF=" TARGET="_new"> ). They have some components that work with the serial ports. Look under <i>components</i> for <b>PORTS</b> and <b>TCommPort</b>.<br> <p>James P. Cottingham<br><a href=mailto:main@ivcusa.com>main@ivcusa.com</a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top