ULONG*

Discussion in 'C++' started by alex, Jun 23, 2004.

  1. alex

    alex Guest

    how do i initialize an atl ULONG* variable?






    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    alex, Jun 23, 2004
    #1
    1. Advertising

  2. "alex" <> wrote in message
    news:40d925d9$1_2@127.0.0.1...
    > how do i initialize an atl ULONG* variable?
    >


    Same way as any other variable.

    ULONG* x = something;

    If you are having some trouble with code, it is best to post the actual
    code.

    john
     
    John Harrison, Jun 23, 2004
    #2
    1. Advertising

  3. alex wrote:
    >

    [snip]
    > ULONG* pnChars = 50; does not compile (int)
    >
    > ULONG* pnChars = 50.0; does not compile (double)
    >


    Man. The * in ULONG* means something!
    It denotes a pointer! Neither 50 nor 50.0 are pointers.

    > ULONG* pnChars = 0; compiles but causes assertion failure when used in:
    >
    > if ( MyCRegKey.QueryStringValue(valName.c_str(), pszValue, pnChars) ==
    > ERROR_SUCCESS )


    Chances are high, that this function just wants to know the address of a variable
    where it should place the result:

    ULONG nChars;

    if ( MyCRegKey.QueryStringValue(valName.c_str(), pszValue, &nChars) ==
    ERROR_SUCCESS )

    Not in every case when there is a pointer variable in an argument list it means
    that you pass a pointer variable. In fact most of the time you simply pass
    the address of a variable. Reading the documentation closely usually clearifies
    things.


    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Jun 23, 2004
    #3
  4. >
    > ULONG* pnChars = 50; does not compile (int)
    >
    > ULONG* pnChars = 50.0; does not compile (double)
    >
    > ULONG* pnChars = 0; compiles but causes assertion failure when used in:
    >
    > if ( MyCRegKey.QueryStringValue(valName.c_str(), pszValue, pnChars) ==
    > ERROR_SUCCESS )
    >
    > MyCRegKey is an object instantiated from CRegKey -- a microsoft class

    that
    > wraps the registry functions.
    >
    > for this QueryStringValue issue I think I'll just call one or more of the
    > registry functions directly, that should take care
    >
    > of things, it would be good to know how to handle this though.
    >


    Common newbie mistake. Just because a function takes a pointer argument it
    doesn't mean that you have to declare a pointer variable. Just declare a
    ULONG (no pointer) and use the address of operator.

    ULONG nChars;
    if ( MyCRegKey.QueryStringValue(valName.c_str(), pszValue, &nChars) ==
    ERROR_SUCCESS )

    john
     
    John Harrison, Jun 23, 2004
    #4
  5. alex

    alex Guest

    "John Harrison" <> wrote in message
    news:...
    > >
    > > ULONG* pnChars = 50; does not compile (int)
    > >
    > > ULONG* pnChars = 50.0; does not compile (double)
    > >
    > > ULONG* pnChars = 0; compiles but causes assertion failure when used in:
    > >
    > > if ( MyCRegKey.QueryStringValue(valName.c_str(), pszValue, pnChars) ==
    > > ERROR_SUCCESS )
    > >
    > > MyCRegKey is an object instantiated from CRegKey -- a microsoft class

    > that
    > > wraps the registry functions.
    > >
    > > for this QueryStringValue issue I think I'll just call one or more of

    the
    > > registry functions directly, that should take care
    > >
    > > of things, it would be good to know how to handle this though.
    > >

    >
    > Common newbie mistake. Just because a function takes a pointer argument it
    > doesn't mean that you have to declare a pointer variable. Just declare a
    > ULONG (no pointer) and use the address of operator.
    >
    > ULONG nChars;
    > if ( MyCRegKey.QueryStringValue(valName.c_str(), pszValue, &nChars) ==
    > ERROR_SUCCESS )
    >
    > john
    >
    >
    >


    yeah, that worked, thanks!






    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    alex, Jun 23, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page