0

I've been working on this project for a while now, its a legacy DLL, my part is to adapt it to work with a new version of a library.

I added a definition to the build defined in the Properties / C/C++ / Preprocessor / Preprocessor Definitions

The definition I added is called CLSOPENLDV and the line looks like this:

    CLSOPENLDV;SP_DEBUG;WIN32;_WINDOWS;_USRDLL;

This use to work and in my code I use the definition to test and switch in and out code:

    #pragma once

    #if defined(CLSOPENLDV) && !defined(CLSOPENLDV_H)
        #define CLSOPENLDV_H
        #pragma comment(lib, "ldv32")
        ...
    #endif

This all use to work, last week I had to switch back to the original build which was a simple case of removing the constant from the properties, however now I want to get back to where I was and for some reason I can't, even though the constant is back in the properties, the preprocessor is not being recognised by the build, the code is grayed in the above #if defined test and I'm really not sure why?

Could it be something to do with pre-compiled headers (pch)?

[Edit] Actually the problem is not exclusive to CLSOPENLDV, the other definition SP_DEBUG isn't making it through to the build either and none of the debug statements included by this definition are enabled.

[Edit2] I've set break points in the debugger and its just not getting to those either, this was all working something is fundamentally broken or disabled.

[Edit3] Its a more fundamental problem than I first thought I cannot debug the project at all...I attach to the Process, but none of my breakpoints are ever hit. I am seeing lots of First-change exceptions in the Output pane but no clue as to where to look as it just gives addresses.

[Edit4] Still trying to figure out whats going on, below is a dump when running the DLL, the only modification I made was to Debug / Exceptions / C++ Exceptions, I checked the Thrown check box, so it now halts with an exception dialog on the first exception:

'Edwards.Scada.AgentService.exe': Loaded 'C:\Program Files\Edwards\Agent Service\Edwards.Scada.AgentService.exe', Binary was not built with debug information. 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\ntdll.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\mscoree.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\kernel32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\KernelBase.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\apphelp.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\apppatch\AcLayers.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\msvcrt.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\user32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\gdi32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\shell32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\windows.storage.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\combase.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\rpcrt4.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\bcryptprimitives.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\advapi32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\sechost.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\shlwapi.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\kernel.appcore.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\SHCore.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\powrprof.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\profapi.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\oleaut32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\setupapi.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\mpr.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\sfc.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\winspool.drv' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\bcrypt.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\sfc_os.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\version.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\msvcr120_clr0400.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\6457de2c799b00351885b50b15ee8582\mscorlib.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\ole32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System\d07dc4c7e25d0f1f688e96c3651ccbe3\System.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Serv759bfb78#\a8b2254177d41e0ba6c21c1620ad7d05\System.ServiceProcess.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\cryptsp.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\rsaenh.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\cryptbase.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Core\c3edb3947295bb8762d800c029930c15\System.Core.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Configuration\2817463703ac432e3bbf54586b3d6b8b\System.Configuration.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xml\9d354ba04e2414d763e9dea657f52fff\System.Xml.ni.dll' The thread 'Win32 Thread' (0x2084) has exited with code 0 (0x0). 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x4890000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x48b0000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Unloaded 'ImageAtBase0x4890000' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Data\e6902bef5b9f4110e975dc92ff87e71d\System.Data.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\Microsoft.NET\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\ws2_32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\crypt32.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\msasn1.dll' First-chance exception at 0x015e401a in Edwards.Scada.AgentService.exe: 0xC0000005: Access violation reading location 0x00000000. 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x4950000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x4960000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Unloaded 'ImageAtBase0x4950000' The thread 'Win32 Thread' (0x25d4) has exited with code 0 (0x0). The thread 'Win32 Thread' (0x13d0) has exited with code 0 (0x0). 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x50a0000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x50f0000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Unloaded 'ImageAtBase0x50a0000' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.ServiceModel\dab9738fa2ffd706ad918f4854011580\System.ServiceModel.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Runt73a1fc9d#\0003c5ec8500bfe2571ef6b3768e3327\System.Runtime.Remoting.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\mswsock.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\NapiNSP.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\pnrpnsp.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\nlaapi.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\winrnr.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\dnsapi.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\nsi.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\rasadhlp.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\IPHLPAPI.DLL' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\FWPUCLNT.DLL' 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x4970000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x50e0000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Unloaded 'ImageAtBase0x4970000' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\SMDiagnostics\5415baffc9d9111d58c8fe05d4e50c8a\SMDiagnostics.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Servd1dec626#\71634b20929e9a6ed53d7acbffa0b93d\System.ServiceModel.Internals.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x4970000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x5220000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Unloaded 'ImageAtBase0x4970000' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Runteb92aa12#\dd6060246740eddfed31aeed179fb81f\System.Runtime.Serialization.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Web.Services\1150e9c52ad5088258dafbd0fce2ae07\System.Web.Services.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x5230000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Loaded 'ImageAtBase0x5280000', No symbols loaded. 'Edwards.Scada.AgentService.exe': Unloaded 'ImageAtBase0x5230000' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Serv14259fd9#\f8ae5cc80236c0593f67d76495fccd46\System.ServiceModel.Activities.ni.dll' First-chance exception at 0x74372ea2 in Edwards.Scada.AgentService.exe: 0xE0434352: 0xe0434352. 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.IdentityModel\43572b8748b627fcbeb032b3656f5810\System.IdentityModel.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Net.Http\f37829993e81bb8c2121b954fda8e480\System.Net.Http.ni.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\httpapi.dll' 'Edwards.Scada.AgentService.exe': Loaded 'C:\Windows\System32\psapi.dll' First-chance exception at 0x74372ea2 in Edwards.Scada.AgentService.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x053dc524..

