Jump to content

C++ dll param Handling


Recommended Posts

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...


87 (0x57)

The parameter is incorrect.


I tried to handle it like so...

if (!param || param == L"") {
        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.


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.

Link to comment
Share on other sites

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
Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...