JohnOne Posted February 17, 2014 Share Posted February 17, 2014 (edited) I have an exported C++ win32 dll function. It has 2 parameters of LPTSTR. It works as I expect when I give it correct params. If I pass an empty string however ("wstr", ""), it errors out with... ERROR_INVALID_PARAMETER 87 (0x57) The parameter is incorrect. I tried to handle it like so... if (!param || param == L"") { CloseHandle(hndl); return 0; } But it does not seem to catch that and the function proceeds, and of course errors out. I guess it's because there's nothing there to have a pointer to, but my question is, is there way to correctly handle this. Cheers for reading, and I hope I made sense. EDIT: I figured an unsafe way to deal with the param that's expecting a fully qualified path, by testing for ":" Of course that's just silly. Edited February 17, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 17, 2014 Share Posted February 17, 2014 (edited) Equality of strings will check for the pointers being equal. What you actually want with C strings (character arrays) when checking for null or empty is this. if (!param || !*param) This will check to see if the pointer is null, and if it isn't, checks to see if the first character pointed to is null. If it's supposed to be a path, you should probably validate it using this http://msdn.microsoft.com/en-us/library/windows/desktop/bb773584%28v=vs.85%29.aspx Edited February 17, 2014 by Richard Robertson JohnOne 1 Link to comment Share on other sites More sharing options...
JohnOne Posted February 17, 2014 Author Share Posted February 17, 2014 So simple, I cannot believe I never thought of that. Thank you Richard. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now