Advertisement

DLLs troubles

Started by January 06, 2001 04:51 PM
3 comments, last by Fresh 24 years ago
Ok I''m making an application which requires to be extensible. The use of this program will require data from an array of a structure which contains amongst other variables a function pointer. This structure will in future versions of this program grow - however it is most likely this is all that will grow. So instead of supplying users with a new version of my entire executable, I would like to supply them with something less which just replaces an old dll. In this dll will be contained the array of structs and the functions it points to. for example:

float
_1S(SPosition *Position) {
	float powered = (float)(Position->xe2 + Position->ye2 + Position->ze2);
	
	return (float)(4 * powered * exp(-2 * sqrt(powered)));
}

struct SStates {
	int state;
	char *name;
	int width;
	float (*CalculatingFunction)(SPosition *Position);
} States[] = {
	{ATOMSTATE_1S, "1S", 6, _1S},
	{ATOMSTATE_2S, "2S", 24, _2S},
	{ATOMSTATE_3S, "3S", 46, _3S},
	{ATOMSTATE_END, "", 0, _NoState}
};
 
That array will grow in time. I know very little about dlls, but I imagine one would be the best way to do this. Correct? Also, would it be runtime or load time linking. As far as I can tell, load time linking requires a .lib file of the dll with the addresses of the functions and the variables. As I see it, simply supplying an updated dll in this case would not work because the extra lib info is not linked into the executable. So I would imagine it is necessary to use runtime linking. I have an example of how to retrieve a function using the GetProcAddress function, but I want here to get the SStates States[] array and be able to access it''s data and the functions it points to. And I''ve no idea how... Please any suggestions would be nice r. "The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."
If you use a .lib it''s static linking and cannot be changed without relinking.

I''m not sure how to get at data members in a dll, you might still use GetProcAddress & just cast it...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
So runtime linking it is. That means instead of having function pointers to the correct function in the array, I would have the name of the function in the array, so I can GetProcAddress it.

So does anybody know for sure how to access global variables from across a dll using runtime linking? This variable will be present in all versions of the dll.
r.


"The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."
Hi!

I don''t know if you are able to use GetProcAddress(), but another option might be to export a function which just returns the global array.

So you might just have:

SStates* QueryStates()
{
return States;
}

The QueryStates() function would be exported by the DLL and can be obtained using GetProcAddress()

- MK42
Ah thanks - should''ve seen that myself.
r.

"The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."

This topic is closed to new replies.

Advertisement