473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointer woes

Ant
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?

Code Follows:
#include "rootclass. h"

int _tmain(int argc, _TCHAR* argv[])
{
CRootClass *testclass;
testclass = new CRootClass;
testclass->TestFunction() ;

delete testclass;
return 0;
}
class CStore
{
public:
CStore(void);
~CStore(void);
friend class CRootClass;
typedef void(CRootClass ::*FunctionPtr) (void);
void PassPtr(Functio nPtr FPtr);
};

#include ".\store.h"

CStore::CStore( void)
{
}

CStore::~CStore (void)
{
}

void CStore::PassPtr (FunctionPtr FPtr)
{
//something happens with ptr
}

#include ".\store.h"
class CRootClass
{
public:
CRootClass(void );
~CRootClass(voi d);

CStore *m_Store;
void TestFunction(vo id);
};
#include ".\rootclas s.h"

CRootClass::CRo otClass(void)
{
m_Store = new CStore();
m_Store->PassPtr(&CRoot Class::TestFunc tion );
}
CRootClass::~CR ootClass(void)
{
delete m_Store;
}
void CRootClass::Tes tFunction(void)
{
//some code
}
Feb 26 '06 #1
10 5621
On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kk******@hotma il.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?

Code Follows:


[snip]

Your code compiles and runs fine, although it doesn't do anything. You
need to show us the code that produces the error.

(BTW, please refrain from posting code which uses non-standard macros
and extensions such as _tmain and TCHAR).

--
Bob Hairgrove
No**********@Ho me.com
Feb 26 '06 #2
Ant

"Bob Hairgrove" <in*****@bigfoo t.com> wrote in message
news:ei******** *************** *********@4ax.c om...
On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kk******@hotma il.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across
a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?

Code Follows:


[snip]

Your code compiles and runs fine, although it doesn't do anything. You
need to show us the code that produces the error.

(BTW, please refrain from posting code which uses non-standard macros
and extensions such as _tmain and TCHAR).

--
Bob Hairgrove
No**********@Ho me.com


Sorry about the TCHAR business, didnt notice that .

Interesting you say it runs fine, this is the code my compiler stops on. The
debug version I compile has some run time checks. It would appear that the
when my root class passes a pointer it somehow corrupts the stack pointer,
or something along those lines.

Using Visual Studio 2003 it produces this error

"Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention.

The program '[3768] friendtest.exe: Native' has exited with code -2147483645
(0x80000003)." (One or more arguments are invalid )
I am not sure why this happenes, all the calling conventions are the same
Feb 26 '06 #3
On Sun, 26 Feb 2006 17:41:56 GMT, "Ant" <An********@hot mail.com>
wrote:
Interesting you say it runs fine, this is the code my compiler stops on. The
debug version I compile has some run time checks. It would appear that the
when my root class passes a pointer it somehow corrupts the stack pointer,
or something along those lines.

Using Visual Studio 2003 it produces this error

"Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention.

The program '[3768] friendtest.exe: Native' has exited with code -2147483645
(0x80000003) ." (One or more arguments are invalid )
I am not sure why this happenes, all the calling conventions are the same


Here is the code I compiled and ran (all in one file instead of
different headers). It is essentially equivalent to the code you
posted. However, I did remove the "(void)" bits since that just isn't
C++, as well as changed _tmain to main:

// test_store.cpp
class CStore
{
public:
CStore();
~CStore();
friend class CRootClass;
typedef void(CRootClass ::*FunctionPtr) ();
void PassPtr(Functio nPtr FPtr);
};

CStore::CStore( )
{
}

CStore::~CStore ()
{
}

void CStore::PassPtr (FunctionPtr FPtr)
{
//something happens with ptr
}
class CRootClass
{
public:
CRootClass();
~CRootClass();

CStore *m_Store;
void TestFunction();
};
CRootClass::CRo otClass()
{
m_Store = new CStore();
m_Store->PassPtr(&CRoot Class::TestFunc tion );
}

CRootClass::~CR ootClass()
{
delete m_Store;
}

void CRootClass::Tes tFunction()
{
//some code
}

int main()
{
CRootClass *testclass;
testclass = new CRootClass;
testclass->TestFunction() ;

delete testclass;
return 0;
}

--
Bob Hairgrove
No**********@Ho me.com
Feb 26 '06 #4
> //something happens with ptr
//some code


are not that parts wrong :S
Feb 26 '06 #5
On Sun, 26 Feb 2006 18:58:57 +0100, "Frank Schmidt" <fs@example.com >
wrote:
//something happens with ptr

//some code


are not that parts wrong :S


Obviously. :)

--
Bob Hairgrove
No**********@Ho me.com
Feb 26 '06 #6
In article <ux************ *******@fe1.new s.blueyonder.co .uk>,
"Ant" <kk******@hotma il.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?


The code you posted is fine, your problem lies elsewhere. Somewhere in
your program you are writing to invalid memory or writing past the end
of an array, this is destroying the runtime environment in unpredictable
ways.

You need to find out where the error really is. Good luck.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 26 '06 #7
Ant
thanks for the replies.

