I'm hoping someone has seen this before ...
I have a header file that looks something like this
typedef struct ATYPE
{
int one;
int two;
char first;
}atype;
typedef struct BTYPE
{
BYTE FIRST;
BYTE SECOND;
atype aData[10];
}btype;
the some functions for the DLL I am linking too...
in my code I add a member varable like
public:
btype *array;
when I stop execution just after that statement I see the
Name Value
&array 0x0012f9e4 "III xA"
but I dont see
array 0x001245ef {...}
|- FIRST 0
SECOND 0
the demo app that I have runs correctly however when I try to recreate the code I get an access violation when trying to pass &array to a function...
it seems I am missing some kind of directive or something but thus far have not been able to track it down...
PLEASE if anyone has seen anything like this before let me know ...
Thank you!
14 3157 Banfa 9,065
Expert Mod 8TB
It sounds like you are using pointers without initialising them by allocating memory from the heap for the data they point to.
It sounds like you are using pointers without initialising them by allocating memory from the heap for the data they point to.
Thats exactly what it sounds like, however even when I change the statement to read
typeb array = new typeb; I still get the same access violation error in MFC42.DLL
Banfa 9,065
Expert Mod 8TB
Run it in the debugger and when it crashes look at the call stack and trace up the call stack to see if any of the functions are being called with invalid parameters. Then determin why the parameters are not valid.
Thank You! i'm getting closer to understanding whats going on here..
I have a header file with the typedef struct statements and the extern statements that point to functions in a win32dll
when I create a MFC Win dialog app with VC++ 6.0 and place my header file as an include in the Dlg.h file and create a pointer to one of my struct types it works correctly ...
however ... when I create a class and include that same header file ...
and create a pointer to the same struct it becomes type char* instead of my typeb*
ex: -
//Header File external.h
-
-
typedef struct TYPEA
-
{
-
int A
-
int B
-
char C
-
}typea;
-
-
typedef struct TYPEB
-
{
-
BYTE var2
-
BYTE var1
-
typea temp[10]
-
}typeb;
-
-
#ifdef __cplusplus
-
extern "C"
-
... etc...
-
-
// Class header file
-
-
#include "external.h"
-
-
/////////////////////////////////////////////////////////////////////////////
-
// myMicro window
-
-
class myMicro : public CWnd
-
{
-
// Construction
-
public:
-
myMicro();
-
-
-
// Attributes
-
public:
-
typeb *tpiData;
-
... this is the problem ...
*tpiData becomes char* and not a typeb* ...
but only if I create a class from it ... it seesm like the typeb is out of scope but im not getting any undefined type errors during compile ...I just get a access violation when I try to pass the char* to a function that expects the typeb*...
im at a loss here.. i need this to be an external class .. but it seems the only way i can get it work work is in a Dlg class...
Banfa 9,065
Expert Mod 8TB
I have a header file with the typedef struct statements and the extern statements that point to functions in a win32dll
If possible you should not do this, you should just include the header file the function are defined in.
*tpiData becomes char* and not a typeb* ...
I sorry but this really doesn't make sense to me (BTW did you mean tpiData rather than *tpiData), you declare tpiData as typeb *, then that is it's type. It does not become another type unless your code chooses to treat it that way (by casting it for example).
Can you post the code you use to allocate data for this pointer, the section of your code where the crash is happening?
BTW when posting code please use code tags, read "How to ask a question" from our forum FAQ.
If possible you should not do this, you should just include the header file the function are defined in.
I sorry but this really doesn't make sense to me (BTW did you mean tpiData rather than *tpiData), you declare tpiData as typeb *, then that is it's type. It does not become another type unless your code chooses to treat it that way (by casting it for example).
Can you post the code you use to allocate data for this pointer, the section of your code where the crash is happening?
BTW when posting code please use code tags, read "How to ask a question" from our forum FAQ.
I meant *tpiData yes...
here is the exact code of the header file that defines the external Win32dll -
// smw_oem.h
-
#ifndef _SMW_OEM_H
-
#define _SMW_OEM_H
-
-
#if defined (SMW_EXPORT_DLL)
-
#define SMWAPI __declspec( dllexport )
-
#else
-
#define SMWAPI __declspec( dllimport )
-
#endif
-
-
typedef struct ALARMREC
-
{
-
int Flag; //Read/Write flag (1= not yet read; 0= read)
-
int AlarmType; //0= Intrepid Cable; 1= Auxiliary Input
-
//11= PM tamper; 12= LU tamper; 13= RM tamper;
-
int AlarmUnitNum; //PM number; Auxiliary number;
-
int AlarmUnitWing; //When AlarmType = 1,
-
//1: PM Auxiliary Input
-
//2: LU Auxiliary Input
-
//3: RM Auxiliary Input
-
int AlarmLocation; //When Alarm Type = 0, Subcell Number for Intrepid Cable Alarm;
-
//When Alarm Type = 1, 2 = Sensor Alarm, 0 = Tamper 1, 1 = Tamper 2
-
int AlarmDelayFlag; //0= Real Time; 1= Delayed;
-
char AlarmTime[20]; //Time Stamp for the alarm
-
}alarmRec;
-
-
typedef struct SMI_IO
-
{
-
BYTE ErrorCode;
-
BYTE DisplaySegmentStatus[50]; //Access/Secure Status for Display Segments 1-50
-
BYTE AuxiliarySensorStatus[60][3]; //A/S (Aux.1-Aux.60;Index2 is 0:TP1; 1:TP2; 2:Sensor)
-
BYTE PMTamperStatus[8]; //Tamper Access/Secure Status (PM1-PM8 available)
-
BYTE LUTamperStatus[9]; //Tamper Access/Secure Status (LU1-LU9 available)
-
BYTE RMTamperStatus[20]; //Tamper Access/Secure Status (RM1-RM20 available)
-
BYTE DisplaySegmentAlarmState[50]; //In Alarm or Normal (Seg#1-Seg#50 available)
-
BYTE AuxiliaryAlarmState[60][3];//Alarm(Aux.1-Aux.60;Index2 is 0:TP1; 1:TP2;2:Sensor)
-
BYTE PMTamperAlarmState[8]; //Tamper In Alarm or Normal (PM1-PM8 available)
-
BYTE LUTamperAlarmState[9]; //Tamper In Alarm or Normal (LU1-LU9 available)
-
BYTE RMTamperAlarmState[20]; //Tamper In Alarm or Normal (RM1-RM20 available)
-
BYTE CableAFaultState[8]; //Cable Fault or Normal (PM1-PM8 available)
-
BYTE CableBFaultState[8]; //Cable Fault or Normal (PM1-PM8 available)
-
BYTE PMComFailState[8]; //Communication Fail or Normal (PM1-PM8 available)
-
BYTE RMComFailState[20]; //Communication Fail or Normal (RM1-RM20 available)
-
alarmRec AlarmData[10];
-
} SmiIo;
-
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
int gObjID;
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI SecureDispSeg(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI AccessDispSeg(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI SecurePM(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI AccessPM(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI SecureLU(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI AccessLU(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI SecureRM(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI AccessRM(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI SecureAuxiliaryTP1(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI AccessAuxiliaryTP1(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI SecureAuxiliaryTP2(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI AccessAuxiliaryTP2(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI SecureAuxiliarySensor(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI AccessAuxiliarySensor(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI TurnOnRelaysOnOneZone(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI TurnOffRelaysOnOneZone(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI TurnOnARelayControl(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
void SMWAPI TurnOffARelayControl(CString portName,int number);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
int SMWAPI SMIAPI_Exit(CString portName);
-
#ifdef __cplusplus
-
extern "C"
-
#endif
-
int SMWAPI SMIAPI_Init(CString portName,LPCSTR mapName,int pcNum,SmiIo **array);
-
#endif
-
This is the header file to my class -
#if !defined(AFX_SWMICRO_H__DA43CD12_A309_49A9_8921_75B0D5C51FB9__INCLUDED_)
-
#define AFX_SWMICRO_H__DA43CD12_A309_49A9_8921_75B0D5C51FB9__INCLUDED_
-
-
#if _MSC_VER > 1000
-
#pragma once
-
#endif // _MSC_VER > 1000
-
// swMicro.h : header file
-
//
-
-
#include "smw_oem.h"
-
-
/////////////////////////////////////////////////////////////////////////////
-
// swMicro window
-
-
class swMicro : public CWnd, public SMI_IO
-
{
-
// Construction
-
public:
-
swMicro();
-
-
-
// Attributes
-
public:
-
SmiIo *tpiData;
-
-
-
// Operations
-
public:
-
bool Connect();
-
bool Disconnect();
-
-
// Overrides
-
// ClassWizard generated virtual function overrides
-
//{{AFX_VIRTUAL(swMicro)
-
//}}AFX_VIRTUAL
-
-
// Implementation
-
public:
-
virtual ~swMicro();
-
-
// Generated message map functions
-
protected:
-
//{{AFX_MSG(swMicro)
-
afx_msg void OnTimer(UINT nIDEvent);
-
//}}AFX_MSG
-
DECLARE_MESSAGE_MAP()
-
};
-
-
/////////////////////////////////////////////////////////////////////////////
-
-
//{{AFX_INSERT_LOCATION}}
-
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-
#endif // !defined(AFX_SWMICRO_H__DA43CD12_A309_49A9_8921_75B0D5C51FB9__INCLUDED_)
-
this is the source file to the class -
// swMicro.cpp : implementation file
-
//
-
-
#include "stdafx.h"
-
#include "testClass.h"
-
#include "swMicro.h"
-
-
#ifdef _DEBUG
-
#define new DEBUG_NEW
-
#undef THIS_FILE
-
static char THIS_FILE[] = __FILE__;
-
#endif
-
-
/////////////////////////////////////////////////////////////////////////////
-
// swMicro
-
-
swMicro::swMicro()
-
{
-
//Constructor
-
tpiData = NULL;
-
}
-
-
swMicro::~swMicro()
-
{
-
}
-
-
-
BEGIN_MESSAGE_MAP(swMicro, CWnd)
-
//{{AFX_MSG_MAP(swMicro)
-
ON_WM_TIMER()
-
//}}AFX_MSG_MAP
-
END_MESSAGE_MAP()
-
-
-
/////////////////////////////////////////////////////////////////////////////
-
// swMicro message handlers
-
-
void swMicro::OnTimer(UINT nIDEvent)
-
{
-
// TODO: Add your message handler code here and/or call default
-
-
CWnd::OnTimer(nIDEvent);
-
}
-
-
/////////////////////////////////////////////////////////////////////////////
-
// swmicro functions
-
-
bool swMicro::Connect()
-
{
-
int ret = SMIAPI_Init("COM3","C:\\MapFiles\\SWMW.smp",1,&tpiData);
-
return(0);
-
}
-
-
bool swMicro::Disconnect()
-
{
-
//TODO:
-
return(0);
-
}
-
when SmiIo *tpiData is decalred it should be type SmiIo however when I use the debugger and break at the method swMicro::Connect &tpiData holds the address of a char* .. that is waht is causing the error when I call SMIAPI_Init
Banfa 9,065
Expert Mod 8TB - class swMicro : public CWnd, public SMI_IO
Do you really want to subclass from SMI_IO???
Any back to the problem,
when SmiIo *tpiData is decalred it should be type SmiIo however when I use the debugger and break at the method swMicro::Connect &tpiData holds the address of a char* .. that is waht is causing the error when I call SMIAPI_Init
What makes you think it is the address of a char *? MSVC 6.0 does not give the types of variables watched.
In a similar situation I see &tpiData as an address, this is correct because it is a pointer, when I expand the expression I see another address, this is ok as well because by expanding a dereference the expression so display *&tpiData or tpiData which is a pointer. When I expand that expression I see the items in the SmiIo structure, all invalid because as yet no data has been allocated for them. See attached image.
the Subclass was just me trying to work around the issue
tpiData needs to be type SimIo or I cannot pass it to the function ... the compiler obviously sees it as the correct type because it compiles ... and if I try a different type .. like say.. .int .. it will not compile ...
I'm not sure how to add a screenshot here.. but suffice it to say.. when i break at the call to the function .. right click on the &tpiData variable and choose Properties .. the type is char*
Banfa 9,065
Expert Mod 8TB
I'm not sure how to add a screenshot here..
It isn't easy :D
but suffice it to say.. when i break at the call to the function .. right click on the &tpiData variable and choose Properties .. the type is char*
Very very strange just tried this and I get SMI_IO **,
thinking...
Banfa 9,065
Expert Mod 8TB
I assume you have no global variables called tpiData?
<clutching at straws>
Try changing - int ret = SMIAPI_Init("COM3","C:\\MapFiles\\SWMW.smp",1,&tpiData);
to - int ret = SMIAPI_Init("COM3","C:\\MapFiles\\SWMW.smp",1,&this->tpiData);
</clutching at straws>
dosent make any difference ...
something i've noticed is that &tpiData is always type char* but when I break at the function call ... I see two variables in the window
i see tpiData .. as type SmiIo with all the members of the struct and I see &tpiData as type char* ...reguardless .. when I let the app make the call I get an Access Violation in MFC42.DLL...
Banfa 9,065
Expert Mod 8TB
Where is SMIAPI_Init defined because I can find no reference to it anywhere.
I think I got it ...
For some odd reason .. if I put the .lib file in the debug/release folder instead of the root project folder .. the call works correctly...
Thank you for all your help!!!
Banfa 9,065
Expert Mod 8TB
No problem, that probably means you have an old .lib floating around on your system somewhere that was getting picked up.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: yanwan |
last post by:
Hello
I met some problems in linking a project, and hope someone can give me some
advice.
-----------Configuration: lighting - Win32 Release--------------------
Linking...
LINK : warning...
|
by: Tatu Portin |
last post by:
Have this kind of struct:
typedef struct {
char **user_comments;
/* ... */
} vorbis_comment;
/* prototype */
char * read_vorbis_string
( FILE *sc);
|
by: Vinayak Raghuvamshi |
last post by:
I have a simple, non-managed structure. When I create an array of this
struct, only the first item in the array gets created, the others are
not. Here is my sample code.
This works when I build...
|
by: prashanth |
last post by:
Hi All,
I have few link errors that i am not able to get rif off in a VC++ project
(plugin for filemaker) where i am trying to port the code written for a mac
to windows.
I am creating a...
|
by: Greg |
last post by:
Except for legacy or non-.NET applications, is there any reason to use VC++
anymore? It seems that for .NET applications, there would be no reason to
choose C++ over C# since C# is faster to...
|
by: danip |
last post by:
Hi,
Is it possible to add a VC++ 6 library ot a VC++ 8 application ? if yes
how ? is it possible to link a DLL ? how ?
-- Dani
|
by: Philip Lowman |
last post by:
I am in the process of trying to migrate a couple of build solutions to
Visual Studio Express 2005 from VS 2003 Professional and I am running
into a weird C/C++ runtime library linking issue when...
|
by: dorkrawk |
last post by:
I am having an issue with some VC++ I am writing. I have a struct and
I'm trying to call a function from it from a function in another
object.
here is the struct....
struct JNI_Interface
{...
|
by: dasilva109 |
last post by:
Hi guys
I am new to C++ and need urgent help with this part of my code for a
uni coursework I have to submit by Thursday
//ClientData.h
#ifndef CLIENTDATA_H
#define CLIENTDATA_H
#include...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
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...
|
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...
| |