Passing 2-Character String

This is a discussion on Passing 2-Character String within the C++ Programming forums, part of the General Programming Boards category; I am trying to pass a 2 character string to a function. The second character of the string must be ...

  1. #1
    Why am I a programmer? shoutatchickens's Avatar
    Join Date
    Mar 2008
    Posts
    45

    Passing 2-Character String

    I am trying to pass a 2 character string to a function. The second character of the string must be either P or R.

    When executed, the function returns a value of 9999 which indicates that the second character of the string was not a P or R.

    I have tried going about this as many ways as I can find, but I am not very adept when it comes to C++. I am using VS 2005 for this.

    Here is the code in question:
    Code:
    /**
    	This function converst PS position into Row/Col position
    	**/
    void PStoRC(int pos, int *result) {
    	int  HFunc, HLen, HRc;
    	char *HBuff = "AP";
    
    	// set the variables for the convert to R/C function
    	HFunc = HA_CONVERT_POS_ROW_COL;
    	HLen  = 0x00;
    	HRc   = pos;
    
    	// execute the conversion function 
    	hllapi(&HFunc, HBuff, &HLen, &HRc); // <- This is where the string is passed
    
    	// get the results
    	result[0] = HLen;
    	result[1] = HRc;
    }
    What are reasons that the function would not see the P? The first character identifies a session to apply the function to. This character is identified as I can change it to produce other errors such as invalid session ID. Is there something I'm doing wrong?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Got a prototype for hllapi?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Looks OK to me, so perhaps somewhere else is where the problem is?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Why am I a programmer? shoutatchickens's Avatar
    Join Date
    Mar 2008
    Posts
    45
    Code:
    long WINAPI hllapi(LPINT, LPSTR, LPINT, LPINT);
    The first variable is a number that identifies a certain "function". That number determines how the other variables are used. So far, everything I have tried has worked up until this fucntion. (The HA_CONVERT_POS_ROW_COL)

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I'm not a Windows programmer, or a student of their naming conventions, but I remember seeing a lots of szVarName declarations for pointers to null terminated strings. Is LPSTR the same thing? Have you tried another level of indirection for HBuff, as in &HBuff?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  6. #6
    Why am I a programmer? shoutatchickens's Avatar
    Join Date
    Mar 2008
    Posts
    45
    I've tried passing (char *)&HBuff, which I tihnk is pretty much the same as passing HBuff.
    It produces compile errors without the type cast.

    I have also tried declaring the string in different ways. Making a classic C-Syle array and setting the characters individually, as well as making strings that are NULL terminated.

    Since the first character is being identified correctly, I can't imagine what could be wrong out side of a problem with the library. I just kind of find that hard to believe for some reason.

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    What is HLen? The length of the string you are passing?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  8. #8
    Why am I a programmer? shoutatchickens's Avatar
    Join Date
    Mar 2008
    Posts
    45
    Not in the case of this particular HFunc value.

    In this case it is passed as a null value and used as a return field for the row.

  9. #9
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Well the manual appears to be here (4.5). If you are sure that the result is HARC99_INVALID_CONV_OPT and you are doing everything else as required then probably you might need to seek support from the library providers/support forum...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  10. #10
    Why am I a programmer? shoutatchickens's Avatar
    Join Date
    Mar 2008
    Posts
    45
    That's definately the error I am getting. Looks like I will have to seek support for the library. Thanks for all of your help.

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Quote Originally Posted by Dino View Post
    I'm not a Windows programmer, or a student of their naming conventions, but I remember seeing a lots of szVarName declarations for pointers to null terminated strings. Is LPSTR the same thing? Have you tried another level of indirection for HBuff, as in &HBuff?
    LPSTR = char*.
    LP means it's a pointer, and STR says it's a string.
    Stupid Windows typedefs / conventions.

    Quote Originally Posted by shoutatchickens View Post
    I've tried passing (char *)&HBuff, which I tihnk is pretty much the same as passing HBuff.
    It produces compile errors without the type cast.
    Do not use casts!
    The compiler is trying to alert you that what you are doing is wrong and the cast only hides it!
    Only use casts if you are really, really, really, really sure of what you are doing.

    And btw, that prototype is very uninformative.
    If you can, do not strip the parameter names: http://cpwiki.sf.net/Don't_remove_parameter_names
    Something to think of in the future. Good luck.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21