Wednesday 24 November 2010

error C2662: cannot convert 'this' pointer from 'const

error C2662: cannot convert 'this' pointer from 'const

OK I've fallen for this one too many times now! What is means is that you are calling a function on a const object, and the compiler is worried that the function will modify the object.. so assuming it doesnt then add const to the end of the declaration and all will be well in the world again.

class MyClass
{
void Func() const;
}

Monday 13 September 2010

Getting the time into a filename using a batch file

I'm repeatedly grabbing some data from an external device, and I want it stored locally under a suitable filename which includes the time for reference.


:loop
SET now=%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
grabdata.exe data%now%.bin

REM The line below forces a pause for two seconds. Very handy!
@ping 127.0.0.1 -n 2 -w 1000 > nul

goto loop


A quick work of warning - you may need to adjust the parameters of the date to match your location.
when I type at the command prompt
echo %date%
I get
13/09/2010
so be prepared to modify if you don't have DD/MM/YYYY format.




Tuesday 31 August 2010

Project : error PRJ0003 : Error spawning 'resgen.exe'.

Project : error PRJ0003 : Error spawning 'resgen.exe'.

Kept getting this in vs2008. Searched for resgen.exe and it existed in the windows SDK directory.

So simply go to Tools/Options/ProjectsAndSolutions/VC++ Directories and append "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin" or whatever to the Executable files list. Sorted!

Saturday 28 August 2010

System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

Argh! Been trying to install a service for about 2 hours. I followed the wizard in vs2008 to create a new service, added a call to start a thread of my code, hit compile, removed unicode and set to clr, hit compile again, and woo an EXE. Opened a command prompt, typed in "myservice.exe -Install" and oh dear.. failure. Seems I had to right click some crazy stuff and "Add Installer".. Sure I didnt have to do that part last time I made a service. Odd. So did it anyway, and tried again.
Still no luck! Tried creating an ASPNET admin user on my machine.. nope..
Some progress was made when switching properties from Local Service to Local System.. but the big breakthrough came when I closed my command prompt and opened another one as administrator.
Still not convinced by all this admin crud in Win7. Not sure it's an advance on XP in that regard. Ho hum, it looks like I've got a service to play with at last :)

Monday 23 August 2010

The application has failed to start because its side-by-side configuration is incorrect.

Argh!
I recent spent a very frustrating day trying to get a program that was built with vs2005 running on a pc without visual studio installed. Any pc with visual studio installed had no problem running the simple exe, but without, this error always appeared:
"The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail."
Straight away I meddled with "Multi-threaded / Multi-threaded DLL", but going totally static wasn't possible as some external librarys were being used that insisted on DLL action. So forget the static, and play nice.. Installed vs2005 runtime on the target machine, and vs2005 runtime SP1. Still no luck. I was compiling in XP, and vista was on the target machine. Maybe an issue there? The vista machine probably wasn't up to date with windows updates too.
Anyway, six frustrating hours later, I opened up the project in vs2008 instead, converted it, and soon managed to get it to compile. This worked!
So it looks like I'll be using vs2008 for all my pc projects now.

Wednesday 7 July 2010

LINK : fatal error LNK1000: Internal error during IncrBuildImage

Oh dear, what's all this?

After a fresh Windows7 install my vs2008 c++ project kept regularly throwing this at me at the link stage.

A microsoft hotfix seems to have sorted it though :

Although maybe the real reason is that I haven't installed the vs2008 SP1 update yet.

Either way the problem has gone so I'm a happy bunny.

Tuesday 6 July 2010

dxguid.lib(dxguid.obj) : fatal error LNK1103: debugging information corrupt; recompile module

dxguid.lib(dxguid.obj) : fatal error LNK1103: debugging information corrupt; recompile module

Argh, what's going on?! There's surely nothing wrong with the debugging info in dxguid.lib. So what's the real problem?

Well it's a known backward compatibility with the Windows SDK. Using the Windows 7 SDK with Visual Studio 2005 can cause problems if linking with libs created with Visual Studio 2008.

So.. either migrate to VS2008, or install the microsoft hotfix http://support.microsoft.com/kb/949009/

..and you are back in action!!


error LNK2005: __vsnprintf already defined in LIBCMT.lib

MSVCRT.lib(MSVCR80.dll) : error LNK2005: __vsnprintf already defined in LIBCMT.lib(vsnprint.obj)

How many times have I seen this type of error? ....and how many times have I had to look up the answer? Too many.

So, while it's fresh in my mind, here's the solution.

Decide if you want your application to use runtime DLLs or to include them internally.

If you include internally then:
- You won't have the benefit of future runtime DLL patches
- You don't have to worry about DLLs following the exe around
- You will have the added cost of greater filesize

So choose either
/MT - (no DLLs) LIBCMT.lib is included
or
/MD - MSVCRT.lib is included and DLLs are used at runtime

The option is found in Project properties / Config properties / C/C++ / Code Generation / Runtime Library

If you experience the above error then you are mixing the two, which is bad. Check each lib that you are linking in conforms to your choice. Rebuild any that do not and the error will disappear like magic!