The first line is very confusing, I've checked the project build several times, it is built for debug.

[Another edit] I've taken the project that was working yesterday from SVN and having completely deleted the existing project, extracted the copy from SVN. I've compiled this and tested, it now crashes where as yesterday it worked, I've re-installed MSVC, installed the service pack and taken a working project and built, but now it doesn't debug and crashes.

Why? What else can I try?

Here is the content of stdafx.h:

#include "stdafx.h"

#ifdef _ATL_STATIC_REGISTRY
    #include <statreg.h>
    #include <statreg.cpp>
#endif

#include <atlimpl.cpp>

Here is the command line from C/C++:

    /Od 
    /I "..\..\..\Legacy Common Files" 
    /I "..\nodetalk2\include"
    /I "..\..\..\..\..\Include" 
    /D "CLSOPENLDV"
    /D "SP_DEBUG"
    /D "WIN32"
    /D "_WINDOWS"
    /D "_USRDLL"
    /D "_VC80_UPGRADE=0x0600"
    /D "_WINDLL" 
    /D "_MBCS"
    /FD /EHsc /MDd /Yc"stdafx.h" 
    /Fp".\Debug/FsLonPlayer.pch"
    /Fo".\Debug/" 
    /Fd".\Debug/" 
    /W4 /nologo /c /Wp64 /Zi /TP /errorReport:prompt

[Edit] The top line of the output is a red herring, it actually is referring to the EXE that this DLL is part of, the DLL is compiled for debug, however having said that it still does not explain why yesterday it was working and I could see source code in the debugger and stop at breakpoints, today I cannot.

