Jump to content
  • Advertisement
Sign in to follow this  
deffer

How to determine if app uses MFC?

This topic is 4970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. So I'm writing an "ultimate" ;) wrapper for files. So there will be CFile for VC++ and FILE* for linux and others. I can make some predefines so the compiler knew what OS it is compiling my headers for. But I cannot be using CFile without using MFC, which I tried and failed to manually include for win-compiled project. So I could use CFile only for win apps, which explicite declared using MFC. It could look somewhat like that:
#if (defined USING_MSVCPP) && (defined "we declared using MFC" )

  typedef CFile CMyFile;

#else

  #include <stdio.h>
  class CMyFile
  {
  protected:
    FILE *m_f;
  public:
    // wrap FILE* operations into CFile-like methods.
  };

#endif


I'm searching formula for "we declared using MFC". Any ideas? /def

Share this post


Link to post
Share on other sites
Advertisement
You'd be better off to completely building CFile yourself than relying on MFC as you can use FILE* the same as in linux. Or put CFile inside a namespace.

I'm not sure about the define, you might check for __AFX_H__ as that gets set when including stdafx.h.

Share this post


Link to post
Share on other sites
Since you can use FILE functions on both Win32 and Linux, why not dispense with the conditional preprocessor commands?

Share this post


Link to post
Share on other sites
I knew I should have told that earlier...

I sustained serious injuries... ekhmmm.. I mean I had some problems with FILE* under win. That absolutely was not happening when using CFile. The symptoms:

FILE* f = fopen("data.smth", "some_options");

int len = 100200;
char* buf = allooooc_and_fill(len);

int lewWr = fwrite(f, buf, len);

// ...





And so lenWr was stopping after something like 700 bytes or so.
I really don't know what was happening, and stopped trying to find out after a few days.

Anyway, I switched to CFile and everything was ok.
So that's the deal. I you can cure that, then, by all means, do it.
/def

Share this post


Link to post
Share on other sites
It only happens whenI try to write a LARGE portion of data.
Or when I try to write SOME chunks of SMALL portions of data ;)

Please help me out with this...

Share this post


Link to post
Share on other sites
it's because fwrite may not write everything, check the return value and retry in a loop

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
fwrite's syntax is:
size_t fwrite( const void *buffer, size_t size, size_t count, FILE *stream );

So you should write

int lenWr = fwrite(buf, sizeof(char), len, f);

instead of

int lenWr = fwrite(f, buf, len);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!