DirectX and MFC

This is a discussion on DirectX and MFC within the Game Programming forums, part of the General Programming Boards category; Is there a way to use only the utility classes in MFC w/o having to include every portion of MFC? ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596

    DirectX and MFC

    Is there a way to use only the utility classes in MFC w/o having to include every portion of MFC?

    I tried #include <afxwin.h> but got an error stating that MFC programs should not include "windows.h". I'm assuming since "d3dx9.h" includes "windows.h" this is where the error is originating.

    I desperately need CString access so I can load data from disk that was written by my MFC game utilities. Personally I don't feel like converting from std::string to CString just for the sake of gaining string functionality.

    Most of the Windows controls return LPWSTR which is no where near a char * and converting from char * to LPWSTR, LPCSTR, and LPCTSTR is a nightmare. Most of the C runtime functions want a const char * instead of a TCHAR * or any of the others mentioned.

    Where the heck did all these string types come from?

    From: Bubba
    Location: String hell.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Quote Originally Posted by Bubba
    Most of the Windows controls return LPWSTR which is no where near a char * and converting from char * to LPWSTR, LPCSTR, and LPCTSTR is a nightmare. Most of the C runtime functions want a const char * instead of a TCHAR * or any of the others mentioned.
    Are you aware of the following functions?

    size_t mbstowcs( /*snipped*/ ); // ansi

    int MultiByteToWideChar( /*snipped*/ ); // win32

    Sorry, can't answer your MFC question for you. I'm suprised you haven't moved on to C# for your tools.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    No I was not aware of that function but I'll check it out. But it doesn't make sense to put char arrays in my structures forcing myself to convert to CString in MFC and vice versa for tool to engine.

    I haven't used C# b/c of the CLI garbage. Currently I'm still plodding through a book concerning C++ and CLI and I may take a stab at C# eventually, but for now MFC does just fine for providing a foundation on which to build small Win32 game tools.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Quote Originally Posted by Bubba
    No I was not aware of that function but I'll check it out. But it doesn't make sense to put char arrays in my structures forcing myself to convert to CString in MFC and vice versa for tool to engine.

    I haven't used C# b/c of the CLI garbage. Currently I'm still plodding through a book concerning C++ and CLI and I may take a stab at C# eventually, but for now MFC does just fine for providing a foundation on which to build small Win32 game tools.
    So, is there some solution that involves writing out your data in a different format so that you don't need CString to load it?
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Not that I can think of right off hand. I'll just stick with the bloat of using MFC until I can get passed the issue. Since I'm using MFC, listboxes, list controls, edit controls, etc, etc, all have overloads which return strings as CString instead of just returning them as the Win32 API does.

    CString is very nice, however, it lacks some features such as being able to convert from string to numeric value in which case you must do this manually.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    This is stupid. I cannot use the utility classes because MFC doesn't want Windows.h included. D3DX9.H includes Windows.h so how the hell can I get around it. I've looked all over the net and found that most people attempting to do this either cannot type or simply have not yet mastered the art of speaking English.

    Summary of problems:

    1. One file needs to CString and CArchive to access the data on the disk.
    2. CString and CArchive are in afxwin.h
    3. Cannot include afxwin.h inside of said file because Windows.h is already defined.
    4. Windows.h is not included in anywhere in the file that needs MFC nor does it include any other file that should include Windows.h . So why the heck is Windows.h already included?


    I fixed it by using pre-compiled headers. Don't ask me how, it just works for now. The header includes d3dx9.h after all the MFC stuff which is why I "think" it works. Whatever.
    Last edited by VirtualAce; 08-29-2006 at 04:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC, WTL or .NET?
    By microchip in forum C++ Programming
    Replies: 7
    Last Post: 11-07-2005, 03:14 PM
  2. MS Visual C++ Link Error with DirectX
    By Maddog42 in forum C++ Programming
    Replies: 4
    Last Post: 09-01-2004, 09:33 PM
  3. DirectX vs. OpenGL
    By bdiamond in forum Game Programming
    Replies: 17
    Last Post: 08-17-2004, 09:08 PM
  4. hWnd in MFC
    By WebmasterMattD in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2003, 08:06 AM
  5. MFC :: Multiple File Extension Support
    By SyntaxBubble in forum Windows Programming
    Replies: 0
    Last Post: 06-02-2003, 10:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21