• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

LPSTR to DWORD?

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #11
    Seriously?

    I'm still not sure whether to take this seriously but what the heck!

    C implements "strings" using char arrays with the end of the string flagged by a null (i.e. = 0). So create the char array of the necessary length and populate with the source pair.

    /* start */
    #include <string.h>
    #include <stdio.h>

    char *string1 = "one";
    char *string2 = "two";

    char* combination = (char*) malloc(strlen(string1) + strlen(string2) + 1);

    strcpy(combination, string1);
    strcat(combination, string2);

    /* use combination in some way */
    printf("%s\n", combination);

    /* get rid off when finished with */
    free(combination);

    /* end*/

    There are many variations on the above but should give you some pointers. Whatever you do though don't use DWORDs because they are not appropriate as pointers to data. Using LPSTRs is probably fine.

    Life can be even easier if you use the C++ String class.

    /* start */
    #include <string>
    #include <iostream>

    using namespace std;

    string string1("one");
    string string2("two");

    string combination(string1+string2);

    /* use combination in some way */
    cout << combination << endl;

    /* end */

    No need necessarily for new() & delete() because C++ allows declaration of variables at any point in function.

    Could give you the java version but Microsoft and java don't really mix. Somebody else can give you the C# which probably looks same as C++ variant.

    Ok, now tell me I've been had!

    Comment


      #12
      Re: Seriously?

      Still don't understand what he's on about. DWORD="Two" not = 2?. Does that mean highest byte is 'T'? etc? I must be thick. Anyhow you could cast char pointers and concat as OH says.

      Comment


        #13
        xog

        I think fundamental failure to understand the data types.

        he needs to go read a decent intro to c++

        Comment


          #14
          re

          cheers O.H.

          Comment


            #15
            Re: re

            First satisified customer in ages - other than the wife - so keep it coming.

            Comment

            Working...
            X