DLL Crash

Windows specific forum
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

DLL Crash

Post by Karbon »

When I exit my program I'm getting a crash, and OnError is reporting the error number -1073741819 on the last line of my Windows callback function.

I've seen this before and just like before I've recently added some calls to a DLL. The first time the solution was to use CallCFunction instead of CallFunction but I'm *positive* that they're stdcall functions in the DLL as I actually wrote this one. That, and I've tried CallCFunction and it didn't work :-)

So, is there something not happening in the DLL on shutdown? It's written in Delphi and is a "plain" DLL - not ActiveX or .NET.

Can anyone make a suggestion as to what I should be looking for? The crash only happens when I exit the program *if* I've called a function in that DLL at some point. The DLL is very straight forward though I am passing some strings in I take them in Delphi as a pchar (which is supposed to be 'ok' for DLLs)..

Thanks for any suggestions - this one has be a bit stumped.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

To add something here - if I *don't* call CloseLibrary before I "end" it doesn't crash!

Hrm...
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Is it possible that some condition in the app leads to the library being closed before it is used?

Just grabbing at a straw.
Dare2 cut down to size
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

No, that's the funny thing - the calls to the DLL all work just fine - it never crashed except when I exited, and then only if I had CloseLibrary()'d it right before.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

my straw to grab is - could you be closing it twice?
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Thought about that too and not AFAIK (both calls to CloseLibrary checked with IsLibrary() before the call was made).
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

my guess is that there's an invalid pointer somwhere.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

That's what I thought too but the only pointers are to the strings passed into the DLLs (and that's 'automatic'), and they all work so they can't be *that* invalid :-)

Perhaps I'm holding on to something in the DLL when I try to close it.. I can't imagine what, though, because the functions are all very straight forward and return clean every time.

I'll find it eventually :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

Karbon wrote:Thought about that too and not AFAIK (both calls to CloseLibrary checked with IsLibrary() before the call was made).
you have multiple calls to CloseLibrary?
without seeing the code, it feels like this could be your problem...
can you restructure your code to only use the one CloseLibrary?
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

No, closelibrary() only appeared once in the entire code tree - I comment it out and the problem disappears :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

So the app runs for a while, using the library successfully?

What version of PureBasic? 4.1? 3.94? 4.2a?

Sorry if this sounds silly (and in the absence of source, which I understand you probably cannot release) but:

There are no conditionals that allow an exit (resume processing) or do some sort of similar bypass between "CloseLibrary(#x)" and "End"? That is, your flow on closing down is linear and unconditional. (Just trying to eliminate the potential error being your side).

Also, are there any clean-up calls to the dll made before the close?

And also, does the DLL have the equivalent of PureBasic's DetachProcess(Instance) and DetachThread(Instance)? That is, could something there be jacking up?


Edit:

I am sure you have done this, but if not - is it possible to get the same result doing something like

Code: Select all

Procedure CallBack(..
..
EndProcedure

OpenLibrary(..
CallFunction(..
CallFunction(..
CloseLibrary(..
And see if you get the crash? Or not. Which may help determine if it is in the lib or PB or something harder to find.
Dare2 cut down to size
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: DLL Crash

Post by tinman »

Karbon wrote:that DLL at some point. The DLL is very straight forward though I am passing some strings in I take them in Delphi as a pchar (which is supposed to be 'ok' for DLLs)..
Does Delphi take a copy of the string pointer and use it as a native Delphi string? Then when you call close library, it cleans up it's resources, freeing the strings. Then when your app quits it tries to free strings which are already freed?

Could you give more details of the "crash"? It is an unhandled exception? What is the exception?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I am thinking along timan's lines although I wouldn't have thought that the dll could free the strings created by PB because it will have no access to the heap created by PB. I would suspect perhaps something in the dll (perhaps a global pointer) is being made to point at one of the strings passed by PB and at some point the dll is thus attempting to free this memory.

Karbon, does the dll have an entry point function being called when the dll is being detached and does this function free any global pointers etc?
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Well, I can't think of anything else to add to the checklist but I am thinking it is going to be something with the equivalent of DetachProcess().

Interested to hear if you got it fixed.
Dare2 cut down to size
Post Reply