Thread

Problemes using AW SDK with visual c++ (Sdk)

Problemes using AW SDK with visual c++ // Sdk

1  |  

bensezoug

Jun 15, 2003, 12:22pm
have some problemes to use the AW SDK with visual c++

There's something wrong with "aw_event_set"

I set up the handler:
aw_event_set (AW_EVENT_CHAT, handle_chat);

the handle_chat function is in the same class

when I build the prog I have this error:

C:\Program Files\Microsoft Visual Studio\MyProjects\awbot\awbotDlg.cpp(190)
: error C2664: 'aw_event_set' : cannot convert parameter 2 from 'void
(void)' to 'void (__cdecl *)(void)'
None of the functions with this name in scope match the target type


Ther's no doubt the mistake is mine, I'm a beginner in coding.

If someone could help me...

strike rapier

Jun 15, 2003, 7:05pm
define your handle chat function as so:

void handle_chat(void);

BTW, using a DLG class as the main bot class is not a good idea... Try using
another class, call it CAwBot...

Class CAwBot
[View Quote]

bensezoug

Jun 15, 2003, 8:48pm
It doesn't work :-( even if I use another class for the bot, I get the same
error message.

"strike rapier" <strike at rapiercom.freeserve.co.uk> a écrit dans le message
de news: 3eecdf7d at server1.Activeworlds.com...
> define your handle chat function as so:
>
> void handle_chat(void);
>
> BTW, using a DLG class as the main bot class is not a good idea... Try
using
> another class, call it CAwBot...
>
> Class CAwBot
[View Quote]

strike rapier

Jun 16, 2003, 4:47am
You must define them right...

As you will know C++ bases everything on type defentions, even functions are
just masks of a variable, with those not returning a value being defined as
void. The aw_event_set function actually needs a pointer to the void to do
this, so *void.

Try this:

-------------------------------------------
AwBot.h
-------------------------------------------

#pragma once
// The event handler functions for avatars
void Event_Avatar_Add(void);
void Event_Avatar_Change(void);
void Event_Avatar_Delete(void);

class CAwBot
{
public:
CAwBot();
~CAwBot(void);
}

-------------------------------------------
AwBot.ccp
-------------------------------------------
#include "aw.h"
#include "AwBot.h"

CAwBot::CAwBot(void)
{
aw_event_set (AW_EVENT_AVATAR_ADD, Event_Avatar_Add);
aw_event_set (AW_EVENT_AVATAR_CHANGE, Event_Avatar_Change);
aw_event_set (AW_EVENT_AVATAR_DELETE, Event_Avatar_Delete);
}

/* End of File */

Notice, how the variables are of type void, hence the functions within them
return with void.

- Mark

agent1

Jun 16, 2003, 11:38am
I believe the problem is that the function you are trying to use is a class member. That doesn't work very well with the AW SDK, so what I sometimes do is add another function that is not a class member for the actual callback and use it to call your real callback function.

-Agent1

[View Quote]

ananas

Jun 16, 2003, 2:13pm
For me this scheme worked :

PROJECTNAME.CPP :
void EvCellObject(void)
{
....
}

this function (not method!) has been created with the editor,
not with the class browser. It is not part of any class.


SOMEWHEREINANYCLASS.CPP :
SetCallbackFunction ()
{
extern void EvCellObject (void);
aw_event_set (AW_EVENT_CELL_OBJECT, EvCellObject);
}


This combines both Strike Rapier's and Agent1's hint.

The complete project will not work as it is based on an old
AW.DLL but if you're interested, I can upload it somewhere
for experimenting. It is a very simple backup/restore bot.



bensezoug schrieb:
> have some problemes to use the AW SDK with visual c++
>
> There's something wrong with "aw_event_set"
>
> I set up the handler:
> aw_event_set (AW_EVENT_CHAT, handle_chat);
>
> the handle_chat function is in the same class
>
> when I build the prog I have this error:
>
> C:\Program Files\Microsoft Visual Studio\MyProjects\awbot\awbotDlg.cpp(190)
> : error C2664: 'aw_event_set' : cannot convert parameter 2 from 'void
> (void)' to 'void (__cdecl *)(void)'
> None of the functions with this name in scope match the target type
>
>
> Ther's no doubt the mistake is mine, I'm a beginner in coding.
>
> If someone could help me...
>
>

xelag

Jun 20, 2003, 9:53am
This is exactly as what I do in Delphi with Xelagot: I define a
procedure which is NOT a class member, install it with aw_event_set,
and in that procedure I call the bot's own class procedure.

Alex


On 16 Jun 2003 09:38:10 -0400, "agent1"
[View Quote] >I believe the problem is that the function you are trying to use is a class member.
>That doesn't work very well with the AW SDK, so what I sometimes do is add
> another function that is not a class member for the actual callback and use it
>to call your real callback function.
>
>-Agent1

bowen

Jun 20, 2003, 2:09pm
[View Quote] Would it be possible to remove the event set from within the class and
call it in main as:

aw_event_set( AW_EVENT_CHAT, foo.bar() ); ? Or would that not work either?

--
--Bowen--

milesteg

Jun 20, 2003, 2:41pm
Hi,
the problem is not from where the set function is called, it is how member
functions are handled in C++.
Even if your function signature looks like void bar(void), in fact its true
signature is void bar(this*);
C++ add 1 parameter in first position, this parameter is a pointer to the
object on which the function is called.
this is why a function for event or callback needs to be a 'raw' c function
or a static function of a class.

Regards,
Miles




"bowen" <Bowen at andras.net> a écrit dans le message de news:
3ef331bf$2 at server1.Activeworlds.com...
[View Quote]

ananas

Jun 21, 2003, 8:41am
I think, class members have different calling conventions.
I once tried to define a global pointer to a class function
and when I called it, it crashed the program.

Maybe class members are _fastcall or _pascal or so.


xelag schrieb:
> This is exactly as what I do in Delphi with Xelagot: I define a
> procedure which is NOT a class member, install it with aw_event_set,
> and in that procedure I call the bot's own class procedure.
>
> Alex

uzume

Jun 25, 2003, 4:07am
Yes, Miles is right. In fact, you can define your call back functions as
class functions but not as member functions. You can do this by declaring
the function "static". This makes it work like any other function that is
outside the class except for the name scoping. As Miles stated, this implies
you will get no implied "this" object passed in and it will be a true class
only function and not a member function that can act on an object so I
recommend you find the owner object of the event and deliver the message to
the right object. I am not sure this buys anyone anything but you *can*
define call backs in classes just not as member functions.

Enjoy,
Uzume

[View Quote]

bowen

Jun 25, 2003, 4:36am
[View Quote] Could anyone provide me with a code that shows it works and then one
that wouldn't work (preferably simple and looking similar).

--
--Bowen--

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn