-
February 22nd, 2004, 01:29 PM
#1
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?
-
February 22nd, 2004, 02:39 PM
#2
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.
-
February 22nd, 2004, 02:47 PM
#3
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.
-
February 22nd, 2004, 04:34 PM
#4
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."
-
February 22nd, 2004, 05:20 PM
#5
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 05:25 PM.
-
February 22nd, 2004, 05:24 PM
#6
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
-
February 22nd, 2004, 06:36 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|