开发者

shdocvw in managed C++

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 namespac开发者_运维技巧e" 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?


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;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