resolving MFC name conflicts
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: resolving MFC name conflicts

Hybrid View

  1. #1
    Join Date
    Aug 2002
    Posts
    212

    resolving MFC name conflicts

    I have been coding a game engine for a while now, the core part of it is in a DLL file. I have started coding the editor for it, and I'm trying to use MFC. the problem is, I have classes named CObject, and CArchive. The first thing I tried to do to fix this is include MFC into a namespace, but I seriously doubted it would work:

    namespace MFC
    {
    // MFC includes here, just the classwizard generated ones
    };
    then use fully qualified MFC names for everything. but, surpise suprise, this didn't work. many hundreds of include file errors, lots of 'name' undefined (particularly time_t), and 'name' is not a member of 'Global namespace' (resulting from things like ::GetWindowTextA in the MFC headers).

    I could put my engine in a namespace, but that would be a LOT of work (300 files +), so this is my last resort. what are my options here?

  2. #2
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    It is not clear to me what you are asking. I don't understand what you are using a namespace for. Perhaps you need to explain what you mean by "game engine". However I am not even sure if you are using a namespace for the game engine or for just the editor.

    My guess is that a good solution would be Automation or an ActiveX control, but I can understand avoiding solutions such as that. It takes a lot of time to learn that stuff.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  3. #3
    Join Date
    Aug 2002
    Posts
    212
    I have a game engine DLL, which has all the game core stuff in it. I'm trying to make an editor which links to the engine and uses it to render its data into the viewports in my editor. there are two applications using the engine, the editor, and the game program. the game program works fine, but when I try to include the engine headers and use it in the editor, I get name conflicts between classes in my DLL headers and MFC's headers (CObject and CArchive). so I tried to include MFC into a namespace to resolve the conflict.

  4. #4
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    Why don't you just rename the classes in your game engine or do
    the proper thing and put the code for your engine in a namespace.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  5. #5
    Join Date
    Apr 1999
    Posts
    27,434
    Originally posted by Kibble
    I get name conflicts between classes in my DLL headers and MFC's headers (CObject and CArchive). so I tried to include MFC into a namespace to resolve the conflict.
    First (as souldog pointed out), either change your names or place your code in a namespace. As a matter of fact, it would be beneficial if you did place your names in a namespace and change the names. Changing the names to CGameObject, or CGameArchive is a much better choice than CObject or CArchive. If you have many source files, usage of a good editor (one that has multiple file "search and replace") makes changing names of classes very easy.

    Second, placing MFC names in a namespace will not work at link-time. The linker will be looking for "CObject" for the MFC names, but will only find "MFC::CObject". Then you will get "unresolved external" errors. In other words, you're wasting your time by placing MFC in a namespace, unless you want to rebuild the entire MFC library with the MFC namespace.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; February 22nd, 2004 at 04:25 PM.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,434

    Re: resolving MFC name conflicts

    Originally posted by Kibble
    I could put my engine in a namespace, but that would be a LOT of work (300 files +), so this is my last resort. what are my options here?
    Again, a good editor makes this less than a day's work, maybe less than an hour. There are many that do file "search and replace" (Multi-Edit, SlickEdit, for example).

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815
    As an alternative to using another editor, also have a look at the articles section - there are add-ins and macros like this one which add search & replace across multiple files to VisualStudio.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center