Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] how to get rid of warning C4275: non dll-interface class?

Started by enchanted Jul 3, 2009 at 2:06 AM 6 replies 14.6k views
Original Post
enchanted
enchanted
here is the warning. d:\main\component\component.h(9) : warning C4275: non dll-interface class 'CDXUTStatic' used as base for dll-interface class 'MyComponent' d:\main\component\dxut\optional\dxutgui.h(688) : see declaration of 'CDXUTStatic' d:\main\component\component.h(9) : see declaration of 'MyComponent' this is the class declaration #ifndef ECLASS #define ECLASS class _declspec(dllexport) #endif ECLASS MyComponent:public CDXUTStatic{ public: static int count; MyComponent(CDXUTDialog* pDialog):CDXUTStatic(pDialog){fTotalTime =0;count++;} virtual void Render( float fElapsedTime ); private: double fTotalTime; }; int MyComponent::count = 0; Here is the base class's declaration class CDXUTStatic : public CDXUTControl { public: CDXUTStatic( CDXUTDialog* pDialog = NULL ); virtual void Render( float fElapsedTime ); virtual BOOL ContainsPoint( POINT pt ) { return false; } HRESULT GetTextCopy( LPWSTR strDest, UINT bufferCount ); LPCWSTR GetText() { return m_strText; } HRESULT SetText( LPCWSTR strText ); protected: WCHAR m_strText[MAX_PATH]; // Window text };
phresnel
phresnel
I guess you should make CDXUTStatic a dll-interface class:

d:\main\component\component.h(9) : warning C4275: non dll-interface class      'CDXUTStatic' used as base for dll-interface class 'MyComponent'


Plus you shall use proper tags: help.
enchanted
enchanted
No.the base class is not write by myself,so I can't change it personally.If I ignore this warning ,what kind of trouble would be caused?
SiS-Shadowman
SiS-Shadowman
Possbile trouble: Say the structure's binary layout (the members or the functions) somehow changes and you don't recompile the dll that uses those structures, then your application using that dll, but compiled with the newer DirectX version may show undefined behaviour/crash.

I don't know if there's more that could happen, but I'm using
#pragma warning (push)#pragma warning (disable:4275)#pragma warning (pop)

regularly when inheriting from non-exported classes, or when having them as members. This stuff is not causing any trouble as long as you always have the chance to recompile your dll. But once you deliver the binary + headers to a customer, then this may just chrash.
rufus74
rufus74
This is a trick I used recently to work around the problem:



// 1. Don't export the derived class...
class ClassDefinedInDll : public ClassDefinedOutsideDll
{
// .....
};

// 2. Expose a method to create an instance and to destroy it.
// (Implement this methods in a cpp file compiled into the dll).

DLL_EXPORT ClassDefineInDll *createInstance( .... );
DLL_EXPORT void destroyInstance(ClassDefineInDll *ptr);


In this way, externally you deal with pointers only and the warning goes away because you don't export the derived class.
It might be that this solution doesn't apply to your case, but I hope this helps.
phresnel
phresnel
Quote:
Original post by SiS-Shadowman
Possbile trouble: Say the structure's binary layout (the members or the functions) somehow changes and you don't recompile the dll that uses those structures, then your application using that dll, but compiled with the newer DirectX version may show undefined behaviour/crash.

I don't know if there's more that could happen, but I'm using
#pragma warning (push)#pragma warning (disable:4275)#pragma warning (pop)

regularly when inheriting from non-exported classes, or when having them as members. This stuff is not causing any trouble as long as you always have the chance to recompile your dll. But once you deliver the binary + headers to a customer, then this may just chrash.


Out-of-core-disclaimer-and-sidenote: Only ever use #pragma warning (disable:XXXX) in the most rare and exotic cases, if nothing standards-conforming does the job, never never ever ever make this a regular programming tool, because, it is not. Rule of Thumb: Do not ignore warnings. Disabling a warning is the same as ignoring.
enchanted
enchanted
rufus74,return the pointer is truly a splendid idea.And that, is the right way the component dll should be.give the consumer only the interfaces,what is the component made up of?It's doesn't matter!the user shouldn't know.

BRILLIANT!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.