CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2014
    Posts
    8

    Runtime conditional varibles

    Hi there, I apologise if this is in the wrong place.

    I am looking for a way to declare variables at run time which being a static language shouldn't happen. I will explain my situation.

    I am upgrading a legacy program that modifies executables (non malicious). I am trying to add 64bit support.

    It is a huge project and I understand the majority of it but my issues with how it handles the input data.

    it has a struct that certain parameters of the input file is loaded into:

    Code:
    typedef struct DATA {
    DWORD                         Size;
    IMAGE_NT_HEADERS32    Headers;
    } _DATA; *PDATA
    etc, etc its a huge list.

    My problem lies in the fact that I need to change IMAGE_NT_HEADERS_32 to IMAGE_NT_HEADERS64 at runtime.

    That DATA struct gets called at least 110 times during runtime.

    Does anybody have any ideas how I might tackle this?

    Having a conditional statement repeated that many times seems ridiculous.

    Thanks in advance

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Runtime conditional varibles

    Are you using C++? If so, don't think in a C-like manner, but think in an object-oriented manner. The way this is usually done is to use inheritance and virtual functions. This would eventually mean that your DATA struct needs to be changed to handle this, as well as your code to read the data (you will need to read the data differently, no?).

    Also, I suggest you draw out a proper design before doing anything else.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jan 2014
    Posts
    8

    Re: Runtime conditional varibles

    Thanks for the reply, Yeah using C++ though typically I am a C programmer. Sort of been dropped in at the deep end.

    I am currently planning it out as we speak ha.

    I will look into those techniques thank you. Will let you know how I get one.

    Many Thanks
    Oli

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Runtime conditional varibles

    Quote Originally Posted by oj2014 View Post
    Thanks for the reply, Yeah using C++ though typically I am a C programmer.
    OK. Remember that coding in C++ requires a paradigm shift if you've been using C.

    Anyway, why not just write a separate program to process 64-bit executables? That would be far easier than changing any of the code.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jan 2014
    Posts
    8

    Re: Runtime conditional varibles

    It is a different kettle of fish ha.

    I wish I was able to but its been requested to be a single executable.

    Thanks
    Oli

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Runtime conditional varibles

    runtime dynamic (named) variables... that's pretty much a perfect match for an associative table (which you can easily achieve in C++ with a map), that's how almost all the scripting languages do it anyway.

    but trying to dynamically "change" a structure at runtime is an entirely different beast.

    You will either need to recompile the entire thing and templatize the 32/64 variance and end up with basically dual code paths.

    or you will need to create a class to abstract the difference and make all i/o to the NT Header structures pass through that class rather than directly.

    Either way wll involve touching every single line of code where you're not accessing the header structure.
    Last edited by OReubens; January 23rd, 2014 at 07:43 AM.

  7. #7
    Join Date
    Jan 2014
    Posts
    8

    Re: Runtime conditional varibles

    Currently I have made another instance of the project and making it work with just 64bit (there's a lot of work to done other than just making sure it loads correctly, so I have to modify almost all the calls anyway).

    Once I have 2 working version I will merge them together probably with dual code paths.

    Thanks for all your help

Tags for this Thread

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