I always get nervous when I see code like this in the .NET wrappers:
windowHandle.ToInt32() // in the CP wrapper
p.WindowId = reinterpret_cast<irr::s32>((void*)windowHandle); // packaged
WindowId should probably be declared as a void*. That way it will always be the correct size. It's used as an HWND, which is definitely a pointer type on Windows. I'm not sure what it is on other operating systems, but I'm sure they could handle a larger data type as well.
[solved]WindowId: shouldn't it be a pointer type?
-
- Posts: 19
- Joined: Wed Mar 21, 2007 6:22 pm
-
- Posts: 19
- Joined: Wed Mar 21, 2007 6:22 pm
What about the possiblity of using a template.
One way I have gotten around OS specific things is to create a lightweight template object and then typedef the whole thing. Other methods can then be added to the template to help with specific requirements of the irrlicht engine.
For example
Then your object uses OsSpecificWindow as it's object type.
Just a thought instead of using raw pointers![Smile :)](./images/smilies/icon_smile.gif)
One way I have gotten around OS specific things is to create a lightweight template object and then typedef the whole thing. Other methods can then be added to the template to help with specific requirements of the irrlicht engine.
For example
Code: Select all
template <typename T>
class MyOsGenericClass
{
public:
/// Constructor.
/// \param obj OS specific object
MyOsGenericClass(T obj);
/// Retrieves the object.
/// \return OS specific object
T GetOsGenericObj();
private:
/// Object
T m_obj;
};
#if defined _WIN32
/// Windows specific concept
typedef MyOsGenericClass<HWND> OsSpecificWindow;
#elif defined OTHER_OS
/// Whatever os specific concept goes here
typedef MyOsGenericClass<uint64_t> OsSpecificWindow;
#endif
Just a thought instead of using raw pointers
![Smile :)](./images/smilies/icon_smile.gif)
I was just throwing it out there. It would at least hide the pointer specific cast from the user. But if you all feel that it's a waste, I'll retract my comment ![Smile :)](./images/smilies/icon_smile.gif)
On a side note, one advantage of hiding pointers behind templates is you can move to more of a smart pointer paradigm (see boost::smart_ptr... think reference counting auto_ptr for those that are not familiar). Things such as auto deletion (which Irrlicht already does do somewhat as part of any object derived from IUnknown), throw exception on NULL dereference for more customized exception handling, etc.
But again, I retract my comment if there is no use for them to solve this particular problem.
![Smile :)](./images/smilies/icon_smile.gif)
On a side note, one advantage of hiding pointers behind templates is you can move to more of a smart pointer paradigm (see boost::smart_ptr... think reference counting auto_ptr for those that are not familiar). Things such as auto deletion (which Irrlicht already does do somewhat as part of any object derived from IUnknown), throw exception on NULL dereference for more customized exception handling, etc.
But again, I retract my comment if there is no use for them to solve this particular problem.
-
- Posts: 19
- Joined: Wed Mar 21, 2007 6:22 pm