SetDllDirectory probably won't work. Cg. Dll likely just links to OpenGL.dll.
When the OS loads Cg. Dll, it sees that there's already a module loaded with that name (yours), so it links Cg with that instead of going off to find some other copy. That is, the search order that SetDllDirectory modifies never even comes into play because the OS doesn't do any searching I suspect your best bet will indeed be to detect re-entrant calls to your library.
When you detect one, instead of doing your custom handling, forward the call directly to the real OpenGL library, which you have a reference to due to calling LoadLibrary and then GetProcAddress for each of the library's functions.
SetDllDirectory probably won't work. Cg. Dll likely just links to OpenGL.dll.
When the OS loads Cg. Dll, it sees that there's already a module loaded with that name (yours), so it links Cg with that instead of going off to find some other copy. That is, the search order that SetDllDirectory modifies never even comes into play because the OS doesn't do any searching.
I suspect your best bet will indeed be to detect re-entrant calls to your library. When you detect one, instead of doing your custom handling, forward the call directly to the real OpenGL library, which you have a reference to due to calling LoadLibrary and then GetProcAddress for each of the library's functions.
I haven't run into this issue before, so I'm not familiar with the best way to handle it. Adding a snippet to the start of each function to call the real one on a particular condition isn't an issue, but what is the best thing to check for? – peachykeen May 3 '10 at 20:33 1 Actually, I had a thought.
Would it be effective and efficient to use a simple global boolean value? At the start of my function, check if (cameBack) { call realFunc; } else { cameBack = true; }, then set it to false when execution leaves. That's sounding like it would be work.
My code does not, so far as I know, need to be thread-safe (the program has a single rendering thread, and a single thread that refers to OpenGL at all, from my debugging). – peachykeen May 3 '10 at 20:41 1 A global variable is exactly what I would have used for a first attempt. If you need multiple threads, then you can try thread-local storage instead of plain globals.
If one of the functions you intercept ends up calling a different OpenGL function that you also want to intercept, then you can use function-specific global variables instead of just one. – Rob Kennedy May 3 '10 at 21:57.
You can use the magic of activation contexts to attempt to solve your problem. A lot hinges on weather the 3rd party components in your system already have manifests - and how much tampering with those manifests might constitute a license violation. In order to resolve dll versioning issues, Windows XP got a technology called activation contexts.
Sometimes known as side-by-side assemblies, or even something horrible like Application Isolation To summarize lots of reading into a small space: manifests are chunks of XML data that can describe an assembly, or describe a dependency on assemblies. An assembly is a manifest, plus its dll. The reason this exists is so that an assembly can take a simple dll."comctl32.
Dll" and its version number (v6), and create a thing with a bigger more unique name, such that multiple versions of the simple dll can be installed in the same place safely. Assemblies are intended to be installed in C:\Windows\WinSxS. When a manifest file describes the dlls in an assembly, its called an assembly manifest.
And usually has a different name to the dll. When a manifest file describes the assemblies a dll or exe uses, its called an application manifest, and is usually embedded as an RT_MANIFEST resource - in EXEs with a res id of 1, in Dlls with a res id of 2 - or on disk as a file with a name "appname.exe. Manifest" / "dllname.dll.
2. Manifest". Application manifests define a thing called an activation context - which is basically a namespace that windows will search in for things. Each manifest creates an activation context.
Each activation context has a mapping of simple dll names to assemblies. So, if you create a assembly with your opengl32. Dll file, and create an activation context for the app.
Exe referencing (the local opengl32. Dll) file, then, potentially, all the remaining dlls can (and will) continue to use the systems opengl32. Dll file despite the fact that the names are very similar coff.
The problem is, the res-id of the application manifest - 1 - means that its used to create the process default activation context - so ALL dlls that do not have their own explicit manifests (Cg? ) are going to search the process default space and find that opengl32. Dll So you have to create manifests for every dll that doesn't already embed one, making sure to simply NOT reference your opengl32.
Dll assembly, which should allow then to revert to the default search order and find it in the normal system32 location. This means that your opengl32. Dll cannot be in the exe's folder as that folder is searched for dll's before system32 (the fact you rely upon for hooking).
We are saved by the rather simple search order the system takes when searching for assemblies. First it searches in WinSxS. Your Opengl32.
Dll won't be in there, installing there is a hard problem. Then it searches in the exe's folder, for a subfolder with the name of the assembly, THEN it searches in the exe's folder for the assemblies manifest directly. This means you can create an assembly - called something like: "OpenGLHook" And your folder structure would look like: \appfolder\ app.
Exe app.exe. Manifest - contains a dependentAssembly node to OpenGLHook OpenGLHook\OpenGLHook. Manifest - contains a file name=opengl32.
Dll OpenGLHook\opengl32. Dll - your hook dll yourimpl. Dll - your implementation dll that linkgs to cg.
Dll cg. Dll - cg libraries cg.dll. 2. Manifest - a stub manifest you put together to ensure cg doesn't use the app default activation ctx.
Um, Good luck?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.