Jump to content
  • Advertisement
Sign in to follow this  
SteveRodrigue

Creating an object in a dll & sending it to an exe file

This topic is 4233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im currently creating an object that inherit a base class named BaseObject, in my DLL, and Im sending it to my application using a static function declared in my application. The problem is that the object looks corrupted when the exe receives it. Does anyone knows what could make this problem? Thanks, Steve [Edited by - SteveRodrigue on December 14, 2006 12:16:34 AM]

Share this post


Link to post
Share on other sites
Advertisement
Here is how my object looks like after I created it in my DLL: http://prookle.com/vbimghost.php?do=displayimg&imgid=127

Then, I pass this object using a static function.

When my application receives it, the object looks like that:
http://prookle.com/vbimghost.php?do=displayimg&imgid=126

As you can see, the data is not the same.

Here is what the BaseObject class looks like:



#ifndef _BaseObject
#define _BaseObject


#ifndef API_DLL
#ifdef CORE_EXPORTS
#define API_DLL //__declspec(dllimport)
#else
#define API_DLL __declspec(dllexport)
#endif
#endif



#include <vector>
#include <iostream>
using namespace std;

#include "APITypes.h"

class API_DLL BaseObject;

typedef void (BaseObject::*EnterExitFn)(uint32);
typedef void (BaseObject::*StateFn)(float);

struct State
{
EnterExitFn mEnterFn;
StateFn mStateFn;
EnterExitFn mExitFn;
uint32 muiStateId;
};

struct Test
{
uint32 uiId;
float fValue;
};


class API_DLL BaseObject
{
public:
BaseObject(uint32 _uiObjectId);

void SetStateFn(uint32 _uiStateId, StateFn _stateFn,
EnterExitFn _stateEnter = NULL,
EnterExitFn _stateExitFn = NULL,
bool _bStopSet = false);

void SetState(uint32 _uiState, bool _bStopSet = false);
void Update(float _fDelta);

uint32 GetObjectId();

//virtual:
virtual uint32 SendMessage(uint32 _uiMessageType, void* _messageData){return 0;};
private:
uint32 FindStateIndex(uint32 _uiStateId);
protected:
vector<State> mvuiStates;

uint32 muiObjectId;
uint32 muiCurrentState;
uint32 muiLastFrameState;

bool mbHasStates;
bool mbCallEnterFn;
bool mbCallExitFn;
};

#endif







Here is how I pass the object from the DLL to the application:



Mouse* pMouse = new Mouse(6);
APIGameObject::RegisterObject((BaseObject*) pMouse);



The mouse class inherit the BaseObject class. The RegisterObject function is a static function declared in the application.

When I break in the RegisterObject static function, the object in parameter looks like this: http://prookle.com/vbimghost.php?do=displayimg&imgid=126

But, when I create the mouse object, it looks like this: http://prookle.com/vbimghost.php?do=displayimg&imgid=127

Hope someone can help me out,
Steve

[Edited by - SteveRodrigue on December 14, 2006 8:02:46 AM]

Share this post


Link to post
Share on other sites
Hi,
I really need that problem to be fixed but I really don't know how to fix it... if anyone can help me out, I would be very happy!

Hope someone can help me out,
Steve

Share this post


Link to post
Share on other sites
Hi,
I really need that problem to be fixed but I really don't know how to fix it... if anyone can help me out, I would be very happy!

Hope someone can help me out,
Steve

Share this post


Link to post
Share on other sites
I will give this a bigger look over later however when I am working with DLLs to create objects I tend to do the following:

my_type* create_object (void* parameters)
{
// Cast parameters to the correct type:
my_data_struct = (my_data_struct*)parameters;
my_type* type = new my_type(my_data_struct);
return type;
}


This method is normally a global function in each dll, which is probably bad style but it seems to work.

The base application has a function which retrieves a base object

base_object* temp = create_object(&data_struct);


Which was normally typedef'd so I have multiple dlls each of which returns an instance of their class in the same way.

which can then cast this to the my_type if it understands that or can simply manipulate the base type itself.

If you want to pass a point to the main application then you could also do it the way you want:

void register_object (app* application)
{
my_type type = new my_type();
application->register (type);
}


My knowledge of C++ is limited but what does the


APIGameObject::RegisterObject


Line actually do? Surely this would not access an instance of the object but rather attempt to use that method in a similar way to std::cin does?

Share this post


Link to post
Share on other sites
Quote:
Original post by SteveRodrigue
Mouse* pMouse = new Mouse(6);
APIGameObject::RegisterObject((BaseObject*) pMouse);
That cast should be unnecessary. Get rid of it. Also note that the identifier _BaseObject in your header include is not legal for you to use. Identifiers beginning with an underscore followed by a captial letter are reserved for compiler and standard library implementers, at any scope (ditto for identifiers containing double underscores, other identifiers beginning with an underscore are reserved only at global scope).

Σnigma

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!