0

I'm sorry if this questions have been asked before, but could not find an appropriate answer here. I need a little help with Visual Studio regular expressions to modify source code. I have source code that loads textures from files. I have lots of line like these.

D3DXCreateTextureFromFileA(pDevice , chFileName , &pTexture) ;
D3DXCreateTextureFromFileA(pDevice , pAttrib->Value() , &pd3dTexture) ;

I need to define a constant and based on that to load textures from a custom format. I want this

   D3DXCreateTextureFromFileA(pDevice , chFileName , &pTexture) ;

to become this

 #ifdef LOAD_TEXTURES_FROM_CF

    CreateTextureFromResourceFile((pDevice , chFileName , &pTexture) ;

 #else

    D3DXCreateTextureFromFileA(pDevice , chFileName , &pTexture) ;

 #endif 

How can I achieve this with Visual Studio regular expressions ? Thank you in advance.

1
  • Why don't you want the macro solution? It works well in your case Commented Aug 6, 2012 at 8:41

1 Answer 1

2

There's no need for regular expression replaces (I would even advice against doing so). Instead of duplicating your new code, just create another macro:

#ifdef LOAD_TEXTURES_FROM_CF
#define CreateTextureFromFile(a, b, c) CreateTextureFromResourceFile((a), (b), (c))
#else
#define CreateTextureFromFile(a, b, c) D3DXCreateTextureFromFileA((a), (b), (c))
#endif

Then just replace all previous occurances of D3DXCreateTextureFromFileA with CreateTextureFromFile and you should be fine.

Sign up to request clarification or add additional context in comments.

2 Comments

Just to add: I'd actually think about using a tiny wrapper function instead of static code/a macro. That way you could even toggle loading at runtime, not just compile time.
Thanks for both of you. I will use a macro as you proposed. Just out of curiosity - how a regex solution will look like ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.