Thread: Strange behaviours

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    147

    Strange behaviours

    Hello,

    I have developed a program which has a function name 'cargarDLL' that inside it load a DLL made by an external developer (I mean, I have no control over dll source code).

    My program and the DLL has been running OK until I upgrade compiler versión from 4.5.2 to 4.7.0. Now the first-called exported dll function runs ok, but when I return from my funcion (cargarDLL), in the 'return' keyword it crashes.

    My question are:

    * Does a DLL run in the data space of the called process? I ask this to know if a bug in the dll can corrupt my program. If not I am sure it is a bug in my code.

    * If it is a bug in my code, how can I catch it? Because in the 'return' keyword I not see anything special to make me suspect of a bug.

    Any ideas how can I solve this?
    Thanks.

  2. #2
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Sounds more like the code is crashing because of some other reason, not the DLL at all.

    How do you catch it? <sarcasm mode> Have you tried using a debugger at all?</sarcasm mode>

    Single-step the program with NO compiler optimisations and see what happens. Chances are you will discover that it crashes somewhere else entirely.

    Also, if you want a "quick and dirty" test, just splat the function with printf's and other code in between calling the DLL and returning and outside the function from it's original call-point (which is where I'd focus my debug efforts, to be honest - sounds like you return a value that causes whatever code that called "cargarDLL" to crash). See what return values you are getting, what you're returning, what you're passing off to the DLL, etc. Call the function outside of everything else in your code (i.e. as close to being the first line of main() as you can get) with valid values and see what it does.

    At a complete guess, I'd say you're returning something like a memory handle to local memory, or the code calling cargarDLL just isn't setup to handle whatever it returns

    But you would be saved from a lot of my and your own guesses by just using a debugger. That's what they are there for. Hell, they're even pretty good at telling you if something crashes in a DLL you loaded, or even things like the C runtime and not your code.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange!
    By manav in forum C++ Programming
    Replies: 17
    Last Post: 03-27-2008, 08:13 AM
  2. something strange
    By negevy in forum C Programming
    Replies: 5
    Last Post: 09-04-2005, 12:37 AM
  3. Very Strange Bug
    By Asm_Freak in forum C++ Programming
    Replies: 0
    Last Post: 02-09-2003, 11:04 PM
  4. strange strange functions
    By threahdead in forum C Programming
    Replies: 4
    Last Post: 10-13-2002, 05:31 PM
  5. It's just strange
    By Series X4 1.0 in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-06-2002, 07:59 PM