I can appriciate that it that it would appear the error lies elsewhere, I
thought so too. The code posted is the entire code , the commens are not
snips to make it easier to post, its the entire program. I suspect its
something to do with a Microsoft compiler flag I need to set/unset

To demonstrate that this is the code that fails and it does not lie
elsewhere in some unsibmited code I can like you to my source files. Sorry
but they are in MS format, its the only compiler I have

http://www.teamkk.com/temp/friendtest.zip
"Daniel T." <po********@ear thlink.net> wrote in message
news:po******** *************** *******@news.ea st.earthlink.ne t...
In article <ux************ *******@fe1.new s.blueyonder.co .uk>,
"Ant" <kk******@hotma il.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me
the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved
across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?


The code you posted is fine, your problem lies elsewhere. Somewhere in
your program you are writing to invalid memory or writing past the end
of an array, this is destroying the runtime environment in unpredictable
ways.

You need to find out where the error really is. Good luck.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.

Feb 27 '06 #8

"Ant" <An********@hot mail.com> schrieb im Newsbeitrag
news:oD******** **********@text .news.blueyonde r.co.uk...
thanks for the replies.

I can appriciate that it that it would appear the error lies elsewhere, I
thought so too. The code posted is the entire code , the commens are not
snips to make it easier to post, its the entire program. I suspect its
something to do with a Microsoft compiler flag I need to set/unset

To demonstrate that this is the code that fails and it does not lie
elsewhere in some unsibmited code I can like you to my source files. Sorry
but they are in MS format, its the only compiler I have

http://www.teamkk.com/temp/friendtest.zip


With all the single files, a #include "rootclass. h" in store.cpp and some
#pragma once in the headers seems to solve the problem. At least on vs2005.

I'm tiered to find the explanation somewhere in "type not known enought for
a stupid compiler"
Feb 27 '06 #9
In article <oD************ ******@text.new s.blueyonder.co .uk>,
"Ant" <An********@hot mail.com> wrote:
thanks for the replies.

I can appriciate that it that it would appear the error lies elsewhere, I
thought so too. The code posted is the entire code , the commens are not
snips to make it easier to post, its the entire program. I suspect its
something to do with a Microsoft compiler flag I need to set/unset

To demonstrate that this is the code that fails and it does not lie
elsewhere in some unsibmited code I can like you to my source files. Sorry
but they are in MS format, its the only compiler I have

http://www.teamkk.com/temp/friendtest.zip


The code above gives me an idea. Where do you make these CRootClass
objects? If you try to make one *inside* CStore, that would be a real
problem.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1719
by: Mark | last post by:
O, woe is me, to have seen what I have seen, see what I see! (That's Shakespeare for those who were wondering what I'm on about) I am "having fun" with cookies. And I wonder if I have missed something obvious.
0
1527
by: Cedric | last post by:
This is a 3 weeks old problem, but having found a solution (and having looked for one here, finding only this message), I'm replying now. From: Jive (someone@microsoft.com) Subject: Upgrade woes: Numeric, gnuplot, and Python 2.4 Date: 2004-12-11 18:45:10 PST > Here's my sitch: > > I use gnuplot.py at work, platform Win32. > I want to upgrade to Python 2.4.
3
3454
by: Angel Cat | last post by:
Trying to get my jobs to send mail when job fails. Should be easy but it's giving me headache Had a whole slew of issues. Outlook is installed with a n outlook mail profile set up that can send mail in outlook. I can create a SendMail DTS and execute it to send mail Email works in these scenarios 1. I create a DTS package in SQL Server with just SendMail with the same Profile "ABC" and click Execute and it sends
2
1832
by: Andrew Thompson | last post by:
- NN 4.78 rendering woes, links at far left - I am trying to rework an old site, make it valid html and css, improving the x-browser and 'older browser' compatibility. My efforts so far, have been abysmal. See, for example, this screen shot of the very simple home page, it is not even 10% finished, but I have already run into problems. http://www.physci.org/test/xbrowser/nn478home01.png
0
2104
by: Arun Bhalla | last post by:
I'm having some inconsistency problems with my deployment project ("Setup") and its custom actions ("Installer"). I'm using Visual Studio .NET 2003 (.NET 1.1, no service pack) on Windows XPSP1. My main project is a band object (Explorer Bar) in an assembly (.DLL) that needs to be registered on installation and unregisted on uninstallation. In addition, during installation, Setup creates registry subkeys, sets registry values, installs...
15
3491
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here is a small program I wrote to check if I could get the address of the function from the member-function-pointer, so that I could pass it to the function as a normal function-pointer.
48
2171
by: yezi | last post by:
Hi, all: I want to record some memory pointer returned from malloc, is possible the code like below? int memo_index; int i,j; char *tmp; for (i=0;i<10;i++){
9
1550
by: Mark Rae | last post by:
Hi, This time, I'm looking for a regular expression which says "the string must contain exactly seven or exactly eight digits" e.g. 123456 fails 1234567 passes 12345678 passes 123456789 fails
1
1896
by: hdogg | last post by:
Scope Woes - IF statement nested in WHILE statement -PHP I have an array $actuals_sum. <?php while(conditions) { if($i == '24) {
0
8995
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9561
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.