报错位置在 comip.h
void _Release() throw()
{
if (m_pInterface != NULL) {
m_pInterface->Release(); // 在这里报的错
}
}
我自己在遇到这个问题时,将 m_pInterface->Release(); 注释掉程序不再报错。
网上一些其他的方法:
1.m_pInterface->Release() 改成 m_pInterface = NULL 出自http://topic.csdn.net/u/20091120/16/8a9c8d91-9a39-416b-8d8d-8c2cd2a71d3e.html
2.程序中实现的时候:ptr->Release();改成ptr.Release();出自http://topic.csdn.net/u/20091120/16/8a9c8d91-9a39-416b-8d8d-8c2cd2a71d3e.html
3.有一种说法是范围问题。个人还不是很懂。详见:http://stackoverflow.com/questions/2653797/why-does-couninitialize-cause-an-error-on-exit
这个方法试了一下,也是可以的。具体见以下说明。
I'm working on a C++ application to read some data from an Excel file. I've got it working, but I'm confused about one part. Here's the code (simplified to read only the first cell).
//Mostly copied from http://www.codeproject.com/KB/wtl/WTLExcel.aspx
#import "c:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.DLL"
#import "c:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
#import "C:\Program Files\Microsoft Office\Office11\excel.exe" rename ("DialogBox","ExcelDialogBox") rename("RGB","ExcelRGB") rename("CopyFile", "ExcelCopyFile") rename("ReplaceText", "ExcelReplaceText") exclude("IFont", "IPicture")
_variant_t varOption((long) DISP_E_PARAMNOTFOUND, VT_ERROR);
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwCoInit = 0;
CoInitializeEx(NULL,