DLL/C++ tutorial discussion thread

@whoward69 can you please link me a tutorial how to compile your DLL ?
The one linked in your signature (from 2012) only talks about the orignial DLL and it seems the first post is not up to date and there are thousands of posts afterwards from you and other modders discovering the dll. While this is an interesting journey, I would prefer a direct tutorial step by step.

Is it necessary to have Civ5 or the SDK installed at the machine I'm compiling the dll?

Eg. I opened your "CvGameCoreDLL.vs2015.sln" project with Visual Studio 2019 trial version and directly received these errors (and have no clue how to deal with them):
Code:
C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj : warning  : The build tools for v90 cannot be found. Install v90 to build using the v90 build tools.

C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj : warning  : Platform 'Win32' referenced in the project file 'CvGameCoreDLL_Expansion2' cannot be found.

error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
error : Designtime build failed for project 'C:\Users\User\Desktop\DLL-VMC-master_original\CvGameCoreDLL_Expansion2\CvGameCoreDLL_Expansion2.vs2010.vcxproj' configuration 'Mod|Win32'. IntelliSense might be unavailable.
   Set environment variable TRACEDESIGNTIME = true and restart Visual Studio to investigate.
 
@whoward69 is there also a tutorial how to debug crashes?
I already had 2 crashes within short time from your original v94 dll (edit: it is a vanilla bug, crash when founding a pantheon, but not have a capital)

About debuggin in community patch github is written:
How do I debug this
Use Visual Studio to build the DEBUG configuration of the project (as opposed to the RELEASE config)
Place the generated dll and pdb file (from the BuildOutput folder) in the mods folder (Community Patch Core), replacing the dll there.
Start CiV and load the mod
In the Visual Studio debugger menu select "Attach to process" and pick Civilization5.exe
Start the game. In case it crashes the debugger will show you where and why. It may be you only see an address, no code. In that case the crash is outside of the game core dll and we're out of luck.
You can also set (conditional) breakpoints in the code to inspect the value of interesting variables.
But this does not really help a newbie like me :D No clue where should I build what and where to find a debug configuration or the release config (might also be related to that english is not my native and I really dont understand that sentence). And is this generated dll a seperate one, or is it basically the same dll, but with debugging enabled? If the last, has your shipped dll already debugging enabled? And would the steps for debugging your dll be the same?
Would be very great if you have a step by step guide, I'm really lost here.

edit:
btw your picknmix website is up again, but your "mod utilities and tutorials" are not working, I tried to see if there is something written about debugging http://www.picknmixmods.com/parts/utilities.html#debug but it only shows me a white page with the categories on the left.

edit2: found a guide: https://forums.civfanatics.com/threads/a-guide-to-debugging-crashes-with-a-custom-dll.506328/ , will try it now.
 
Last edited:
@whoward69 :
Your tutorial explains why we use "#if defined("Mod_XY")" in the dll code. But it does not explain the difference to the default code "if (Mod_XY)".
For example for your radaring fix:

#if defined(MOD_BUGFIX_RADARING)
if (MOD_BUGFIX_RADARING) {...

Why these 2 checks? Why isnt the first one enough, or the last one?
And why:
#define MOD_BUGFIX_RADARING gCustomMods.isBUGFIX_RADARING()

Ok, lets try it logically:
"if defined" is only checking if something is defined, not what value it is. So even if we do
#define MOD_BUGFIX_RADARING (false)
the first line will be executed?
So the "#if defined" is really only to be able to fast "remove" code for testing purpose. And when I want code to be actived by custommodptions, then I need:
if (MOD_BUGFIX_RADARING) {...

Ok... I think I understood, I just wondered why sometimes we have this double line (defined and chekcing the value), while other times we only check "defined" and not the value. I would expect that we should always use the double lines, to only alter the dll code if forced by a custom mod.

(I will send this post in case someone else also wonders in the future)


edit:
Ah one last question I was not able to answer myself yet:
When using:
#if defined(...)
how does the code know which one is closed with "#endif", if we nested these?
Like:
Code:
#if defined(A)
// code...
#if defined(B)
// code...
#endif
//code...
#endif
which one got closed now with the first #endif?
edit3: ok, it seems always the inner part is closed first, so LIFO.

edit2:
I tried to add a new event, but for whatever reason
if (MOD_EVENTS_VISCOUNT_CHANGED) is always false. I added it to CustomMod.h like this:
#define MOD_EVENTS_VISCOUNT_CHANGED gCustomMods.isEVENTS_VISCOUNT_CHANGED()

and I' sure the xml with
<CustomModOptions>
<Update>
<Where Name="EVENTS_VISCOUNT_CHANGED"/>
<Set Value="1"/>
</Update>
</CustomModOptions>
is properly loaded after the dll mod.

I also have the MOD_OPT_DECL and MOD_OPT_CACHE things, although I dont know what they do...
I tested "#define MOD_EVENTS_VISCOUNT_CHANGED (true)", then everything works as intended.
hm... this is the only problem left, no clue how to use those custommodoptions...
 
Last edited:
Top Bottom