Click here to Skip to main content
15,899,026 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: get millisecond Pin
David Crow23-Jun-06 3:42
David Crow23-Jun-06 3:42 
Questionmsvc keeps recompiling all Pin
ehh22-Jun-06 9:11
ehh22-Jun-06 9:11 
AnswerRe: msvc keeps recompiling all Pin
PJ Arends22-Jun-06 19:52
professionalPJ Arends22-Jun-06 19:52 
Questionproblem walking all over an array Pin
pblais22-Jun-06 9:04
pblais22-Jun-06 9:04 
AnswerRe: problem walking all over an array Pin
Zac Howland22-Jun-06 9:27
Zac Howland22-Jun-06 9:27 
GeneralRe: problem walking all over an array Pin
pblais22-Jun-06 10:21
pblais22-Jun-06 10:21 
GeneralRe: problem walking all over an array Pin
David Crow23-Jun-06 3:49
David Crow23-Jun-06 3:49 
GeneralRe: problem walking all over an array Pin
pblais23-Jun-06 10:53
pblais23-Jun-06 10:53 
Ok... David.. I'll retype the whole thing again

In the header file for the main dialog app, I have the following code:
#include "APM_Driver.h"<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// CAPM_CPDlg dialog<br />
<br />
class CAPM_CPDlg : public CDialog<br />
{<br />
// Construction<br />
public:<br />
	CAPM_CPDlg(CWnd* pParent = NULL);	// standard constructor<br />
<br />
	APM_Driver	*MYDLL;<br />


In the main cpp file for the dialog app, I have the following code:
/////////////////////////////////////////////////////////////////////////////<br />
// CAPM_CPDlg message handlers<br />
<br />
BOOL CAPM_CPDlg::OnInitDialog()<br />
{<br />
	CDialog::OnInitDialog();<br />
<br />
	// IDM_ABOUTBOX must be in the system command range.<br />
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);<br />
	ASSERT(IDM_ABOUTBOX < 0xF000);<br />
<br />
	CMenu* pSysMenu = GetSystemMenu(FALSE);<br />
	if (pSysMenu != NULL)<br />
	{<br />
		CString strAboutMenu;<br />
		strAboutMenu.LoadString(IDS_ABOUTBOX);<br />
		if (!strAboutMenu.IsEmpty())<br />
		{<br />
			pSysMenu->AppendMenu(MF_SEPARATOR);<br />
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);<br />
		}<br />
	}<br />
<br />
	// Set the icon for this dialog.  The framework does this automatically<br />
	//  when the application's main window is not a dialog<br />
	SetIcon(m_hIcon, TRUE);			// Set big icon<br />
	SetIcon(m_hIcon, FALSE);		// Set small icon<br />
	<br />
	MYDLL = new APM_Driver;<br />


In the dll header file I have the following code:
// APM_Driver.h: interface for the APM_Driver class.<br />
//<br />
<br />
#if !defined(AFX_APM_Driver_H__C456738C_8198_48CC_8DE2_25874D70899F__INCLUDED_)<br />
#define AFX_APM_Driver_H__C456738C_8198_48CC_8DE2_25874D70899F__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
<br />
#include "APM_exportheader.h"<br />
.<br />
.<br />
.<br />
class APM_API APM_Driver  <br />
{<br />
public:<br />
	APM_Driver();<br />
	virtual ~APM_Driver();<br />
<br />
	char	GetGetSomething();<br />
<br />
	byte	ROM_Buffer[100];   <----BAD LINE<br />
	byte	RxBuffer[256];<br />
	byte	TxBuffer[256];<br />
.<br />
.<br />
.<br />
};<br />
<br />
#endif // !defined(AFX_APM_Driver_H__C456738C_8198_48CC_8DE2_25874D70899F__INCLUDED_)<br />


in APM_exportheader.h, I have the following code:
// The following ifdef block is the standard way of creating macros which make exporting <br />
// from a DLL simpler. All files within this DLL are compiled with the EXPORT_FUNCTIONS<br />
// symbol defined on the command line. this symbol should not be defined on any project<br />
// that uses this DLL. This way any other project whose source files include this file see <br />
// EXPORT_FUNCTIONS functions as being imported from a DLL, wheras this DLL sees symbols<br />
// defined with this macro as being exported.<br />
<br />
	#ifdef EXPORT_FUNCTIONS<br />
		#define APM_API __declspec(dllexport)<br />
	#else<br />
		#define APM_API __declspec(dllimport)<br />
	#endif<br />


In the dll cpp file, I have the following code:
// APM_Driver.cpp: implementation of the APM_Driver class.<br />
//<br />
#include "APM_Driver.h"<br />
.<br />
.<br />
.<br />
char APM_Driver::GetGetSomething()<br />
{<br />
	char	data_1[] = {1,1,12,0};<br />
<br />
	char	i_loop1 = 0;<br />
	for(i_loop1 = 0; i_loop1 <= data_1[1] + 1; i_loop1++)<br />
		data_1[3] ^= data_1[i_loop1];<br />
<br />
	comms1->Output(data_1, 4);<br />
	comms1->FlushRxBuffer();<br />
<br />
	data_byte_recieved = false;<br />
<br />
	Timeout = 100;<br />
	while(data_byte_recieved == false)<br />
	{<br />
		RX_Handler();<br />
		Sleep(5);<br />
		if(Timeout-- == 0)<br />
 			return 1;<br />
	}<br />
<br />
	char	c_CRC = 0;<br />
<br />
	RxBuffer[0]--;<br />
	c_CRC ^= RxBuffer[0];<br />
	for(i_loop1 = 1; i_loop1 <= RxBuffer[0]; i_loop1++)<br />
		c_CRC ^= RxBuffer[i_loop1];<br />
<br />
	c_CRC ^= RxBuffer[i_loop1];<br />
<br />
	if(c_CRC)<br />
		return	1;	// Wrong Checksum<br />
	else<br />
		return	0;	// Correct Checksum<br />
}<br />


