473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How can I access non-static variables from static funcition?

Is it possible ?

There is any work around?

Thanx

Sep 17 '07 #1
8 1940
Neviton wrote:
Is it possible ?

There is any work around?

Thanx
If you need to modify an instance, pass in an reference or pointer to
the object, if you just want to call the function, then create a temp
obj (const/non-const).
Last resort, there must be something wrong with your design, refactor.
--
Thanks
Barry
Sep 17 '07 #2
Thanks for the quickly response Barry.
Last resort, there must be something wrong with your design, refactor.
Yes probably. :) I'm starting.
Perhaps you can give me some tip.

I'm subclassing a Button control.
I create a class for this and I define my subclassing procedure as
static.
But I have a non-static HBITMAP variable that I want to use inner
subclassing static procedure.

thanks again
Sep 17 '07 #3
Neviton wrote:
Thanks for the quickly response Barry.
>Last resort, there must be something wrong with your design, refactor.
Yes probably. :) I'm starting.
Perhaps you can give me some tip.

I'm subclassing a Button control.
I create a class for this and I define my subclassing procedure as
static.
But I have a non-static HBITMAP variable that I want to use inner
subclassing static procedure.
In this case I would rather make the member function non-static,
if you can't make it non-static, then the former two ways can solve the
problem.

--
Thanks
Barry
Sep 17 '07 #4
On Sep 17, 8:47 am, Neviton <nevito...@gmail.comwrote:
Thanks for the quickly response Barry.
Last resort, there must be something wrong with your design, refactor.

Yes probably. :) I'm starting.
Perhaps you can give me some tip.

I'm subclassing a Button control.
I create a class for this and I define my subclassing procedure as
static.
But I have a non-static HBITMAP variable that I want to use inner
subclassing static procedure.
Presumably you are doing this because there is some
library code (the operating system, etc.) that looks
after the mundane parts of doing the button operations.
And that other code wants a static function so it can
be used as a callback. This is an evergreen question
that gets asked repeatedly. Read through the FAQ for
what to do about callbacks.

But basically: A static member function does not know
about specific instances of the class. You've got to
tell it somehow. It isn't really possible for me to
solve your problem without actually doing all the work.
You need to have some scheme for keeping track of which
button-class instance is being invoked. Some callback
systems allow the setting of a parameter that can be
a pointer. Some allow the storage of some kind of ID
number that your prog could keep track of buttons.
Or possibly there is some ID number the system keeps
track of automatically and you can use that. In window
systems there is usually a window ID or a frame number
or some such.

So, when you are setting up the button, you'd store
something in the system. When the callback happens,
it passes you some extra parameter. And you use that
extra parameter to sort out which button instance
you need to call. Your static function looks up this
stuff in a static table, then calls it. That table
is something you have to maintain as buttons are
created, destroyed, modified, etc.

If at all possible, it's way better to have the
callback system get a pointer to an instance. Then
if you can persuade it to call a member function
to do the job you can shorten this entire problem.
But that assumes you have the ability to modify
the system so that works. If you don't, then you
have to do something like the static table.
Socks

Sep 17 '07 #5
I tried to change my function to non-static but I get this error:

....Button.cpp aggregate value used where an integer was expected

this occur on this line when I try get the address of my subclass
procedure(OwnerDrawButtonProc):

mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC, (LONG)
OwnerDrawButtonProc);

Any help is welcome

And

Thanks for your reply Puppet_Sock

Sep 17 '07 #6
"Neviton" <ne*******@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
>
Any help is welcome
You are attempting to reinvent the wheel. Microsoft provides at least 3 C++
libraries that solve this problem. (ATL, WTL, MFC).

Sep 17 '07 #7
On Sep 17, 12:07 pm, Neviton <nevito...@gmail.comwrote:
I tried to change my function to non-static but I get this error:

...Button.cpp aggregate value used where an integer was expected

this occur on this line when I try get the address of my subclass
procedure(OwnerDrawButtonProc):

mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC, (LONG)
OwnerDrawButtonProc);

Any help is welcome
You have moved into the area of specifics of a libary for
doing window stuff. This is outside of what happens in this
news group as we are only interested in standard C++ language
stuff here. You need to go to a group that is specific to
your compiler and operating system.

It *looks* like Microsoft, but I'm not sure. If it is, you
need a news group with Microsoft or Visual C++ or DOS or
something like that in the name. Go to groups.google.com
and search around for groups that talk about your compiler
and operating system.

Basically, if I'm recalling those things correctly, that
function wants the address of a static function. It tells
the operating system to call that function whenever it
needs to draw the button. It can not be a class non-static
member function. It has to be static. Then you have to
re-read the post I posted before. Then go to that other
news group.
Socks

Sep 17 '07 #8
You have moved into the area of specifics of a libary for
doing window stuff. This is outside of what happens in this
news group as we are only interested in standard C++ language
stuff here. You need to go to a group that is specific to
your compiler and operating system.
Yes, I'm playing with WIN32 stuff but the error don't have anything to
do with this.
I create one class just to make sure that this error occur even
without WIN32 stuff.

Well
I first wanna to say thanks for all your patience
because what I know about C++ is so little.
And
Take a look on this code that rise the same error( no Win32 stuff
now :] ):
....MyClass.cpp In member function `void MyClass::Initialize()':
....MyClass.cpp aggregate value used where an integer was expected
....Makefile.win [Build Error] [MyClass.o] Error 1

The code:
/* MyClass.h *****************/
class MyClass
{
public:
void Initialize();
void MyFunction();
};

/* MyClass.cpp **************/
#include "MyClass.h"
void MyClass::Initialize()
{
long address = (long)MyFunction; //this line rises the error
}

void MyClass::MyFunction()
{
}

Sep 17 '07 #9

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

Similar topics

6
by: John | last post by:
Hi We have an access app (front-end+backend) running on the company network. I am trying to setup replication for laptop users who go into field and need the data synched between their laptops...
92
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why does IT hate MS Access so much. I have tried...
6
by: Woody Splawn | last post by:
It is real important to choose the right tool for a given problem and it is not clear to me just what the advantage of VS.net is over Access, for example, when writing a non-web applicaiton. I see...
57
by: TC | last post by:
I'd like to open a discussion about the state of the industry. For the past year, I've been unable to find competent Access developers available for hire. I'm worried about that. I think there's...
22
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need to be able to speak intelligently about when one...
17
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting...
0
ADezii
by: ADezii | last post by:
In Tip #12, we showed how to display a Progress Meter within Access by using the SysCmd() Function. By using this same Function, with different Action Arguments, we will now demonstrate how you can...
8
by: Sid | last post by:
I hope someone could help me with this. I am trying to setup a criteria to decide when to allow/not allow user to click on the check box. logically it looks simple but I am not able to...
5
ADezii
by: ADezii | last post by:
Periodically, the same or similar question appears in our Access Forum: How can I use Excel Functions within Access? For this reason, I decided to make this Subject TheScripts Tip of the Week. In...
5
by: DotNetDanny | last post by:
Hello Machine: Windows Vista Business, standalone machine (no domain). Installed an old classic ASP webapplication in IIS7, running under a new app.pool with 'NETWORK SERVICE' account (using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
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...
0
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...
0
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,...
0
isladogs
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...

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.