Sign in to follow this  
deffer

How to determine if app uses MFC?

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
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
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
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
@Endurion:
fwrite() sets errno on failure. I'm afraid GetLastError() is not supposed to give you any information which is relative to a failure of fwrite.

Funny thing: in MS fwrite.c - the one which is shipped with VS7, lines 75 and 76:

/* do the read */
retval = _fwrite_lk(buffer, size, count, stream);


Regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this