CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    1,689

    How do I write to a struct like this?

    This is the struct that I need to write to, I can not change it as it's part of Firefox's api.
    Code:
    typedef struct _NPVariant {
        NPVariantType type;
        union {
            bool boolValue;
            int32_t intValue;
            double doubleValue;
            NPString stringValue;
            NPObject *objectValue;
        } value;
    } NPVariant;
    It's been a long time since I've used unions and I don't remember how to write to it, and I think I've forgotten how to. I seemed to think that unionable items all had to be the same size (maybe that was just C.)

    But anyway, here my method is passed one of these structs via pointer from an external dll (which I also have no control over, it's the firefox flash plugin.)

    Code:
    result -> type = NPVariantType_Int32;
    int32_t ii = ((Area*)PluginOwnerNPP) -> AbsTop.GetValuei();  //returns an int
    result -> value = ii;
    //result -> intValue = ii;

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: How do I write to a struct like this?

    Try result->value.intValue = ii;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured