0

I am trying to use shdocvw in a managed C++ program. I have read COM Interop using managed C++ - CodeProject. I used the instructions in How to add references to a managed Visual C++ project to create Interop.shdocvw.dll. I moved the file to my project directory. I am using VS 2010 Professional. I added:

#using "Interop.shdocvw.dll"

to my program. In my program I have:

SHDocVw::ShellWindows swList;

I am getting the error:

error C2653: 'SHDocVw' : is not a class or namespace name

I have also tried using a "using namespace" but that does not work either.

I am not getting an error from the #using so it is finding the file. I assume I am close to getting it to work; what am I missing?

2 Answers 2

0

I cannot imagine why this doesn't work, other than something drastically going wrong when you ran the tlbimp.exe utility. There's no need to do this, you can also do it with the IDE.

Right-click the project in the Solution Explorer window, Properties, Common Properties, Framework and References. Click the Add New Reference button. Browse tab, navigate to c:\windows\system32\shdocvw.dll. You should now have no trouble using the SHDocVw namespace. Troubleshoot with View + Object Browser.

And don't forget that interfaces are reference types, you need the hat:

 SHDocVw::ShellWindows^ swList;
2
  • Thank you, Hans. I downloaded [ILSpy][1]. It told me that the namespace is Interop.shdocvw. Of course that is Interop::shdocvw for C++. That worked. Yes, I got the message "cannot use this type here without a top-level '^'" so it did not take me long to learn about the hat. Thank you for the alternative method of adding a reference. I will likely do that in the future. So now I need to figure out how to get the events hooked up but I am sure that will be easy, especially compared with doing it using unmanaged C++. [1]: wiki.sharpdevelop.net/ilspy.ashx
    – Sam Hobbs
    May 30, 2011 at 2:19
  • I know you (Hans) have the best advice possible, I recognize you from elsewhere, probably the MSDN forums. I am SimpleSamples in the MSDN forums.
    – Sam Hobbs
    May 30, 2011 at 2:21
0

As of VC++ 2008, you shouldn't be creating your own interop assembly for shdocvw.dll -- the type library importer notoriously fails to correctly translate many of the signatures (especially those of events) so Microsoft started shipping a manually-translated interop assembly with the .NET framework in VS 2008 called Microsoft.mshtml.dll.

So, get rid of your Interop.shdocvw.dll and add a reference to Microsoft.mshtml.dll, the contents of which are in namespace ::mshtml.

2
  • I changed Interop.shdocvw.dll to Microsoft.mshtml.dll in the using statement but the compiler did not find it. I tried both with double-quotes and with angle brackets. I searched my system for Microsoft.mshtml.dll and it was not found anywhere in my C:. I searched the MSDN for information about it but I did not find anything in the MSDN saying it is to be used and or where to download it from Microsoft. I can't find anything in the MSDN that says that ShellWindows is in the mshtml namespace. Are you sure you meant to say that ShellWindows is in the mshtml namespace?
    – Sam Hobbs
    May 28, 2011 at 6:53
  • @SamHobbs : Oh, I assumed you needed IWebBrowser or some other HTML related functionality; if you need ShellWindows, then you will indeed need to import the type library yourself. If you want the filename Interop.shdocvw.dll with contents in namespace SHDocVw, then run this command: tlbimp shdocvw.dll /out:Interop.shdocvw.dll /namespace:SHDocVw
    – ildjarn
    May 28, 2011 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.