Jump to content


Photo

WindowDLL


  • Please log in to reply
3 replies to this topic

#1 DefuzionGames

DefuzionGames

    GMC Member

  • GMC Member
  • 1417 posts
  • Version:Unknown

Posted 18 June 2012 - 02:39 PM

I have this window dll with many functions getset window focus, get window handle by caption and set window show style.

It works fine.

But every now and again it wont work. I get about 40 errors at start up saying failed to define external function for this dll.

So whats causing this. Nothing else is changing.
  • 0

#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 18 June 2012 - 10:36 PM

I have this window dll with many functions getset window focus, get window handle by caption and set window show style.

It works fine.

But every now and again it wont work. I get about 40 errors at start up saying failed to define external function for this dll.

So whats causing this. Nothing else is changing.


failed to define external happens on the external_define line. if it worked before but not anymore and you did not mess with the function parameters in the dll. then here is the reason:

When you use a dll and you know it works without problem and you get this error, it's because you forgot to free the dll from memory with external_free, or GM could not quit properly (when it does end properly, it external frees the dlls for you, well, windows does).... Also if GM toggles an error in your game, like any error in your script, variable not found for example, not dll related. you no longer have the option to Abort, you must click ignore until the game resumes (if it can) and then you must quit (ESC) the game normaly, it's not always an option but try if you can. This to allow external free to be called.

Solution: Do not abort a game, hit ignore until the game resumes normally if possible then quit (esc). If it starts to show the error, then you must fully shut down and restart your computer.


The other reason if the error happens on some PCs is you used MS to make the dll and forgot to install the MS redist package with the dll. I use code::blocks for my dlls so this wont happen.
  • 0

#3 paul23

paul23

    GMC Member

  • Global Moderators
  • 3355 posts
  • Version:GM8

Posted 18 June 2012 - 10:51 PM


I have this window dll with many functions getset window focus, get window handle by caption and set window show style.

It works fine.

But every now and again it wont work. I get about 40 errors at start up saying failed to define external function for this dll.

So whats causing this. Nothing else is changing.


failed to define external happens on the external_define line. if it worked before but not anymore and you did not mess with the function parameters in the dll. then here is the reason:

When you use a dll and you know it works without problem and you get this error, it's because you forgot to free the dll from memory with external_free, or GM could not quit properly (when it does end properly, it external frees the dlls for you, well, windows does).... Also if GM toggles an error in your game, like any error in your script, variable not found for example, not dll related. you no longer have the option to Abort, you must click ignore until the game resumes (if it can) and then you must quit (ESC) the game normaly, it's not always an option but try if you can. This to allow external free to be called.

Solution: Do not abort a game, hit ignore until the game resumes normally if possible then quit (esc). If it starts to show the error, then you must fully shut down and restart your computer.


The other reason if the error happens on some PCs is you used MS to make the dll and forgot to install the MS redist package with the dll. I use code::blocks for my dlls so this wont happen.


Or simply linke to the static runtime library instead of dynamic :P.


Also I'm really wondering why sometimes dlls aren't freed - as it isn't GM's responsibility to free it. It is actually the responsibility of the "dllhost" process on your pc. GM just tells the dllhost to free when you call the function. However the OS will always free a dll when the master proces is no longer active.

I never experienced this problem myself though, never had a problem with running dlls after an error; I'd love to actually experience this problem myself, so I could debug it a bit and see if dllmain the dll is actually unloaded. The closest thing to a cause I found here

When handling DLL_PROCESS_DETACH, a DLL should free resources such as heap memory only if the DLL is being unloaded dynamically (the lpReserved parameter is NULL). If the process is terminating (the lpvReserved parameter is non-NULL), all threads in the process except the current thread either have exited already or have been explicitly terminated by a call to the ExitProcess function, which might leave some process resources such as heaps in an inconsistent state. In this case, it is not safe for the DLL to clean up the resources. Instead, the DLL should allow the operating system to reclaim the memory.


  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 19 June 2012 - 12:37 AM

Or simply link to the static runtime library instead of dynamic

It's like the n'th time this was stated. You cannot use the static runtimes in a dll compile. At least not with 2008 and earlier MS dev studios. I spent days trying to make the static runtime compile work. People help telling me how to do it but were no-where to be found when I reported the sln was not compatible...

Also I'm really wondering why sometimes dlls aren't freed - as it isn't GM's responsibility to free it. It is actually the responsibility of the "dllhost" process on your pc. GM just tells the dllhost to free when you call the function. However the OS will always free a dll when the master proces is no longer active.

Yes, I implied that from my wording. I don't know either but something happens when you hit that abort button. The worst though is this affect other gm compiled games that use a dll so I have no idea WTF is going on with that under the Windows hood. It's like all subsequent executions of a GM exe is affected by the execution of the one that screwed things up.

I never experienced this problem myself though, never had a problem with running dlls after an error; I'd love to actually experience this problem myself, so I could debug it a bit and see if dllmain the dll is actually unloaded. The closest thing to a cause I found here


You can always make an app that loads a dll and write code that makes GM trigger an error.

create object0
load_dll();
inst = instance_create(x,y,object1);

step
with(inst) instance_destroy();

err = inst.x;


just run and click abort. if you are lucky, the 20th time it will crash on load_dll.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users