   Cg code triggers an error when run from inside a DLL
  I have an OpenGL application that uses CgFx to load and run shaders. Lately, I've experienced a very strange behavior. When a call to cgSetPassState caused an error a couple of days ago, my LONG hours of debugging didn't reveal any pitfalls. Today, I realized that the reason that cgSetPassState triggers the error callback is that my cg related code resides inside a DLL!!! OK, I know what you're thinking, but no, I'm not crazy! [wink] Just read on.As soon as I move the very same code to a standalone exe, things start to work smoothly, but the very moment that I put the code back into the function that resides inside the dll, cgSetPassState causes a CGerror = 1000, which translates to an "unknown error".I am extremely confused. This is SO strange I'm speechless. I use Glut to create the window and initialize OpenGL so I'm pretty sure the bug is not related to my OpenGL initialization code. I've tested the same code using Direct3D with the same results. What does happen here? What's causing this behavior? What's the rational explanation to this? And here's a view of my code:[exe]// call a function (say F) from the DLL[DLL]void errorCallback() {CGerror error = cgGetError();}CGtechnique technique;void display() {CGpass pass = cgGetFirstPass( technique );while ( pass ) {cgSetPassState( pass );cgResetPassState( pass );}}void F() {glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);glutInitWindowSize(640, 480);glutCreateWindow( "test" );CGcontext context = cgCreateContext();cgSetErrorCallback( errorCallback );cgD3D9RegisterStates( context );CGeffect effect = cgCreateEffectFromFile( context, "C:\\DEBUG.fx", NULL );if ( !effect ) {return;}technique = cgGetFirstTechnique( effect );if ( !cgValidateTechnique( technique ) ) {return ;}glutDisplayFunc(display);glutMainLoop();}I hate to think this is one of those times that I don't get any answers. So don't let me down guys. Even your craziest explanations are welcome. Shoot at will!Thanks in advance   
  Are you calling Cg functions from both the main exe and the DLL ? In this case, it's probably just a static data member or a separate heap issue. First, make sure to link your exe and all of your DLLs with the MT DLL runtime (not the static ones). Then, I don't know how well Cg handles replicated statics and heap separation on a single context. It's probably best to call these functions only from within one single DLL.;  Thanks for the reply.I've already linked with the MT DLL runtime and I'm only calling cg functions from the DLL. It's very strange. I've been debugging this for 3 long days for now with no results. No matter how many times I changed that, the cgSetPassState call (and only this call) always breaks.Cg returning an "Unknown Error" is not much of a help either. Are there any other compiler options that might somehow relate to this behavior? Any info on why cgSetPassState might fail in general? Thanks alot   