SPlatten
  • 5,334
  • 11
  • 57
  • 128
  • Could this be something to do with pre-compiled headers (pch)? Seems unlikely, but to test this theory simply turn off pch in your project. – john Jul 17 '18 at 05:41
  • @john, I wish it was that simple, there are a lot of changes to make in the source as a result of a lot of build errors with the pch turned off. – SPlatten Jul 17 '18 at 05:43
  • Sounds like a badly structured project then. If implemented properly pch should be transparent. Maybe your real problem is there. – john Jul 17 '18 at 05:45
  • This project is over ten years old, my involvement in it is the last 3 months, it is what it is... – SPlatten Jul 17 '18 at 05:47
  • Well sure, but if you fix the problem with pch, so you can turn it on and off at will then maybe this problem will also disappear. Anyway it's hard to advise when I can't see the project. – john Jul 17 '18 at 05:50
  • One possible cause may be that if you have several configurations of your project, e.g. `Debug` and `Release`, it's possible to set independent properties for each configuration. So if you added the `-D` option back in to `Release` only, and then set the actual configuration in the IDE to `Debug`, you could possibly see the behavior you're experiencing. – dgnuff Jul 17 '18 at 05:57
  • @dgnuff, thank you, yes I've consider this, there are multiple configurations and I'm very careful to update and choose the correct configuration. – SPlatten Jul 17 '18 at 05:58
  • If you go to the properties for a `.CPP` file that is experiencing this, what shows there in the `Preprocessor` tab, and while you're at it, is the option visible in the `Command Line` tab at the very bottom? Probably not, but it does no harm to ask. – dgnuff Jul 17 '18 at 06:00
  • In response to @john's comments, if it is a PCH issue, you can force a rebuild of the PCH files by cleaning the project and then building it again. – dgnuff Jul 17 '18 at 06:03
  • @dgnuff, thank you, done that too, many times, I'm not 100% convinced it is a PCH issue, just clutching at straws... – SPlatten Jul 17 '18 at 06:12
  • Did you check CLSOPENLDV_H? Remove it from #if condition and see if it works. – zdf Jul 17 '18 at 06:18
  • @ZDF, please explain, what do you mean? – SPlatten Jul 17 '18 at 06:19
  • Replace #if... line with #if defined(CLSOPENLDV) – zdf Jul 17 '18 at 06:23
  • @ZDF, please clarify, you are not making sense, this is exactly what I already have. – SPlatten Jul 17 '18 at 06:24
  • Your current if contrition is #if defined(CLSOPENLDV) && !defined(CLSOPENLDV_H). Replace it with #if defined(CLSOPENLDV) – zdf Jul 17 '18 at 06:29
  • @SPlatten When you set a breakpoint, it shows as a full red dot when the program's not running. What happens if you set one, hit F10 to step into `main()` / `WinMain()` and then look at the breakpoint. Is it still a solid dot, or has it become an outline? – dgnuff Jul 17 '18 at 06:58
  • @dgnuff, No, the breakpoint is set as a red circle not filled, the project is a dll, I have to attach to the process in the debugger, I have a breakpoint in DllMain, it doesn't get there. – SPlatten Jul 17 '18 at 07:00
  • You surely need to take what the debugger tells you more seriously. A very simple explanation is that you have the Release configuration active. Switch back to the Debug configuration. And fix the problem, you probably forgot to also define the macro in the Release configuration. Standard mishap. Not having SP_DEBUG defined in Release ought to be normal. Another detail that is bound to byte you in the rear end is that the build directory does not include the configuration name like it normally does. So the release build is apt to overwrite the debug build. – Hans Passant Jul 17 '18 at 12:12
  • @HansPassant, thats way to obvious and I would love to agree, however it isn't true, In the tool bar I 100% have Debug selected, yet when I run it displays those warnings. Also, SP_DEBUG is my own switch, nothing to do with debug, just displays more verbose information while its present. – SPlatten Jul 17 '18 at 12:15
  • Well, that's why I thought it was a good idea to also note that the release build could overwrite the debug build. Use Build > Rebuild. And do check the preprocessor identifiers for the Release configuration. – Hans Passant Jul 17 '18 at 12:20

2 Answers2

0

Need to move this to an answer for the formatting. I think @ZDF is suggesting you replace the line:

#if defined(CLSOPENLDV) && !defined(CLSOPENLDV_H)