The only reason I have for why it is so spaghetti like this, other than the fact that I inherited this is as follows. We, the Microelectronics people, design hardware that has to be tested with a PC. We try to keep the items that are specific to the hardware only in a DLL so we can turn it over to the test group later. We build our own Control Panels, hence the CP in the main dialog name to test and debug our designs. The test group, in turn uses the DLL in a "big picture" to test a complete system.

That being said, I have a piece of hardware "hanging" off the PC's come port. In this case, this hardware is an APM. In this particular example, the control panel needs to read the version of the firmware that is in the APM so it has to call GetSomething(). It does this as follows:
void CAPM_CPDlg::OnConnect() <br />
{<br />
	CString		Display_Data = "";<br />
	unsigned int	iTemp = 0;<br />
	<br />
	Display_Data += "          D E B U G  -  I N F O";<br />
	Display_Data += "\r\n";<br />
	Display_Data += "----------------------------------------------------";<br />
	Display_Data += "\r\n";<br />
<br />
<br />
	if(DUT->GetSomething())<br />
	{<br />
		Display_Data += "APM PIC	: ";<br />
		Display_Data += MYDLL->RxBuffer[1];<br />
		Display_Data += MYDLL->RxBuffer[2];<br />
		Display_Data += MYDLL->RxBuffer[3];<br />
		Display_Data += MYDLL->RxBuffer[4];<br />
		Display_Data += MYDLL->RxBuffer[5];<br />
		Display_Data += MYDLL->RxBuffer[6];<br />
		Display_Data += MYDLL->RxBuffer[7];<br />
		Display_Data += MYDLL->RxBuffer[8];<br />
		Display_Data += MYDLL->RxBuffer[9];<br />
		Display_Data += MYDLL->RxBuffer[10];<br />
		Display_Data += MYDLL->RxBuffer[11];<br />
		Display_Data += MYDLL->RxBuffer[12];<br />
		Display_Data += MYDLL->RxBuffer[13];<br />
		Display_Data += "\r\n";<br />
	}<br />
	else<br />
		Display_Data += "Not Connected";<br />
	SetDlgItemText(IDC_DISPLAY, Display_Data);	<br />
}<br />


If I comment the BAD LINE indicated above in the dll header file, everything runs fine. If I dont comment it out the following happens:

When I put a break in the GetSomething() function inside the DLL, RxBuffer is good but if I put a break in the control panel, MYDLL->RxBuffer is trashed.

If I move the declaration of ROM_Buffer below RxBuffer a few lines below the TxBuffer declaration, it works. But, I have a feeling I am trashing something else.

ALLLLLLLLLLLSO....
if I increase the size of ROM_Buffer to 200 I get this when I try to run it.....

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: D:\Projects\APM\Software\Release\APM_CP.exe
File: dbgheap.c
Line: 1099

Expression: _pLastBlock == pHead

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
---------------------------
Abort   Retry   Ignore   
---------------------------


There David... is that enough information????

Regards
Pierre
GeneralRe: problem walking all over an array Pin
Zac Howland25-Jun-06 8:45
Zac Howland25-Jun-06 8:45 
GeneralRe: problem walking all over an array Pin
pblais26-Jun-06 9:06
pblais26-Jun-06 9:06 
GeneralRe: problem walking all over an array Pin
Zac Howland26-Jun-06 9:28
Zac Howland26-Jun-06 9:28 
GeneralRe: problem walking all over an array Pin
pblais26-Jun-06 10:13
pblais26-Jun-06 10:13 
GeneralRe: problem walking all over an array Pin
Zac Howland26-Jun-06 10:25
Zac Howland26-Jun-06 10:25 
Questionabout printing formulars Pin
ivanris22-Jun-06 8:08
ivanris22-Jun-06 8:08 
Questionmultiple selections in List View (LVS) Pin
aafcls22-Jun-06 8:04
aafcls22-Jun-06 8:04 
AnswerRe: multiple selections in List View (LVS) Pin
Michael Dunn22-Jun-06 8:28
sitebuilderMichael Dunn22-Jun-06 8:28 
GeneralRe: multiple selections in List View (LVS) Pin
aafcls22-Jun-06 8:48
aafcls22-Jun-06 8:48 
GeneralRe: multiple selections in List View (LVS) Pin
Zac Howland22-Jun-06 9:40
Zac Howland22-Jun-06 9:40 
GeneralRe: multiple selections in List View (LVS) Pin
Michael Dunn22-Jun-06 10:45
sitebuilderMichael Dunn22-Jun-06 10:45 
GeneralRe: multiple selections in List View (LVS) Pin
aafcls23-Jun-06 4:02
aafcls23-Jun-06 4:02 
GeneralRe: multiple selections in List View (LVS) Pin
Michael Dunn23-Jun-06 15:01
sitebuilderMichael Dunn23-Jun-06 15:01 
QuestionTypedef Pin
Jay0322-Jun-06 7:59
Jay0322-Jun-06 7:59 
AnswerRe: Typedef Pin
Michael Dunn22-Jun-06 8:29
sitebuilderMichael Dunn22-Jun-06 8:29 
GeneralRe: Typedef Pin
Jay0322-Jun-06 8:36
Jay0322-Jun-06 8:36 
GeneralRe: Typedef Pin
Zac Howland22-Jun-06 9:33
Zac Howland22-Jun-06 9:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.