Sign in to follow this  
Followers 0
JohnOne

C++ dll param Handling

3 posts in this topic

#1 ·  Posted (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 by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#2 ·  Posted (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 by Richard Robertson
1 person likes this

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0