what a night! WHAT! A! NIGHT!
If I ever "should've written a waterproof testcase", this was it!
Using a unmanaged C++ with a C# app really has its disadvantages! If you don't have a good Test Driven Design that is! Let me give you some real life examples.
[ where's the problem? ]
For one, is the C# System.NullReferenceException.
MSDN says: The exception that is thrown when there is an attempt to dereference a null object reference.
I learned this past week that it really means: The DLL file was not found. The function was not found in the DLL file. The function in the DLL crapped itself.
Yes, either one of those three errors! My tip is set something in the absolute beginning of your function to show that it's actually called, thus making it clear that it's not one of the two first reasons for NullRef.Exc. How do you do that? Read on!
[ how do I get there? ]
hohoho... here's the fun part... YOU CAN'T! You can't step into the function like you can when debugging from a C++ app! HAH! How fun! And OutputDebugString() from a unmanaged DLL doesn't show up in the output window when stepping through your C# app! So how did I do it? Thanx to this little gem, it's freeware. DebugView
It shows OutputDebugString() messages, even when you're not debugging the app! ie. you can have it run in the background while you test out a program that can't be run in debugging mode inside VS.NET (but the program must've been compiled in debug mode).
[ how did you debug it? ]
By adding OutputDebugString() like make-believe breakpoints in my C++ DLL, and watching the text fly by in DebugView. Kinda like programming before you knew what a breakpoint was!
[ what did we learn? ]
if you can't figure that out... re-read! ;)
[ any tips? ]
Yes. Test Driven Design! I'm not kidding folks! If you're only going to make a test case for ONE module in your life, make it this one... Create a uber waterproof C++ test app for your C++ DLL. Remember that all functions promises something/somethings. Like changing a internal value, to something valid. Or returning a pointer on success and otherwise NULL. So check for those stuff to. But a better introduction can be found on this article here at gamedev.
If you're interested, get this book. I know I am...