1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[SDK] Using Microsoft Visual C++ 2005 Express Edition

Discussion in 'Civ4 - Modding Tutorials & Reference' started by Chazcon, Dec 13, 2006.

  1. Chazcon

    Chazcon Prince

    Joined:
    Feb 16, 2006
    Messages:
    475
    Location:
    Left Coast
    Beats me. Try going through all the steps again?
     
  2. Psychic_Llamas

    Psychic_Llamas Wizard in the Making

    Joined:
    Nov 25, 2005
    Messages:
    6,366
    Location:
    Western Australia
    Oh... bugger...
     
  3. rothn

    rothn Chieftain

    Joined:
    May 6, 2007
    Messages:
    76
    Location:
    Austin, TX
    I need a download for the Warlords CvGameCoreDLL. I have the vanilla, but I want to mod warlords.
     
  4. klokwerk

    klokwerk Prince

    Joined:
    Sep 3, 2006
    Messages:
    433
    Location:
    Paris
    Thanks a lot Chazcon. I work on BetterAI on Visual Studio 2005 now thanks to your thread. ;)
     
  5. Kalimakhus

    Kalimakhus Emperor

    Joined:
    May 8, 2007
    Messages:
    1,249
    Thanks a lot..

    I used the same with Visual Studio 2005 Professional and it worked like a dream:)
     
  6. Jean Elcard

    Jean Elcard The Flavournator

    Joined:
    Feb 26, 2006
    Messages:
    1,008
    Location:
    Leipzig, Germany
    @Chazcon: I think you should update your first post. I ran into trouble using the provided makefile with Beyond the Sword source code. There is a new file (CyPlayerPythonInterface2.cpp) you need to integrate into the make file to make the linking process work for it. Otherwise you will get an error telling you something about an unresolved external symbol and stuff.

    I've attached my modified version of the makefile for those who want it. If you are going to use it, don't forget repeat step 6: Changing the paths to your installation of the Microsoft Platform SDK and the Visual C++ Toolkit.
     

    Attached Files:

  7. Death900

    Death900 Chieftain

    Joined:
    Jul 31, 2007
    Messages:
    35
    Hey guys, i got some tips for you if you want to try debugging.

    Now, if you want to debug the DLL while you're testing it in Civ4, you must be able to build a debug release instead of a final release. You can always try with the final release, but i'm not sure this will work since i'm always working in debug release (don't worry, it doesn't corrupt anything).

    1- get your DLL compiling and be able to run it in Civ4. If you can't run Civ4 with the modified DLL, don't go farther. Get back into VS and make that DLL work.

    2- Start Civ4 with the modified DLL.

    3- Once Civ4 has finished loading, meaning waiting for you to make an action in the start-up menu, get back into VS.

    4- In the menu bar, click on - Debug - then - Attach to process -

    5- A window appears listing all processes (application) currently running on your computer.

    6- Find the process Civilization4.exe (Vanilla) or Civilization4Warlords.exe (Warlords). For BtS, i have no idea, but it should look like Civilization4"Something".exe where something could be BtS or Beyond or anything else related to BtS. This name is decided by Firaxis btw.

    7- Click - Ok - (or it may be - Attach -, i don't have VS installed at home for now)

    8- You're now ready to use the debugger in VS 2005!


    The two things that i see that could possibly make this procedure not work is:
    1- Might not work with a final release. You'll have to test it, because i'm not sure.
    2- You don't know how to use the debugger in VS. There should be some tutorial around the web.


    I have not tried any of it since my computer got formated and I don't have the time to download all that is required, but it's the standard procedure if you want to debug any DLL that a program is using. I had to do that for my 2007 year project at school (no, not on Civ4).

    I'll get the tools as soon as i can and test that myself, but until then you can always ask question here and i'll try to answer.
     
  8. Kalimakhus

    Kalimakhus Emperor

    Joined:
    May 8, 2007
    Messages:
    1,249
    Good advice Death900.. allow me to add some.
    DLL projects in VS have a property that indicates the exe file that is supposed to use the dll. If you set this to whatever civ4 exe you can then use the run command of VS to launch civ4 with the DLL (without even replacing the original dll).

    The problem with final release is not that it won't work at all. It is supposed to work but it will have very little debug data so won't be useful for debugging.

    For people who may need to know how to enable debugging. you need to add another build configuration and use command lines that has the Debug build of the make file in place of Final_Release.

    For using the debugger VC++ express comes with enough documentation to explain it.

    Happy coding folks.
     
  9. Chazcon

    Chazcon Prince

    Joined:
    Feb 16, 2006
    Messages:
    475
    Location:
    Left Coast
    Hey all,

    I haven't played a game of Civ in nearly a year, nor done any modding. This procedure was only for Vanilla and Warlords, no idea how it works with BtS. I leave up to the community to modify this for BtS. Feel free to add or make changes of course, please make sure you post good, tested and verified information. Have fun modding!

    -c
     
  10. Death900

    Death900 Chieftain

    Joined:
    Jul 31, 2007
    Messages:
    35
    Thanks for the tip. We're always learning!
     
  11. LtChambers

    LtChambers Chieftain

    Joined:
    Jun 24, 2007
    Messages:
    19
    Is the 2003 toolkit still necessary for compiling the DLL from BtS? Is the Civ4.exe using different system library versions or something than 2005 and that's what causes my crashes? I can get the DLL to build just fine but it crashes when I go to start a game (single player->custom game->crash).

    I wonder why Firaxis doesn't release a version of Civ4 using MSVC8? I saw a few for loop conformance bugs in the DLL code, took only a few minutes to fix - maybe the standards adherence in the main exe is much worse and so upgrading to MSVC8 isn't feasible?
     
  12. Kalimakhus

    Kalimakhus Emperor

    Joined:
    May 8, 2007
    Messages:
    1,249
    Yes BTS still uses the same libraries as civ4 and warlords. Linking the DLL with the libraries that come with VS2005 will sure cause the game to crash when using this DLL.

    It is possible for the people of Firaxis to rebuild the exe against new libraries, but then they must rebuild every single DLL the games uses. The patch they would need to release will be quite large. All that besides it is quite a headache. Now why should miss with something that is working already? Also many modders are happily using the VS2003 toolkit. There are many free IDEs that will simply work with the tool kit. Code Blocks, Eclipse, and others. Also the free VC++ 2005 Express can work with it.
     
  13. Gunner

    Gunner Emperor

    Joined:
    Aug 21, 2004
    Messages:
    1,389
    Location:
    Goochland, VA
    Forgive my ignorance, but what are the advantages of using the method outlined here with Visual C++ 2005 over the method outlined by Kael's post with Codeblocks for Civ4?
     
  14. Kalimakhus

    Kalimakhus Emperor

    Joined:
    May 8, 2007
    Messages:
    1,249
    Each method has its advantages and drawbacks. It depends on what you think is more important for you. This method allows you to use a very sophisticated IDE which helps a lot in editing code. It has powerful tools for navigating code. For instance when you like to find out where a specific function is used so if you are goinf to change it you can go every where it is called to change the call. Also VS has a very good debugger, according to my experience CodeBlocks debugging capabilities are quite limited.

    One advantage for code blocks is that it will maintain the makefile for you. You can add new code files from within the IDE and the makefile and dependencies are updated properly. With VS it has to be done manually. Also the current makefile for nMake (that used by VS) doesn't account for dependencies on header files so if you change a header file the cpp files that depend on it won't be recompiled if you build the project. You have to go to the intermediate files folder and clean it then do a full rebuild. However if someone has the time he can fix the makefile.
     
  15. Déja

    Déja Beyond the Mod

    Joined:
    Dec 19, 2005
    Messages:
    353
    I love that I posted about this exact method (along with a rudimentary makefile, http://forums.civfanatics.com/showthread.php?t=189651) nearly two full months before this thread was started, but that my name is consipcuously absent from the credits.

    Much obliged, gents. Much obliged, indeed.
     
  16. Kalimakhus

    Kalimakhus Emperor

    Joined:
    May 8, 2007
    Messages:
    1,249
    @Deja
    I am sure Chazcon either haven't seen your thread or at least didn't depend on it to come up with the instructions he posted here.

    I downloaded your makefile and went through it. It is an excellent work. First it adds header files dependencies which will get obj files depending on them rebuilt whenever the headers are changed. Second it uses windows del command to clean intermediate files so clean and rebuild options actually work.

    The difference between the two methods is that your depend on having VS2003 installed while this one requires the VS2003 toolkit instead. It is quite a minor difference. In fact I will adjust your makefile to reference the folders of the VS2003 toolkit and the PSDK so that I can use it.

    Thanks a lot for your effort. I am sorry it wasn't properly recognized.
     
  17. Déja

    Déja Beyond the Mod

    Joined:
    Dec 19, 2005
    Messages:
    353
    In case you haven't done it yet, I've attached an updated makefile that is tailored for BTS (3.03) and which now uses the toolkit 2003 and platform sdk.

    All of the dependencies should still be current.
     

    Attached Files:

  18. Kalimakhus

    Kalimakhus Emperor

    Joined:
    May 8, 2007
    Messages:
    1,249
    Thanks a lot this is really helpful.
     
  19. Death900

    Death900 Chieftain

    Joined:
    Jul 31, 2007
    Messages:
    35
    I went through the makefile and it's just so beautiful, i'm in awe. totally. Makefile is something i'd really like to understand, so, if you don't mind, i'll ask 2 or 3 questions about things i'm not sure:

    1- on line 327, the LINKFINAL flag: why is the PDB used twice? And, related, what PDB stands for? Project DataBase?

    2- At the beginning of the file, you tell us that using the DEBUGBUILD flag (i.e. DEBUGBUILD=_DEBUG for example) will output the correct dll to CvGameCoreDLL_DEBUG.dll, which is correct according to line 408 with the definition of the OUTFILE. But why then on CPPDEBUG and LINKDEBUG you don't use DEBUGBUILD to specify the output file, and instead hardcode CvGameCoreDLL_DEBUG.dll on line 331?

    3- How can you declare two flags with the same name, such as CPPFLAGS and LINKFLAGS (used at line 318 and 379 for example for CPPFLAGS)? How does Make know which one to use first, since you can declare FLAGS after they are actually used, such as OUTDIR?

    4- Line 418: what's the difference between using echo and @echo? I think is some base in scripting, but i have no clue what's the difference ^^

    thanks in advance ^^

    p.s. I thought those question were good for general purpose if other people wanted to know. If you feel it's better to answer me by mail, then you are free to do so.
     
  20. Déja

    Déja Beyond the Mod

    Joined:
    Dec 19, 2005
    Messages:
    353
    Well, I never claimed that it was perfect :)

    1 - This is just a typo, and the second reference can safely be removed. PDB stands for program database. They're part of VC++'s incremental linking process.

    2 - I added the debug macro as an afterthought. I simply forgot to go back and use it in the other macros.

    3 - Makefile macros are defined from the top of the file down. So the first time, CPPFLAGS is set to a value. Then the second time, it overwrites the value of CPPFLAGS. However, the initial $(CPPFLAGS) macro is expanded before its overwritten, so those two statements actually prepend additional flags to the macro.

    4 - Using @ before a command means that the command won't be shown in the output. Consider the following two examples:

    The code:
    Code:
    echo: echo Hello World
    Would look like this:
    Code:
    >nmake echo
    echo Hello World
    Hello World
    
    While the code:
    Code:
    echo: @echo Hello World
    Would look like this:
    Code:
    >nmake echo
    Hello World
    


    I hope that these answers help. If you have any other questions, don't hesitate to ask.
     

Share This Page