473,473 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error: aggregate value used where an integer was expected

Help with this error ! Please !
The code below is simplified, because I'm trying to solve this error.

....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()
{
//empty
}

Sep 18 '07 #1
14 13474
Neviton wrote:
Help with this error ! Please !
The code below is simplified, because I'm trying to solve this error.

...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
MyFunction is member function, not function

void MyClass::*pmf = &MyClass::MyFunction;

Moreover, casting a function pointer to other type is meaningless.

}

void MyClass::MyFunction()
{
//empty
}

--
Thanks
Barry
Sep 18 '07 #2
Barry wrote:
Neviton wrote:
>Help with this error ! Please !
The code below is simplified, because I'm trying to solve this error.

...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

MyFunction is member function, not function

void MyClass::*pmf = &MyClass::MyFunction;
Sorry, what a impulsive man I am! deal too much with pointer to member
recently :-)

void (MyClass::*pmf)() = &MyClass::MyFunction;
>
Moreover, casting a function pointer to other type is meaningless.

>}

void MyClass::MyFunction()
{
//empty
}


--
Thanks
Barry
Sep 18 '07 #3
Ok impulsive man. :)
Thank you Barry.
I will try this and give you a feedback.
Sep 18 '07 #4
How can I get the address of the function and save in a long variable.

My deal is use this WIN32 function that must receive the address of
function.

I know, I know
This is not a WIN32 Group but
I think my problem is with C++ instead WIN32.

I am wasting time for a few days and I can´t find a solution for my
problem.

If you can help me I will really appreciate

Thanks again

Sep 18 '07 #5
When I try this in the main application class everything works fine.
The "aggregate value used where an integer was expected" error just
happen when I put the code in a Class.

Sep 18 '07 #6
Neviton wrote:
How can I get the address of the function and save in a long variable.

My deal is use this WIN32 function that must receive the address of
function.

I know, I know
This is not a WIN32 Group but
I think my problem is with C++ instead WIN32.

I am wasting time for a few days and I can´t find a solution for my
problem.

If you can help me I will really appreciate
If you have various kind of function which have different parameter
list, then you have to borrow Boost.Function, as my experience, I use
boost::function0<voidas wrapper, then bind any type of functor, free
function and member function into this wrapper.

If the parameter list is fixed, then you can write your own wrapper,
refer to 'mem_fun', 'bind2nd' ... in STL.
--
Thanks
Barry
Sep 18 '07 #7
Neviton wrote:
How can I get the address of the function and save in a long variable.
If that's a question, the answer is to use 'reinterpret_cast', but do
not rely on the pointer to fit into a 'long'. You may need to have
something different there, like 'uint64_t'.
My deal is use this WIN32 function that must receive the address of
function.
<shrug OK. Where does the 'long' come in?
I know, I know
This is not a WIN32 Group but
I think my problem is with C++ instead WIN32.
Maybe. See FAQ 5.8.
I am wasting time for a few days and I can´t find a solution for my
problem.
Neither can we unless we actually see some code.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #8
Neviton wrote:
When I try this in the main application class everything works fine.
The "aggregate value used where an integer was expected" error just
happen when I put the code in a Class.
Post your code to speak the error

--
Thanks
Barry
Sep 18 '07 #9
Neviton wrote:
How can I get the address of the function and save in a long variable.

My deal is use this WIN32 function that must receive the address of
function.
I don't even want to know why windows would want a function pointer as
a long (although having seen the Windows API I'm not even surprised
about anything anymore), but if if expects a pointer to a *function* and
you are giving a pointer to a *method* it won't work (at least if that
windows function tries to call your function through the pointer). A
method is not a regular function.
Sep 18 '07 #10
Here is the code:

I'm getting this error
.... Button.cpp In member function `void Button::Create(HWND__*,
char*)':
.... Button.cpp aggregate value used where an integer was expected

/* Button.cpp ****************/
#include "Button.h"
void Button::Create(HWND hWindow, char * text)
{
Button::hWindow = hWindow;
handle = CreateWindow("Button", text, WS_CHILD | WS_VISIBLE, 10,
10, 100, 20, hWindow, (HMENU)0, NULL, NULL);
mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC,
(LONG) OwnerDrawButtonProc); // THE ERROR OCCUR HERE

}

HWND Button::Handle()
{
return handle;
}

LRESULT CALLBACK Button::OwnerDrawButtonProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
return TRUE;
}
return CallWindowProc(mainWindowProc, hWnd, uMsg, wParam, lParam);
}
/* Button.h ******************/
#include <windows.h>
class Button
{
public:
void Create(HWND hWindow, char * text);
HWND Handle();
private:
LRESULT CALLBACK OwnerDrawButtonProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
HWND hWindow;
HWND handle;
WNDPROC mainWindowProc;
};

Sep 18 '07 #11
Neviton wrote:
Here is the code:

I'm getting this error
... Button.cpp In member function `void Button::Create(HWND__*,
char*)':
... Button.cpp aggregate value used where an integer was expected

