C++ DLL Export driving me NUTS

Started by
3 comments, last by emeyex 15 years, 8 months ago
Hey guys! Right heres the deal... I currently have a working architecture built in C++ visual studio 2005. I have fully lit scene, meshes, normal maps etc etc. Essentially everything displaying correct. I m currently trying to implement some tools e.g. a level editor etc. The approach im trying to use is to build a tool in c# and render the scene to a special 'render panel' using the c++ engine architecture in Engine.dll I currently have 4 functions im exporting from my c++ to use in my c# app. Appsetup(HWND Hwnd) AppShutdown() UpdateScene(float dt) RenderScene() 4 functions thats it!! (appsetup creates an instance of my engine class etc using the window provided, works FINE in pure c++ app) However, im exporting these functions and trying to run them in my c# loop so that the HWND passed through is the render panel in my app (to give me a nice rendered section n tools/buttons around the edge etc). Now i tried this with another app, (a particle system editor) and it worked FINE. displays and renders/updates correctly. Now.. when i try using my Engine.dll (exports functions with the same signature) i get the error: ''An unhandled exception of type 'System.AccessViolationException' occurred in WorldED.exe Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'' . The compiler also highlights the function UpdateScene() or RenderScene() in the c# app. Now the hard thing is with a dll i cant (that i know of) step through code in my engine project to see what is happening... just some random error that i CANT seem to fix with this app!!. Its driving me CRAZY!!! PLEASE HELP!!!!! (i can post any additional info anyone needs). oh side question.. is it ok to forward declare an exported function.. e.g DLL_EXPORT void UpdateScene(); and then later on have the body DLL_EXPORT void UpdateScene() { // DO update stuff } (although that isnt the problem in my app since if tried it both ways!)
Advertisement
This is how I export my classes.
#ifdef MYCLASS_EXPORTS  #define MYCLASS_ __declspec(dllexport)#else  #define MYCLASS_ __declspec(dllimport)#endifclass MYCLASS_ MyClass{  public:   void funtcion();   //etc..};
I'm pretty sure you can hit breakpoints inside of your DLL, even if its being called from managed code. I assume the DLL is being compiled in a different solution. Find the .PDB file and add it to your symbol directory in the editor solution. (Tools > Options > Debugging > Symbols)

It sounds like you know what you're doing, but I'll ask anyway: do you know what you're doing with the dllexport stuff? Have you done it successfully before?

The particular error you seem to be getting sounds like you forgot to pin your image pointer or something.
Did you check if a function is actually called from this dll ? (maybe just put a MessageBox in there)
How about commenting out some huge blocks of code and see if it will work then (with less functionality of course).
Also, if you want to be able to debug the C++ code running from a solution in which you have both C# and C++ projects, then you need to be sure to check the "Mixed mode debugging" checkbox in the project properties (I think it's the properties for the C# app you're booting from).

This topic is closed to new replies.

Advertisement