Archived

This topic is now archived and is closed to further replies.

Infinisearch

DLL's

Recommended Posts

I want to make the video, sound, input... portions of my program into DLL''s. But I also want to have different implementations of the same exported function depending on user hardware (SSE,SSE2,3DNOW,FPU...). The executable is going to query the system as to capabilities and store the result in globals, and i was going to check what to use by using dllmain() to check the globals. Is there a way I can load only the appropriate ''code path'' for the user''s system? Or will i have to make seperate dll''s for each ''code path''? Or is there a better way to go about this? (oh, each implementation will have the same interface of course) -potential energy is easily made kinetic-

Share this post


Link to post
Share on other sites
you could have the dll return the interfcae in the form of an object (ie oop goodness). this can be a "real" class which implements yoru functons using virtual functions. your program loads the library and then calls the GetBlahInterface(theFlags) which can pass the flags and returns an instance of the object approiate for the cpu (the dl should not handle it, so that the game can force certain code paths regardless of the cpu). yoru funtion woudl look like:

  
CBaseClass *GetBlahInterface(DWORD flags)
{
if(flags&SSE2)
return (new CSSE2Class());
else
if(flags&SSE)
return (new CSSEClass());
else
if(flags&3DNOW)
return (new C3DNOWClass());
else
if(flags&MMX)
return (new CMMXClass());

return (new CGenericClass());
}


of you could use function pointers in a struct:

  
// same deal

// of course in this case you wold have varibles like

BlahFuncPtrs SSE2BlahFuncPtrs =
{
InitSSE2,
CleanupSSE2,
switchStuffSSE2,
makeCoolEffectSSE2,
dazzleThemSSE2
}
// you may want to place the SSE2, SSE, MMX, etc portion

// in fonrt of the function names for quicker viewing

// up to you.

BlahFuncPtrs *GetBlahInterface(DWORD flags)
{
if(flags&SSE2)
return (&SSE2BlahFuncPtrs);
else
if(flags&SSE)
return (&SSEBlahFuncPtrs);
else
if(flags&3DNOW)
return (&3DNOWBlahFuncPtrs);
else
if(flags&MMX)
return (&MMXBlahFuncPtrs);

return (&GenericBlahFuncPtrs);
}


that hopefully makes sense.

Share this post


Link to post
Share on other sites
Thanks for your response ''person''... I realize now I should have just ask is there a way to only load certain functions from a DLL not all of them? I don''t know much about DLL''s beyond run time linkage, they have a DLL main function, and u might need a DEF file to export those files. I don''t want to waste memory by loading unnecessary code, but i was hoping there was a way that i wouldn''t have to make one DLL for each implementation.

-potential energy is easily made kinetic-

Share this post


Link to post
Share on other sites