/* Button.cpp ****************/
#include "Button.h"
void Button::Create(HWND hWindow, char * text)
{
Button::hWindow = hWindow;
handle = CreateWindow("Button", text, WS_CHILD | WS_VISIBLE, 10,
10, 100, 20, hWindow, (HMENU)0, NULL, NULL);
mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC,
(LONG) OwnerDrawButtonProc); // THE ERROR OCCUR HERE
Make your member function("OwnerDrawButtonProc") static
>
}


--
Thanks
Barry
Sep 18 '07 #12
Neviton wrote:
Here is the code:

I'm getting this error
... Button.cpp In member function `void Button::Create(HWND__*,
char*)':
... Button.cpp aggregate value used where an integer was expected

/* Button.cpp ****************/
#include "Button.h"
void Button::Create(HWND hWindow, char * text)
{
Button::hWindow = hWindow;
handle = CreateWindow("Button", text, WS_CHILD | WS_VISIBLE, 10,
10, 100, 20, hWindow, (HMENU)0, NULL, NULL);
mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC,
(LONG) OwnerDrawButtonProc); // THE ERROR OCCUR HERE
Does it work if you simply pass 0?
>
}
Well, since we don't know what 'SegWindowLong' does, and what it
expects as its third argument, it's hard to tell what the solution
would be. However, it might help you to define 'OwnerDrawButtonProc'
as non-member, perhaps. Are you sure it's a static function in
your 'Button' class? If it isn't, you probably can't declare it
"CALLBACK" because callbacks usually don't have the instance of
the class to be called for. Search the FAQ for "callback".

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #13
On Sep 18, 5:30 pm, Neviton <nevito...@gmail.comwrote:
How can I get the address of the function and save in a long variable.
If it's a non-static member function, you can't.
My deal is use this WIN32 function that must receive the address of
function.
What is the signature of the target function? I'm willing to
bet that it's something like:

void f( void (*)( void* ), void* ) ;

or even (more likely):

extern "C" void f( void (*)( void* ), void* ) ;

In neither case is a non-static member function acceptable, and
in the second case, even a static member function is not
acceptable.

If the pointer to the function is in fact passed using some data
type, e.g. a uint32_t, then you are skating on thin ice. You
must know how the function will be called. (`extern "C++"' or
`extern "C"', according to the standard, but VC++ has some
additional options), and only convert the address of a function
which can be called in that matter. In this case, the compiler
cannot help with the verifications. (And of course, a member
function is called in a far different manner than a non-member
function. The two are not compatible in any way.)
I know, I know This is not a WIN32 Group but I think my
problem is with C++ instead WIN32.
A bit of both. There are certainly C++ problems involved (and
Posix has similar problems).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 19 '07 #14
On Sep 18, 5:51 pm, Juha Nieminen <nos...@thanks.invalidwrote:
Neviton wrote:
How can I get the address of the function and save in a long variable.
My deal is use this WIN32 function that must receive the address of
function.
I don't even want to know why windows would want a function pointer as
a long (although having seen the Windows API I'm not even surprised
about anything anymore), but if if expects a pointer to a *function* and
you are giving a pointer to a *method* it won't work (at least if that
windows function tries to call your function through the pointer). A
method is not a regular function.
For various reasons, OS's often have functions which violate
type safety. Regretfully, Windows isn't alone in this. (The
worst I've seen is dlsym, under Unix.)

And the problem isn't just (non-static) member vs. regular
function. Windows (or at least VC++) supports several different
call conventions; unless the function has the expected call
conventions, there's going to be problems at runtime.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 19 '07 #15

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

Similar topics

1
by: Job Lot | last post by:
Is it possible to use Aggregate functions with GROUP BY Clauses on DataTable. I have a DataTable with following values: Date Amount Int Balance 1/1/2004 5000.00 50.00 5050.00...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Tim Pascoe | last post by:
I'm trying to implement a sorting routine for a string array. The sort routine is from http://ourworld.compuserve.com/homepages/attac-cg/acgsoft.htm (a great selection of routines in the 'Sequence...
6
by: Larry Menard | last post by:
Folks, I know that DB2 does not (yet?) support this, but I wonder if anyone can suggest a work-around. I've seen article...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
4
by: SAL | last post by:
I'm sorry if this has been answered before but I didn't see it in a quick scan of the list. The following code is causing an error when the field is null: Error text: Conversion from type...
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
2
by: ghostrider | last post by:
I've been trying to clear these error messages that I keep getting, was wondering if someone could help me out here. 1. Value of type '1-dimensional array of String' cannot be converted to...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
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
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
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...
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
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.