Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Needs help with windows fileselector which crashes on Cancel button...

Author
Message
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 23rd Oct 2011 16:56 Edited at: 23rd Oct 2011 16:59
I've been trying to help out a guy on this thread: http://forum.thegamecreators.com/?m=forum_view&t=190567&b=1&p=0 but I'm having problems when the Cancel button is pressed the program crashes.

After doing a lot of reading up I've found out how to attach the comctrl32.lib (to the linker section) and use the functions InitCommonControls() and CoInitialize() but it still does the same thing. Using the file selector in my own C/C++ programs works fine without any glitches but in a plugin form crashes.

All other functions work fine and dandy.





It is basically a standard plugin setup but I've had to attach the comctrl32.lib.

Any ideas?

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 23rd Oct 2011 18:51
I've even just tried some googling and found destructions on embedding a manifest file, still everything compiles fine, the program runs, the file selector opens, but it "still" crashes when the cancel button is pressed...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Oct 2011 19:07
Without your file-selector class, it's impossible to say what's wrong.

I'd guess at uninitialised pointers, uninitialised memory, or even buffer overflows from what I see of the code you have posted ... but that's just a guess.

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 23rd Oct 2011 20:18 Edited at: 23rd Oct 2011 20:25
The file selector class is simple enough:



I've just moved the memory allocation into the Constructor() function, the new code now look like this... Still crashing on the Cancel button...



EDIT: Actually it now just crashes... Grrr...

EDIT2: I just changed this bit to cause the imminent crashing...


The fileselector would open if the above memory allocation was in place...

It seems that Constructor() isn't being called...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Oct 2011 23:53
Style issue 1:
Quote: "using namespace std;"

Don't do this at global scope in a header file. Put in within the class, or within a namespace, or even within inline functions in your header file, but not at global scope. Putting it at global scope affects every .cpp file you include that header into, whether you want it to or not.

Style issue 2:
The point of a class is to encapsulate its functionality, not leave it open for any code to trash its internal and (what should be) private state variables. Almost all of the real functionality in your code to do with filename selection is in your .cpp file, not with your class.

You have a limit of 259 character pathnames in your .cpp file, and a limit of 511 characters in your class - are you ensuring that you don't overflow these limits?

If you can't get DBPro to call your constructor, move the code into ReceiveCoreDataPtr and see if it gets called there.

Setting the filter: You are not ensuring that your filter is double-terminated (end with two null bytes).

The final one is probably the cause of the crash.

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 24th Oct 2011 00:16
I've cleaned everything up, after everything has been moved around the place in between the source files. One of the previous problems was I was not EXPORT'ing the Constructor(), but that's fixed.

This is wrecking my brain...

I've attached the entire project. I've googled I think everything. Sorted the hWnd and hInstance so that the selector shows up in the DBP window instead of being independent. I've linked the comctl32.lib and comdlg32.lib. I think I've exhausted everything. I've switched between Unicode and Multibyte. I upped the char buffers to 512 bytes just in case. It's only when the 'Cancel' button is pressed it crashes...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Attachments

Login to view attachments
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Oct 2011 15:09
I'll download your code this evening and try it out. You use VC++2008 don't you?

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 24th Oct 2011 18:35
Yes... Thank you...

It's probably something simple like DBP hasn't loaded up enough of the windows libs...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Oct 2011 19:55
Ok, I've got everything compiled with minimal config changes (you didn't include a solution file, and your pathnames are different to mine) but I can't reproduce your problem.

I'm using the following code to test, as I believe that this covers what you are doing (correct me if I'm wrong):


I've attached the DLL for you to try.

Attachments

Login to view attachments
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 24th Oct 2011 20:30
That still produces the same error when the Cancel button has been pressed, apart from that everything still works fine.

I'm wondering if MSVC links to different libraries when setting up DLL's compared to setting up a standard Win32 app.

I've cleaned the solution up and archived what I can so far. It should be all there, fingers crossed... The solution did have over 10 projects but last night I moved a lot of them so they are now separate.

The code you've put above is enough to produce the error when the Cancel button is pressed.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Attachments

Login to view attachments
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Oct 2011 00:07 Edited at: 25th Oct 2011 00:08
Quote: "I'm wondering if MSVC links to different libraries when setting up DLL's compared to setting up a standard Win32 app."

No, there's no difference.

Try the attached code (you'll need to compile it yourself) and see if it makes any difference - you can either use my solution file, or simply copy the project directory over your own.

I've spent some time cleaning up the code, and sorting out the project settings:
- Set up the linker lib directories and removed the specific libs specified for my interface plug-ins.
- Removed all of my header files from your project listing - they don't need to be added, and although what you did wouldn't cause any harm, it did make *your* files harder to find.
- Recode your WL_FSel class so that everything is self contained.
- ... including a complete recode of the setting of the file filter to properly double-terminate the filter, and to allow pipe as a separator.
- Replaced your gstring buffer with a vector-as-a-buffer.
- General cleanup of your commands, related to everything above.

If it still crashes, then can you post a screen-shot of the actual error you are getting, unless it's failing silently in which case can you check for a crash log in your DBPro executable directory.

Attachments

Login to view attachments
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 25th Oct 2011 01:52
Awesome... It works a dream now. And I've gone over your added comments a couple of times so I understand where everything is at.

I can't thank you enough. My code got that jumbled about I may as well have had goto's all over the place. Although I was gutted over 'gstring' being taken out, I've always had a 'gstring' in my code... he he (global string).

I will definitely have to start using more and more C++ style coding in my future projects.

Thanks once again...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Oct 2011 10:47
Great, then what I've done probably removed a buffer overflow that you had hidden in there somewhere.

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 25th Oct 2011 22:42
@IanM - After faffing about a bit today with the tests on this, I did actually track the problem down as it started crashing again on 'Cancel'.

As soon as started using the GetRelativeFilename() function the crash would occur. So I looked and found it straight away this time. The function normally returns a pointer to a string but on a zero length input string it would just return NULL. I've changed that now so that it returns a pointer to a NULL string.

WORKS!!!!!!!!

IanM, as lots of us have said, you're still a god!

Now to check the Color selector and the Font selector... (Hopefully I don't have any problems...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2019-10-16 23:41:07
Your offset time is: 2019-10-16 23:41:07