-
unresolved externals and function signatures
Posted on June 2nd, 2009 No commentsBuild issues can be extremely aggravating and hard to track down. I spent quite a bit of time tracking down a link error where everything seemed in order. Function declaration and implementation of a library function matched the call in my application. After much trial and error I decided to get forensic on the compiler. I looked at the mangled function signature of the library file (dropped the .lib file into Visual Studio) and compared it with the mangled function signature in the output window where it was reporting an unresolved external. I used the command line program undname to show me the user-friendly function signatures and the difference was one used __cdecl and the other used __stdcall. I was then able to find that my application was using the C/C++…Advanced…Calling Convention…__stdcall (/Gz) whereas the library was using __cdecl (/Gd). Comparing file signatures between what was actually compiled into the library and what is expected in the application can expose several inconsistant settings. Another one might be the General…Character Set settings.
-
CGI programming
Posted on April 8th, 2009 No commentsI’ve never had an opportunity to work with CGI until now. CGI is defined on wikipedia this way:
The Common Gateway Interface (CGI) is a standard protocol for interfacing external application software with an information server, commonly a web server.
The task of such an information server is to respond to requests (in the case of web servers, requests from client web browsers) by returning output. Each time a request is received, the server analyzes what the request asks for, and returns the appropriate output. The two simplest ways for the server to do this, are the following:
- if the request identifies a file stored on disk, return the contents of that file;
- if the request identifies an executable command and possibly arguments, run the command and return its output
CGI defines a standard way of doing the second. It defines how information about the server and the request is passed to the command in the form of arguments and environment variables, and how the command can pass back extra information about the output (such as the type) in the form of headers.
Here is a great getting started article on CGI.
-
Analyzing Memory Usage on your PC
Posted on March 25th, 2009 No commentsWhat do the Task Manager memory columns mean?
Working Set and Private Working Set explained (It’s like a box of crayons).
-
Link problems with static library
Posted on December 17th, 2008 No commentsAn application is generating the following errors:
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in libcmtd.lib(dbgmalloc.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in libcmtd.lib(dbgfree.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __endthreadex already defined in libcmtd.lib(threadex.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __beginthreadex already defined in libcmtd.lib(threadex.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fprintf already defined in libcmtd.lib(fprintf.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>.\Debug/MyApp.exe : fatal error LNK1169: one or more multiply defined symbols foundQ148652 explains the problem and ways to solve it.
I found that I was linking a static library that was compiled with the C/C++…Code Generation…Runtime Library option set to Multi-threaded Debug DLL (/MDd).
My application was using Multi-threaded Debug (/MTd).
The problem went away once I created a version of the static library that was compiled using Multi-threaded Debug (/Mtd) to match the application.
-
Debugging LoadModule
Posted on December 16th, 2008 No commentsI just finished spending a couple days troubleshooting a problem with a Win32 non-mfc DLL failing a LoadLibrary(). Actually, the post build step for my DLL ran regsvr32 to register it and it started failing with the following message:
RegSvr32.exe calls the following Win32 functions in this order:
- OleInitialize
- LoadLibrary to load the DLL
- DllRegisterServer or DllUnregisterServer
- FreeLibrary
- OleUninitialize
A common reason for failure is that there are dependent DLL's missing. Dependency Walker is good for checking this. Unfortunately, this lead me down a rat hole when I saw that there was a complaint about MSVCR90D.dll. It also led me to erroneously try various things to modify the manifest used and the Code Generation…Library Used settings.
I was unable to break in the DLLMain of the library so I assumed there was a problem in the way I was building it. I even installed the latest Vista SP1 and Visual Studio SP1 to try to make the "build" problem go away.
Ultimately, what worked was for me to create a simple program that called LoadLibrary() on my dll. I then set the Debug…Exceptions options to catch all exceptions. As soon as the test program called LoadLibrary() (on my debug build) it went right to the line of code that was causing an "Invalid access to memory", just like the message said! I guess that's the danger of giving too much information in a message, users will erroneously choose the wrong symptom.
This worked because the problem was in some code that was called during the construction of a C++ object, which was instantiated prior to calling the main entry point of the DLL.
Lesson learned: When a module fails on startup, check your global objects' construction code, and don't forget to turn on catching all exceptions in the debugger!
-
Software Piracy
Posted on September 25th, 2008 No commentsThis is a terrific post on the topic of who pirates and what you can do. The comments offer many additional tips: -
Working with Windows Driver Kit and Visual Studio 2008
Posted on July 9th, 2008 No commentsI had an occasion to try to build a sample app that talked to an HID (Human Interface Device) USB device. I downloaded the latest WDK and attempted to build it with VS2008. I got an error stating that _In_out_ was undefined. This thread was the most helpful but was not specific enough to help me. I figured out a fix which I posted to that thread.
I simply renamed the file C:\WinDDK\6001.18001\inc\api\sal.h so that it would not be found, and the version provided by Visual Studio 2008, C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h, gets used.
-
Link error LNK2005
Posted on June 26th, 2008 No commentsWas getting this error with some legacy code when converted to VS 2008:
nafxcw.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
This article provided a solution. More discussion on this issue here.
Overview of C Run-Time and associated options
Based on Visual C++ 6.0:
Solution One: Force Linker to Link Libraries in Correct Order
1. On the Project menu, click Settings. 2. In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors. 3. On the Link tab, click to select Input in the Category combo box. 4. In the Ignore libraries box, insert the library names (for example, Nafxcwd.lib;Libcmtd.lib). Note The linker command-line equivalent in /NOD:<library name>.
5. In the Object/library modules box, insert the library names. You must make sure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib). -
This application has failed to start because the application configuration is incorrect
Posted on June 24th, 2008 5 comments"This application has failed to start because the application configuration is incorrect"
Was getting this message when testing an application recently converted to VS 2008 from VS 6.0. Depends showed that MSVCRT80.DLL was a missing dependency.
Here are a few threads on the subject:
The programs was pretty small so I felt the easiest workaround was to link statically to the C runtime library. I did this by making sure I selected Multi-threaded (/MT) rather than Multi-threaded DLL (/MD) in the C/C++…Code Generation…Runtime Library option.
-
regsvr32 and Vista
Posted on June 16th, 2008 1 commentTesting the registration of one of our plugins (DLLs) under Vista fails when regsvr32 is launched returning error code 0×80070005. This is an "Access Denied" error and has to do with the fact that under Vista, if you run regsvr32 from a command prompt, the command prompt must be started in Admin Mode (elevated).
Programatically registering a dll.
Not only would executing a shell command to launch regsvr32 fail, but updating ther registery also gets a AccessDenied error. I ended up just turning off UAC while I tested. I suppose since our setup program accessed permission, once given, everything else worked.