with

#if defined(CLSOPENLDV)

While I'm at it, this next suggestion may not be a long term solution, but it should provide a data point to help figure what's gone wrong. Create a new header file, with just this line in it:

#define CLSOPENLDV

Don't use #include to include it anywhere, instead open the project properties, got to C/C++ -> Advanced and enter the full path to your new header file in the Forced Include File field. Give that a try and see what happens.

Also, another (possibly stupid) idea. Can you pull a version of the project files from your SCM repo as was a week and a half ago when you had this working?

-- Edit --

Just saw your edit to your original post. Did you check the properties for an actual .cpp file, you can do this very easily by viewing the properties for the project itself, verifying that the two definitions are present, and then just clicking on a .cpp file in Solution Explorer. That'll take you to the same property page for the file itself.

I'm highly curious to know what shows there.

dgnuff
  • 3,195
  • 2
  • 18
  • 32
  • I'm really not with you, changing the #if defined condition doesn't help, the code inside the block is still grayed, which tells me that for some reason the definition "CLSOPENLDV" isn't making it through. – SPlatten Jul 17 '18 at 06:32
  • 1
    @SPlatten intellisense is not always working correctly. You'll have to compile. – zdf Jul 17 '18 at 06:33
  • @ZDF, thats what I am doing. – SPlatten Jul 17 '18 at 06:34
  • @SPlatten Even though it fails, it's a data point that helps. We now know for sure that `CLSOPENLDV` has gone M.I.A. – dgnuff Jul 17 '18 at 06:35
  • It's so frustrating, I'm getting errors for files in the C library that are not part of my build: error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file. – SPlatten Jul 17 '18 at 06:36
  • @dgnuff, agreed, whats going on? – SPlatten Jul 17 '18 at 06:37
  • @SPlatten Hmmmm. Very intersting about the `/Ycstdafx.h` thing. You've noted that your project uses PCH files, what's the name of the "pch header" file? By default VS sets it to `stdafx.h` but it's not that uncommon to change it to something else: I've seen both `common.h` and `pch.h` in my time. – dgnuff Jul 17 '18 at 06:53
  • @dgnuff, this project is a mess, this project is part of a bigger project where projects higher up the folder tree, make reference to the stdafx.h using #include "stdafx.h" but the file isn't in the same folder...I'm amazed at how it ever worked? The pch header is stdafx.h – SPlatten Jul 17 '18 at 06:57
  • @SPlatten I'm beginning to agree with the assessment that the project file for what you're looking at is a bit corrupted. As suggested in my answer, do you have an option to use your SCM setup to just rewind time to before you removed `-D CLSOPENLDV` and start again from there? Possibly in a new branch, and then cherry-pick / merge over any other changes you'e made in the interim? – dgnuff Jul 17 '18 at 07:01
  • @dgnuff, the whole thing is in SVN, I will roll back to an earlier version. – SPlatten Jul 17 '18 at 07:02
  • @dgnuff, I backed up the source folder, then went back to an earlier version from SVN, rebuilt the project and re-ran in debugger, still the same which now leads me to think that there is something in Visual Studio thats broken....next thing is to uninstall and reinstall Visual Studio. – SPlatten Jul 17 '18 at 07:06
  • @dgnuff, I should also add that the host operating system is Windows 10 Enterprise, which was recently updated, not sure if there are any compatibility issues... – SPlatten Jul 17 '18 at 07:51
  • @dgnuff, regarding your edit, what specifically on the file would you like me to check? The file has no Preprocessor settings, the entry for Preprocessor Definitions is empty. – SPlatten Jul 17 '18 at 08:00
0

This project is very large and there are multiple sub-projects in the build, it turns out that one of the other projects in the build was causing a problem with my project. Having checked out a much older tree from SVN and built that we can now work out where the faulty project is and fix.

SPlatten
  • 5,334
  • 11
  • 57
  • 128