Sign in to follow this  

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

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
Here is how my object looks like after I created it in my DLL:

Then, I pass this object using a static function.

When my application receives it, the object looks like that:

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
#define API_DLL //__declspec(dllimport)
#define API_DLL __declspec(dllexport)

#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
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 uint32 SendMessage(uint32 _uiMessageType, void* _messageData){return 0;};
uint32 FindStateIndex(uint32 _uiStateId);
vector<State> mvuiStates;

uint32 muiObjectId;
uint32 muiCurrentState;
uint32 muiLastFrameState;

bool mbHasStates;
bool mbCallEnterFn;
bool mbCallExitFn;


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:

But, when I create the mouse object, it looks like this:

Hope someone can help me out,

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

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


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


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this