Posts in Visual Studio
Troubleshooting SGEN : error : An attempt was made to load an assembly with an incorrect format
- 10 September 2024
I have a POCO entity project that must generate XML Serializers due to a memory leak bug. Xml serializer generated dynamic assemblies are not ever collected.
Turning on verbose mode in MSBuild options tells the problem.
如何在64位win10的VS2017环境下搭建汇编环境
- 18 June 2018
用户AcmeContracted安装masm32失败,所以想知道是否能集成masm64到Visual Studio 2017中。
VS里面masm不是单独的,是C++工具集的一部分,而在VS2017里C++工具集不是默认安装的,所以要先安装C++工具集。
Book review: Mastering Windows 8 C++ App Development
- 08 August 2013
Disclaimer: I am a Microsoft MVP in Visual C++, so is Pavel Yosifovich, the author of the book.
Mastering Windows 8 C++ App Development by Pavel Yosifovich is a new addition to the Windows Store development books. It took me a while to read (304 pages) but is well worth the time from the perspective of a C++ developer. The book obviously went through great lengths to be comprehensive, not only introduced the typical Windows Runtime (WinRT) APIs in a crisp manner but also added a refreshment of C++ 11, the Model View ViewModel (MVVM) pattern, and the Windows Runtime C++ Template Library (WRL). In addition, being a book for C++ developers, the author’s emphasis on performance can be found in several tips and discussions, which is a nice focus for C++ developers. There are also several weaknesses in the book. Introducing WRL before C++/CX may be a poor choice as it is difficult to inspire the reader with laborious code. Also the book could use a few more details on DirectX and some WinRT APIs such as GeoPosition. Nevertheless, the book is an excellent text for the subject and I recommend the book to C++ programmers who want to start developing Windows Store apps and can do research outside of the book.
How to: Migrating a CLR console Visual C++ project to Windows Forms
- 17 December 2012
Note: Windows Forms programming in new development is discouraged by Microsoft at this point as Microsoft wants to make full use of hardware accelerated drawing instead of using the CPU-intensive GDI. But maintaining old Windows Forms code in Visual C++ 2012 is still supported, GDI isn’t going anywhere anytime soon.
Visual C++ 2012 removed the Windows Forms project template and I see people scramble to find ways to create a Windows Forms project. There is a walkaround that’s been around for years, that is, to convert a CLR console application to a Windows one, then add forms related code to the project.
Add the correct interface first in Adding an MFC Class from an ActiveX Control wizard.
- 04 December 2012
In good old times aka VC6, if you want to use an ActiveX in MFC, the Components and Controls Gallery would generate all the properties and methods of an ActiveX and pull dependent types and create wrapper classes for them as well. And it was good. It magically knows the main class of the Windows Media Player ActiveX is CWMPPlayer4 and that GetCurrentMedia method returns CWMPMedia.
Welcome to the modern Visual C++. Now comes a new wizard that gives you options to choose interfaces to import from. At the same time you got to decide if you really need that many types from an ActiveX. If you went the unfortunate path of Adding a Member Variable wizard in the dialog editor and somehow got a COCX1 class back, you don’t have the luxury to choose, and you end up with an CWnd wrapper class that does not really wrap up the properties and methods of the ActiveX. It is still good for early binding (like querying IWMPPlayer4 from the result of CWnd::GetControlUnknown) but if you plan to use late binding and MFC’s OLE support (hello COleException!), you probably want to delete the COCX1 files and start over with the Adding a Class from an ActiveX Control wizard.
What’s new in MFC/ATL 11 Beta
- 22 April 2012
Note this post is on Visual Studio 11 Beta, you can download it from http://www.microsoft.com/visualstudio/11/en-us/downloads Since Sinofsky posted about no desktop apps on Windows on ARM (WOA), it looks like MFC and ATL are going to support metro-style apps, although most ATL classes are not going to be compatible with metro style apps.
DAO support for ARM is missing, just like the lack of DAO support for 64 bit apps. Jet was deprecated a while ago, no surprise here.
Windows Update KB2538242 or KB2538243 offered repeatedly
- 24 June 2011
Recently (this post was originally published in 2011) there is an outburst of posts related to the KB2538242 update being offered repeatedly on MSDN’s Visual C++ forums, TechNet’s various Windows security forums and the Windows Update forum on Microsoft Answers forums. Questions about KB2538243 appear as well, but to a less degree.
To save your time going to the forums or calling Microsoft’s free security hotline, this is my answer:
Bug in Security Update for Visual C++ Redistributable Package: April 12, 2011 causes program error on Windows 2000
- 17 April 2011
Update:Microsoft’s Visual C++ team has released workarounds on the problem. AVG has released an utility that can revert the KB2467175 update, downloadable at http://twitter.blog.avg.com/2011/04/avg-feedback-update-26411.html
Avira is reporting that its AntiVir software throws “The procedure entry point FindActCtxSectionStringW could not be located in the dynamic link library KERNEL32.dll.” error after installing the update released earlier this week.
How to solve LNK2001 errors related to Windows SDK CLSIDs
- 08 April 2011
User IMFCoder wants to know how to solve a LNK2001 error related to CLSID_CMpeg4sDecMediaObject. The user has no problem linking a lib file in the project but couldn’t find which lib the CLSID is in.
The Windows SDK is strangely cryptic on which lib file the CLSID is exported from. Luckily you can find out the library file you need to link with, if you execute the following command line in the SDK command prompt.
Visual Studio 2010: Class Wizard重返Visual C++… Control Shift X.
- 11 November 2009
在消失4个版本之后,类向导终于重返Visual C++。新的功能:搜索现在可以部分匹配而不是从字符串开始匹配。
测试版还是存在一些问题,向导不是总能找到现存的函数,以致删除函数功能不是总有效。在打开很多文档的时候尝试打开Class Wizard会出现“value does not fall in expected range” 错误。再就是性能问题,打开的文档越多,类向导启动所需的时间就越长。
Walkaround for Error : An add-on for this website failed to run. When opening Visual C++’s Add Variable Wizard after IE 8 is installed
- 24 March 2009
Update: it looks like a lot of people are hitting this page by mistake. If you don’t write software for a living then this page is not for you.
The program is lost, but what it does is basically copying the entries from the restricted zone to the 1000 zone (custom zone of VC++ Wizards engine). In addition it has a REG_DWORD value set to 0 for name “1207”. IE security zone settings are stored in the registry path HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet SettingsZones
Visual C++ 10 和 MFC 10的新特性
- 11 October 2008
Boris Jabes 和Damien Watkins将会在PDC上演示Visual C++10中的新功能。IDE的新功能包括基于SQL Compact的智能提示、 支持自定义插件的新的项目和编译系统、面向大型应用的优化和改善的调试体验。MFC库增加了对Windows 7 中新增的多点触摸检测功能和高DPI支持,以及Windows Vista中集成的功能,例如高彩图标 、 Windows 搜索和重启管理器。Visual C++程序员们才习惯不用MFC来直接调API。
MFC是很老了,不容易学,也不优雅,但是很稳定,也有很多第三方扩展和示例支持。其他的用户界面库还有很多,但是单单用户界面并不能完成一个程序。在调用操作系统的底层功能的时候,有一个面向对象的接口还是很方便的。
MFC Feature Pack发布
- 07 April 2008
Visual C++项目组今天发布了Visual C++ 2008 Feature Pack。这个Feature Pack包含了一些以前需要付费给BCG Soft才可以使用的控件,例如BCG著名的窗口布局和风格自定义功能,不过也有一些有用的控件,例如文件夹列表、文件夹树、属性窗格等等。
这个Feature Pack也包含从Dinkumware获得授权的一些对STL的扩展,实现了TR1草案。这包含新的随机算法、集合类和正则表达式支持。关于TR1的更多信息,可以参考Dinkumware的网站。
MFC更新Beta版
- 08 January 2008
一个面向Visual C++ 2008的MFC更新测试版已经发布,同时也提供了文档的下载。这个版本包含新的界面的特性,例如Office Ribbon、2003和XP风格,Visual Studio风格和MDI标签。另外,这个版本也包含部分TR1的实现,例如正则表达式、更加丰富的集合和智能指针。 另外,在下载页面居然说这个版本还不支持Visual Studio 2008 Service Pack 1的Beta版,正式版才出来几天SP1的测试版就出来了?
Visual C++ 2008 Beta2 里面的Class Designer
- 30 July 2007
Visual Studio 2008 Beta2中的Class Designer终于支持C++了,上面是一个MFC程序的类图,可以看到已经支持扩展MFC的宏了,可惜只能看不能重构代码。尽管Class Designer这功能相当不错,但是设计师们可能还是更习惯IBM 的Rational Rose Developer for Visual Studio和UML。我用Class Designer的C#支持的时候也就是加加注释而已,重构我更习惯用DevExpress提供的工具Refactor来做,类则用XSD.exe生成,因为Class Designer生成的属性只会扔NotImplementedException异常。
CSDN Tags: C++, Class Designer, Visual Studio 2008, Rational Rose, UML, C#, DevExpress, Refactor
Visual C++项目组在做下一个版本的市场调查,有兴趣的可以去提提要求。
STL/CLR, Compiler and Marshaling
- 12 April 2007
MSDN第9频道又采访了Visual C++类库组的项目经理Nikola Dudar和Sarita Bafna,以及质量控制组的Marina Polishchuk。尽管Visual C++项目组已经转移了工作重点,但是很少人注意到这一点。或许这些采访可以帮助你了解Visual C++项目组的工作。 为什么C++仍旧重要?
非托管的应用程序有很大的代码积累,而这些程序的升级工作仍旧在进行
性能是选择C++的重要因素。举例来说,游戏和杀毒程序更适合用非托管代码来编写。
多平台支持。虽然.Net号称是跨平台的,但是如果要编写真正的跨平台程序,开发的时候遵循C++标准还是很有必要的。
为什么C++程序员仍旧重要?
C++程序员理解整个机器的运作,他们知道怎么写垃圾收集机制,甚至可以写机器代码
C++程序员可以很容易的学会其他语言——C++已经是最难学的语言之一了
C++程序员并不只使用一种语言。如果有必要的话,他们会选择汇编、C#或者Perl这样更适合特定任务的语言。
为什么Visual C++项目组转移了工作重点?
C++程序员对于转到C#没有抵触心理,所以Visual C++项目组不认为有必要尽快实现Visual C#支持的所有特性,比如LINQ和WPF设计器
C++程序员对于让他们的非托管程序调用其他语言的托管代码比用C++来写托管代码更有兴趣
核心模块,例如IE和Windows外壳会更加频繁地更新,而会有更多的非托管代码需要调用这些新的特性,为了这些特性,有必要在MFC中引入新的封装类来节省C++程序员的时间
Orcas中Visual C++的新特性:
托管代码互操作库。可扩展的托管数据类型和非托管数据类型的转换支持
STL/CLR。使得托管代码可以利用旧的STL编写的算法
Vista支持。对Vista中新的通用控件和文件对话框等界面元素的MFC封装。
DevExpess重构引擎——将包含DevExpess的Refactor!™ for C++。
Orcas之后的考虑
更新界面。有些Visual C++的代码是针对20年之前的硬件环境设计的,已经不适合现在的需要。新的Phoenix编译引擎使得重写前台变得更加容易。
太多现有的代码需要重构。新的Phoenix编译引擎使得代码分析变得更加容易。
C++标准。新的C++标准TR1可能会在Orcas下一版本开发时成为正式标准。
多核支持。需要编写可以充分利用多CPU的代码。第一个尝试是LINQ。
结论
MFC和非托管代码回来了
性能和多平台支持的重要性越来越低,托管代码仍旧具有很大的市场。
Visual C++项目组的其他动作
ATL Server发布到了源代码共享站点CodePlex。这包含CAtlRegExp,在.Net和第三方类库(boost,TR1)的竞争下已经不再有必要维护一个单独的条件表达式标准了
Visual Studio 2005 Untrusted by IE7
- 11 November 2006
Today I upgraded one of my development machine to IE7. Everything looks fine, except I have to change the FileDownload event handler to make my code compile.
However, suddenly I found Visual Studio 2005 is complaining:
Conclusion:
Visual Studio is based on WebBrowser control (Is this news story?)
Upgrade to IE7 may break some applications (Again, is this a news story?)
Everything else works fine so far…
Nomination of Microsoft Award for Customer Excellence
- 22 November 2005
Dear Sheng Jiang, Thank you for being a great contributor to Microsoft Visual Studio 2005. You have been nominated to receive the Award for Customer Excellence. This award recognizes your extraordinary contribution to the Visual Studio 2005 product and will be shipped to you without charge. Please click the following link to arrange shipment of your award: (link omitted) Should you have any questions about this award, please contact (email omitted). All the best, S. Somasegar Corporate Vice President, Microsoft Developer Division
However, I’v already got VS2005 from my one year free MSDN Premium Subscription (for Visual Studio 2005), as a part of Microsoft Most Valuable Professional Award package. It may be better if they put something else in the ACE award package …
FAQ:如何在……中获得……的指针(MFC)
- 10 November 2005
问:请问如何在一个全局函数中,获得视图类,文档类得指针啊? 问:如何在一个对话框中,获得视图类,文档类得指针啊?
答:虽然你可以使用AfxGetMainWnd或者AfxGetApp之类的函数来访问全局变量,但是不建议这么做。你应该尽量少使用全局函数和变量以增加代码的可移植性。你可以在对象中声明变量来保存和传递需要使用的对象和指针,调用函数或者创建对象时传递指针。
Visual C++ 2005 中的XML注释
- 05 November 2005
C#程序员可以用三个斜杠来开始XML格式的注释,而且编译器可以据此生成可用于自动生成帮助文档的XML文件。Visual C++ 2005中的编译器也支持了这个功能,而且对非托管函数也生效,前提是必须打开/clr和/DOC开关,并且不能使用/clr:oldSyntax开关编译。
有空的话,多去微软的反馈中心提提对产品的建议是很有好处的……
How to use Visual C++ with Perl
- 03 November 2005
Microsoft Visual C++ and later do not support perl scripts by default. That is, the Developer Studio does not associate any special significance to perl scripts without being informed otherwise. However, there are several viable options, namely custom build rules, which enable the creation of projects that depend directly upon perl scripts. The remainder of this article discusses the following three methods for adding perl script files to a Visual C++ project:
Using custom build rules
托管C++中函数调用的双重转换(Double Thunking)
- 07 October 2005
在VC.Net中使用默认设置/clr编译时,一个托管函数会产生两个入口点,一个是托管的,供托管代码调用,另外一个是非托管的,供非托管代码调用。但是函数地址,特别是虚函数指针只能有一个值,所以需要有一个默认的入口。
非托管入口点可能是所有调用的默认入口(在 Visual Studio .NET2003 中,编译器总是会选择非托管入口,但是在Visual Studio 2005中,如果参数或者返回值中包含托管类型,那么编译器会选择托管入口),而另外一个只是使用托管C++中的互操作功能对默认入口的调用。在一个托管函数被另一个托管函数调用的时候,这可能会造成不必要的托管/非托管上下文切换和参数/返回值的复制。如果函数不会被非托管代码使用指针调用,那么可以在声明函数时用VC2005新增的__clrcall修饰符阻止编译器生成两个入口。 现在用简单的冒泡排序算法来比较一下使用__clrcall之后的性能改善程度。
西雅图MVP峰会见闻
- 03 October 2005
个人觉得这次MVP峰会最大的进步就是技术相关的Session数量大大增加,按照MVP专长来分类;而不像上次那样按主题分类。我只需要在VC产品组的日程里面选择就可以了,而不是像上回那样不得不去听移动开发。当然这回也有MVP不去参加VC的Session,跑去听IE和移动开发。内容方面也比上次活泼很多,Don Box还是那么幽默,比尔·盖茨也有搞笑的演出,不过他看起来比去年七月份在北京的时候老多了。
一些可能有人会感兴趣的技术信息
C++/CLI中的默认属性访问
- 30 August 2005
目前版本的VC2005测试版中,default关键字不仅用于指定类级别的索引器,而且也用于访问默认属性。但是奇怪的是,默认属性的原名不能访问了,也就是说,如果要把下面的代码段从托管C++移植到VC2005附带的C++/CLI,不仅需要更改指针的类型,而且要把属性的名称更改为default:
如果继续使用原来名字来访问属性的话,会报告编译错误:
MFC,欢乐与痛苦
- 20 August 2005
MFC提供了许多十分有用的类和对象,在很多时候在Office插件、BHO、常规DLL这样的工程中加入MFC支持是一个不错的选择。但是,MFC中的很多功能,例如资源查找,消息预处理等等都依赖于在进程或者线程创建时被初始化的MFC内部数据;而对于需要添加MFC支持的工程,这些数据并不会被自动地初始化。
这时候使用一些MFC的功能,例如使用CString从字符串表加载一个字符串,或者使用CDialog::DoModal()创建一个模态对话框,都会有断言错误,用ATL向导创建的支持MFC的程序也没有多少改善,在CWinApp的DLL版本中没有初始化线程数据,所以调用AfxGetThread会返回空指针。解决这个问题的一个办法是使用AfxBeginThread来启动一个MFC线程,这样MFC会初始化线程相关的数据。
Visual Studio 2005中MFC的变化
- 05 July 2005
关于新功能的说明 http://msdn2.microsoft.com/library/y8bt6w34(en-us,vs.80).aspx
一些源代码的变化:
Use windbg as an external tools of Visual C++
- 27 June 2005
在我的前一篇BLOG(使用WinDbg调试VC程序)中我提到了如何使用WinDbg来调试Visual C++程序。但是从IDE到命令行之间的切换比较麻烦,为了偷懒起见,可以把WinDbg加到Visual Studio的工具菜单中,这样就可以直接从IDE启动WinDbg来进行调试了。下面是外部工具配置界面的设置
标题 : WinDbg
使用WinDbg调试VC程序
- 08 June 2005
虽然在VC6.0中可以通过安装Visual C++ Toolkit(https://archive.org/details/microsoft-visual-c-toolkit-2003)来编写基于最新版本的平台SDK、DirectX SDK的程序以及托管代码,但是VC6附带的调试器并不支持新版本的调试信息,所以实际上是不能用VC6来调试新版本编译器生成的程序的。
一个替代的解决方案是使用新版本的Windows调试工具Windbg(https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/)。Windbg的调试功能基本和Visual C++中的相同,但是需要手动设定源文件和调试符号文件的搜索路径(可以参考VC6.0中的对应设置)。
Visual C++ 2005的版本区别
- 21 April 2005
经常看见有些人问Visual C++ 2005里面为什么没有了MFC。实际上,MFC只是在目前免费下载测试版的Express版本里面没有,在其它的版本里面都有——但是一般都是要付钱的。具体的各个版本的比较可以参见参考部分的链接。不过对于用VC来学习.Net开发的程序员来说,Express版就足够了。
小道消息:
程序员之懒
- 19 April 2005
程序员在我看来是比较会偷懒的一个群体。为了在开发软件的时候减少人工操作,他们会使用各种各样的软件和语言特性,例如IDE和预处理宏。李建忠在他的BLOG(http://blog.joycode.com/lijianzhong/archive/2005/05/08/50440.aspx)中提到,为了简化声明属性的工作,他的同事自己写了一些小工具来生成需要的代码。在C++托管扩展中,这个工作稍微简单一些,用预处理宏就可以了。
当然,如果使用C++/CLI的话,这个工作更加简单:
Visual C++ 2005 Beta 2中的变动
- 19 April 2005
stdcli::language名称空间被取消,代之以cli名称空间。
MFC对.Net控件的事件支持宏VENT_DELEGATE_ENTRY的参数类型变化:例如
VC的自动化向导的BUG
- 19 April 2005
BUG: ClassWizard Omits Methods with BYTE or BYTE* As Parameters (http://support.microsoft.com/kb/q241862/)
BUG: VTS_UI1 and VTS_PUI1 are Defined Incorrectly in AfxDisp.h (http://support.microsoft.com/kb/242588/)
示例:在MFC程序中集成.Net中的控件
- 19 March 2005
从.Net Framework 1.1开始,.Net控件可以以ActiveX的方式被集成到非托管宿主中——但是官方的支持只对于使用托管C++的MFC程序。Chris Sells在2003年3月份的MSDN杂志中描述了这样一个示例(https://web.archive.org/web/20030304083154/http://msdn.microsoft.com/msdnmag/issues/03/03/WindowsForms/default.aspx)。这个示例使用的代码稍微繁琐,而且没有描述如何处理控件的事件。MFC 8.0增加了一系列这方面的支持来把这个集成过程简单化(参考http://msdn2.microsoft.com/en-us/library/ahdd1h97.aspx)。这使得在MFC程序中使用.Net中的一些比较好用的类,例如System::Windows::Forms::PropertyGrid比以前容易多了。
举例来说,要在MFC的基于对话框的程序中使用System::Windows::Forms::PropertyGrid控件,首先创建一个基于对话框的程序,添加必要的引用:
《转换指南: 将程序从托管扩展C++迁移到C++/CLI》译后
- 17 March 2005
终于把Stan Lippman先生的这篇文章译完了。从去年4月在全球MVP峰会上拿到这篇文章的手稿到现在,差不多一年过去了。虽然当时的Visual Studio 2005还不支持一些语法,但是我和董颖涛对新的C++/CLI语言都很感兴趣,在当时就讨论过翻译的问题。之后我就开始翻译这篇文章,但是进度一直很慢——主要是杂务太多、语言上的困难(尽量避免误解和词不达意的情况,以及斟酌用词的选择)。在1月份完成了全文之后,看到了Sunhui的一篇文章(http://community.csdn.net/expert/Topicview1.asp?id=3834281),觉得附录里面讲到的一些内容或许一些人也有兴趣,所以继续翻译附录的工作,幸好现在是春假,比较有时间,终于在今天完成了。译文目前在http://blog.csdn.net/jiangsheng/archive/2004/10/18/140450.aspx可以访问,希望读者指正。
在翻译过程中得到了曾毅的帮助,得以联系到Stan Lippman先生,在此一并感谢。
虚析构函数
- 24 January 2005
编译器总是根据类型来调用类成员函数。但是一个派生类的指针可以安全地转化为一个基类的指针。这样删除一个基类的指针的时候,C++不管这个指针指向一个基类对象还是一个派生类的对象,调用的都是基类的析构函数而不是派生类的。如果你依赖于派生类的析构函数的代码来释放资源,而没有重载析构函数,那么此时会有资源泄漏。
所以建议的方式是将析构函数声明为虚函数。如果你使用MFC,并且以CObject或其派生类为基类,那么MFC已经为你做了这件事情;CObject的析构函数是虚函数。一个函数一旦声明为虚函数,那么不管你是否加上virtual修饰符,它在所有派生类中都成为虚函数。但是为了理解明确起见,建议的方式还是加上virtual 修饰符。
在Visual C++中编译工程时自动增加版本号
- 24 January 2005
微软知识库中的文章How To Increment Version Information After Each Build in Visual C++(https://web.archive.org/web/20070211114127/http://support.microsoft.com/kb/237870/)提供了在VC6中自动增加版本号的方法。在VS.Net中,需要对这个宏进行少许的更改:https://web.archive.org/web/20040616201737/http://www.thecodeproject.com/macro/IncBuildNrMacro.asp
也可以使用VS.NET插件来实现该功能,一个示例在下面的网址可以找到:
Good Bye MFC?
- 12 December 2004
原文地址在https://web.archive.org/web/20041204071945/https://channel9.msdn.com/ShowPost.aspx?PostID=31152
起源是VC开发组的一个人的言论“MFC仅仅用于支持旧的代码,新的代码不应该用MFC编写,而是应该用C#或者Managed C++”
98年出的VC6看来也是和Win98一样日落西山了
- 11 November 2004
段落小题引用了《大话西游》中的若干段落,在此声明。
谁说我斗鸡眼?我只是把视线集中在一点以改变我以往对事物的看法
VC6 with .NET CLR & Managed C++
- 28 April 2004
如何让你的VC6也可以写出mc++的程序是一个有挑战性的工作,不过看来MS对于解决这个问题似乎是手到擒来.通过下载一个名叫Microsoft Visual C++ Toolkit 2003 的软件,就可以实现这样的愿望。
访问这个了解更多:http://msdn.microsoft.com/visualc/vctoolkit2003/
Visual Studio 6.0 Service Pack 6
- 01 April 2004
FIX: “Cannot Save File” Error Message in the Visual C++ IDE
https://web.archive.org/web/20040417095303/http://support.microsoft.com/default.aspx?kbid=822856
