12

A strange error:

error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions. C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets 744

I got this error when trying to use OpenSceneGraph (OSG) in an ActiveX control. A Google search showed all kinds of solutions which didn't really solve the problem or locate the exact cause of the error, so I'd like to put the solution in one place: Here.

I found the solution to it, and will be answering my own question soon, so that people can find their solution if they encounter the same problem.

Bart
  • 18,467
  • 7
  • 66
  • 73
Nav
  • 16,995
  • 26
  • 78
  • 120

6 Answers6

24

This error happens when Visual Studio (2010) can't find the dependent dll files that are required by the program for creating the OCX. The OCX is created in the Debug directory of the project (for Debug builds), and specifying the "Working directory" (in project settings) as the folder where the dependent DLL's are, won't help Visual Studio in locating the DLL's.

Now the catch is (this is what makes it a headache to solve the problem) that sometimes, without Visual Studio being able to create the OCX, you won't be able to run Dependency Walker on the OCX. So you'll never figure out that the missing DLL's are the problem.

If you know which DLL's need to be placed in the Debug folder, just place them there, and the error will disappear. If you don't know, and if your OCX didn't get created, then go to project settings > Linker > General > Register Output and set the value to "No". This will create your OCX for you, but won't go through the process of registering it, which is when it needs the dependent DLL's.

Once you double-click the OCX and Dependency Walker shows you the missing DLL's with yellow circle icons, just place those DLL's in the same folder as the OCX, and your program will work fine. It's that simple.

Nav
  • 16,995
  • 26
  • 78
  • 120
  • 1
    Very helpful. Getting a built OCX and using dependency walker helped me identify the issue - turns out I didn't have the 64 bit files it depended on (Modules with different CPU types were found). – Jon Peterson Jun 04 '13 at 15:50
  • Is there anyway to do this without copying the dlls to the debug directory? I'd rather specify another directory that contains the dll, just like the additional library directories property which it uses to find the lib. – steinybot Jul 15 '14 at 22:39
  • It's a common problem. Even I wanted a solution to it: http://stackoverflow.com/questions/4953843/why-cant-visual-studio-find-my-dll and so did these guys http://stackoverflow.com/questions/2119539/visual-studio-how-to-set-path-to-dll and http://stackoverflow.com/questions/428085/how-do-i-set-a-path-in-visual-studio – Nav Jul 16 '14 at 12:00
  • I had encountered this error and because of this post I could identify that the issue was occurring due to missing of dependant DLLs....Thanks a lot... – Partha Aug 07 '19 at 13:05
8

The issue could be that your project tries to register a COM object, but there are not enough privileges to do that. On Windows 7 and 8 regsvr32 requires administrative permissions.

What you can do is the following. Create a shortcut on your desktop to C:\Windows\SysWOW64\cmd.exe (the 32-bit console). Right click, Properties -> Advanced -> check Run as administrator. Launch the shortcut, and make sure User Access Control pops up, and click Yes. Start building from this special console window.

Tamas Demjen
  • 650
  • 1
  • 6
  • 7
5

I tried using run as "Administrator" VS 2015, it's able to solved the problem

EW28x021
  • 59
  • 1
  • 1
3

MSB8011 seems to be a generic error raised whenever regsvr32 encounters a problem. In my case, regsvr32 exited with code 4 when Per-User Registration was set to "Yes", but the DLL I was building did not define a DllInstall entry point.

Mike
  • 61
  • 1
2

You can also do this via VS 2013 IDE by launching this IDE from program files shortcut, Select Visual Studio 2010/2013 and then right click and select run as administrator, after IDE launched, then open your solution file and build it, you will never get such errors because of regsrv32 DLL/COM registration

Suresh
  • 21
  • 1
1

On the Property page go to

Configuration Properties->Build Events->Post-Build Event

you might be referring to it as a /Service. Modifying options as shown below could help.

Before modification:

Before modification

After modification:

After modification

CJBS
  • 13,354
  • 5
  • 76
  • 124