Search Results

Search found 53 results on 3 pages for 'queryinterface'.

Page 3/3 | < Previous Page | 1 2 3 

  • How to deploy a visual studio custom tool?

    - by Aen Sidhe
    Hello. I have a my own custom tool for Visual Studio 2008 SP1. It consists of 5 assemblies: 3 assemblies with code that used heavily in my other projects, 1 assembly-wrapper above VS2008 SDK and assembly with the tool. If I'd debug my tool from visual studio, using "Run external program" option with command line "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" and arguments "/ranu /rootsuffix Exp" all work perfectly. After that I trying to deploy it to my working VS copy, not to experimental hive doing: gacutil /i Asm1.dll for all my assemblies and doing RegAsm Asm1.dll only for assembly with custom tool. Neither of utils prints any error, all work as planned, even registry keys appeared. But my tool don't work even after PC restart. What did I do wrong? Wrapper looks like that: [ComVisible(true)] public abstract class CustomToolBase : IVsSingleFileGenerator, IObjectWithSite { #region IVsSingleFileGenerator Members int IVsSingleFileGenerator.DefaultExtension(out string pbstrDefaultExtension) { pbstrDefaultExtension = ".cs"; return 0; } int IVsSingleFileGenerator.Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress) { GenerationEventArgs gea = new GenerationEventArgs( bstrInputFileContents, wszInputFilePath, wszDefaultNamespace, new ServiceProvider(Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider) .GetService(typeof(ProjectItem)) as ProjectItem, new GenerationProgressFacade(pGenerateProgress) ); if (OnGenerateCode != null) { OnGenerateCode(this, gea); } byte[] bytes = gea.GetOutputCodeBytes(); int outputLength = bytes.Length; rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength); Marshal.Copy(bytes, 0, rgbOutputFileContents[0], outputLength); pcbOutput = (uint)outputLength; return VSConstants.S_OK; } #endregion #region IObjectWithSite Members void IObjectWithSite.GetSite(ref Guid riid, out IntPtr ppvSite) { IntPtr pUnk = Marshal.GetIUnknownForObject(Site); IntPtr intPointer = IntPtr.Zero; Marshal.QueryInterface(pUnk, ref riid, out intPointer); ppvSite = intPointer; } void IObjectWithSite.SetSite(object pUnkSite) { Site = pUnkSite; } #endregion #region Public Members public object Site { get; private set; } public event EventHandler<GenerationEventArgs> OnGenerateCode; [ComRegisterFunction] public static void Register(Type type) { using (var parent = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\VisualStudio\9.0", true)) foreach (CustomToolRegistrationAttribute ourData in type.GetCustomAttributes(typeof(CustomToolRegistrationAttribute), false)) ourData.Register(x => parent.CreateSubKey(x), (x, name, value) => x.SetValue(name, value)); } [ComUnregisterFunction] public static void Unregister(Type type) { using (var parent = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\VisualStudio\9.0", true)) foreach (CustomToolRegistrationAttribute ourData in type.GetCustomAttributes(typeof(CustomToolRegistrationAttribute), false)) ourData.Unregister(x => parent.DeleteSubKey(x, false)); } #endregion } My tool code: [ComVisible(true)] [Guid("55A6C192-D29F-4e22-84DA-DBAF314ED5C3")] [CustomToolRegistration(ToolName, typeof(TransportGeneratorTool))] [ProvideObject(typeof(TransportGeneratorTool))] public class TransportGeneratorTool : CustomToolBase { private const string ToolName = "TransportGeneratorTool"; public TransportGeneratorTool() { OnGenerateCode += GenerateCode; } private static void GenerateCode(object s, GenerationEventArgs e) { try { var serializer = new XmlSerializer(typeof (Parser.System)); using (var reader = new StringReader(e.InputText)) using (var writer = new StringWriter(e.OutputCode)) { Generator.System = (Parser.System) serializer.Deserialize(reader); Generator.System.Namespace = e.Namespace; Generator.GenerateSource(writer); } } catch (Exception ex) { e.Progress.GenerateError(ex.ToString()); } } } Resulting registry keys: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Generators] [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Generators\{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}] [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Generators\{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}\TransportGeneratorTool] @="TransportGeneratorTool" "CLSID"="{55a6c192-d29f-4e22-84da-dbaf314ed5c3}" "GeneratesDesignTimeSource"=dword:00000001 "GeneratesSharedDesignTimeSource"=dword:00000001

    Read the article

  • "Exception has been thrown by the target of an invocation" Running Tests - VS2008 SP1

    - by omatrot
    I'm using Visual Studio 2008 Team Suite and I'm unable to run tests and display the Test/Windows/Test Result Window. The result is a dialog box with the following content : "Exception has been thrown by the target of an invocation". Team Explorer has been installed after Visual Studio 2008 SP1. So I have re-apllied the service pack. Searching the web I found that this error is pretty common but unfortunately, the proposed solutions does not work for me. The problem was never analysed so I decided to give it a try : I reproduced the problem on a computer, attached the process with windbg and start with the basic investigations. Following are the first results : 0:000>!dumpstack OS Thread Id: 0xdb0 (0) Current frame: USER32!NtUserWaitMessage+0x15 ChildEBP RetAddr Caller,Callee 003fec94 75a32674 USER32!DialogBox2+0x222, calling USER32!NtUserWaitMessage 003fecd0 75a3288a USER32!InternalDialogBox+0xe5, calling USER32!DialogBox2 003fecfc 75a6f8d0 USER32!SoftModalMessageBox+0x757, calling USER32!InternalDialogBox 003fed3c 6eb61996 mscorwks!Thread::ReverseLeaveRuntime+0x95, calling mscorwks!_EH_epilog3 003fedb0 75a6fbac USER32!MessageBoxWorker+0x269, calling USER32!SoftModalMessageBox 003fede0 6ea559c3 mscorwks!SetupThreadNoThrow+0x19a, calling mscorwks!_EH_epilog3_catch_GS 003fee24 6eb61d8a mscorwks!HasIllegalReentrancy+0xac, calling mscorwks!_EH_epilog3 003fee30 6ea89796 mscorwks!SimpleComCallWrapper::Release+0x2e, calling mscorwks!CompareExchangeMP 003fee38 6ea0da05 mscorwks!CLRException::HandlerState::CleanupTry+0x16, calling mscorwks!GetCurrentSEHRecord 003fee44 6ea0c9c0 mscorwks!Thread::EnablePreemptiveGC+0xf, calling mscorwks!Thread::CatchAtSafePoint 003fee4c 6ea8a241 mscorwks!Unknown_Release_Internal+0x24d, calling mscorwks!GCHolder<1,0,0>::Pop 003fee50 6ea0c86c mscorwks!_EH_epilog3_catch_GS+0xa, calling mscorwks!__security_check_cookie 003fee54 6ea8a24c mscorwks!Unknown_Release_Internal+0x258, calling mscorwks!_EH_epilog3_catch_GS 003fee7c 75a16941 USER32!UserCallWinProcCheckWow+0x13d, calling ntdll!RtlDeactivateActivationContextUnsafeFast 003feed8 7082119e msenv!ATL::CComCritSecLock<ATL::CComCriticalSection>::Lock+0xd, calling ntdll!RtlEnterCriticalSection 003fef08 75a6fe5b USER32!MessageBoxIndirectW+0x2e, calling USER32!MessageBoxWorker 003fef7c 70a1e367 msenv!MessageBoxPVoidW+0xda 003fefd4 70a1db60 msenv!VBDialogCover2+0x11b 003ff01c 70a1e4c0 msenv!VBMessageBox2W+0xf0, calling msenv!VBDialogCover2 003ff044 7087246b msenv!main_GetAppNameW+0xa, calling msenv!GetAppNameInternal 003ff04c 70a1e4f2 msenv!VBMessageBox3W+0x1c, calling msenv!VBMessageBox2W 003ff064 70a1d6d7 msenv!_IdMsgShow+0x362, calling msenv!VBMessageBox3W 003ff0cc 70951841 msenv!TaskDialogCallback+0x7e0, calling msenv!_IdMsgShow 003ff118 6eb20da4 mscorwks!Unknown_QueryInterface+0x230, calling mscorwks!_EH_epilog3_catch_GS 003ff14c 6eb20c43 mscorwks!Unknown_QueryInterface_Internal+0x3d8, calling mscorwks!_EH_epilog3_catch_GS 003ff168 02006ec4 02006ec4, calling 0247a1e8 003ff16c 6ea0c86c mscorwks!_EH_epilog3_catch_GS+0xa, calling mscorwks!__security_check_cookie 003ff198 6eb20562 mscorwks!COMToCLRWorker+0xb34, calling mscorwks!_EH_epilog3_catch_GS 003ff19c 0247a235 0247a235, calling mscorwks!COMToCLRWorker 003ff1c4 7083249f msenv!CVSCommandTarget::ExecCmd+0x937 003ff1e4 7086d5c8 msenv!VsReportErrorInfo+0x11, calling msenv!TaskDialogCallback+0xd8 003ff1f8 7093e65b msenv!CVSCommandTarget::ExecCmd+0x945, calling msenv!VsReportErrorInfo 003ff25c 7081f53a msenv!ATL::CComPtr<IVsLanguageInfo>::~CComPtr<IVsLanguageInfo>+0x24, calling msenv!_EH_epilog3 003ff260 70b18d72 msenv!LogCommand+0x4c, calling msenv!ATL::CComPtr<IVsCodePageSelection>::~CComPtr<IVsCodePageSelection> 003ff264 70b18d77 msenv!LogCommand+0x51, calling msenv!_EH_epilog3 003ff280 70a4fd0e msenv!CMsoButtonUser::FClick+0x1d1, calling msenv!CVSCommandTarget::ExecCmd 003ff2f4 70823a87 msenv!CTLSITE::QueryInterface+0x16 003ff31c 70cb7d4d msenv!TBCB::FNotifyFocus+0x204 003ff35c 70ce5fda msenv!TB::NotifyControl+0x101 003ff3bc 709910f6 msenv!TB::FRequestFocus+0x4ed, calling msenv!TB::NotifyControl 003ff414 708254ba msenv!CMsoButtonUser::FEnabled+0x3d, calling msenv!GetQueryStatusFlags 003ff428 7086222a msenv!TBC::FAutoEnabled+0x24 003ff43c 7098e1eb msenv!TB::LProcessInputMsg+0xdb4 003ff458 6bec1c49 (MethodDesc 0x6bcd7f54 +0x89 System.Windows.Forms.Form.DefWndProc(System.Windows.Forms.Message ByRef)), calling 6be3b738 003ff50c 70823ab0 msenv!FPtbFromSite+0x16 003ff520 70991c43 msenv!TB::PtbParent+0x25, calling msenv!FPtbFromSite 003ff52c 708dda49 msenv!TBWndProc+0x2da 003ff588 0203d770 0203d770, calling 0247a1e8 003ff598 70822a70 msenv!CPaneFrame::Release+0x118, calling msenv!_EH_epilog3 003ff5b0 75a16238 USER32!InternalCallWinProc+0x23 003ff5dc 75a168ea USER32!UserCallWinProcCheckWow+0x109, calling USER32!InternalCallWinProc 003ff620 75a16899 USER32!UserCallWinProcCheckWow+0x6a, calling ntdll!RtlActivateActivationContextUnsafeFast 003ff654 75a17d31 USER32!DispatchMessageWorker+0x3bc, calling USER32!UserCallWinProcCheckWow 003ff688 70847f2b msenv!CMsoComponent::FPreTranslateMessage+0x72, calling msenv!MainFTranslateMessage 003ff6b4 75a17dfa USER32!DispatchMessageW+0xf, calling USER32!DispatchMessageWorker 003ff6c4 70831553 msenv!EnvironmentMsgLoop+0x1ea, calling USER32!DispatchMessageW 003ff6f8 708eb9bd msenv!CMsoCMHandler::FPushMessageLoop+0x86, calling msenv!EnvironmentMsgLoop 003ff724 708eb94d msenv!SCM::FPushMessageLoop+0xb7 003ff74c 708eb8e9 msenv!SCM_MsoCompMgr::FPushMessageLoop+0x28, calling msenv!SCM::FPushMessageLoop 003ff768 708eb8b8 msenv!CMsoComponent::PushMsgLoop+0x28 003ff788 708ebe4e msenv!VStudioMainLogged+0x482, calling msenv!CMsoComponent::PushMsgLoop 003ff7ac 70882afe msenv!CVsActivityLogSingleton::Instance+0xdf, calling msenv!_EH_epilog3 003ff7d8 70882afe msenv!CVsActivityLogSingleton::Instance+0xdf, calling msenv!_EH_epilog3 003ff7dc 707e4e31 msenv!VActivityLogStartupEntries+0x42 003ff7f4 7081f63b msenv!ATL::CComPtr<IClassFactory>::~CComPtr<IClassFactory>+0x24, calling msenv!_EH_epilog3 003ff7f8 708b250f msenv!ATL::CComQIPtr<IUnknown,&IID_IUnknown>::~CComQIPtr<IUnknown,&IID_IUnknown>+0x1d, calling msenv!_EH_epilog3 003ff820 708e7561 msenv!VStudioMain+0xc1, calling msenv!VStudioMainLogged 003ff84c 2f32aabc devenv!util_CallVsMain+0xff 003ff878 2f3278f2 devenv!CDevEnvAppId::Run+0x11fd, calling devenv!util_CallVsMain 003ff97c 77533b23 ntdll!RtlpAllocateHeap+0xe73, calling ntdll!_SEH_epilog4 003ff9f0 77536cd7 ntdll!RtlpLowFragHeapAllocFromContext+0x882, calling ntdll!RtlpSubSegmentInitialize 003ffa10 7753609f ntdll!RtlNtStatusToDosError+0x3b, calling ntdll!RtlNtStatusToDosErrorNoTeb 003ffa14 775360a4 ntdll!RtlNtStatusToDosError+0x40, calling ntdll!_SEH_epilog4 003ffa40 775360a4 ntdll!RtlNtStatusToDosError+0x40, calling ntdll!_SEH_epilog4 003ffa44 75bd2736 kernel32!LocalBaseRegOpenKey+0x159, calling ntdll!RtlNtStatusToDosError 003ffa48 75bd2762 kernel32!LocalBaseRegOpenKey+0x22a, calling kernel32!_SEH_epilog4 003ffac4 75bd2762 kernel32!LocalBaseRegOpenKey+0x22a, calling kernel32!_SEH_epilog4 003ffac8 75bd28c9 kernel32!RegOpenKeyExInternalW+0x130, calling kernel32!LocalBaseRegOpenKey 003ffad8 75bd28de kernel32!RegOpenKeyExInternalW+0x211 003ffae0 75bd28e5 kernel32!RegOpenKeyExInternalW+0x21d, calling kernel32!_SEH_epilog4 003ffb04 6f282e2b MSVCR90!_unlock+0x15, calling ntdll!RtlLeaveCriticalSection 003ffb14 75bd2642 kernel32!BaseRegCloseKeyInternal+0x41, calling ntdll!NtClose 003ffb28 75bd25d0 kernel32!RegCloseKey+0xd4, calling kernel32!_SEH_epilog4 003ffb5c 75bd25d0 kernel32!RegCloseKey+0xd4, calling kernel32!_SEH_epilog4 003ffb60 2f321ea4 devenv!DwInitSyncObjects+0x340 003ffb90 2f327bf4 devenv!WinMain+0x74, calling devenv!CDevEnvAppId::Run 003ffbac 2f327c68 devenv!License::GetPID+0x258, calling devenv!WinMain 003ffc3c 75bd3677 kernel32!BaseThreadInitThunk+0xe 003ffc48 77539d72 ntdll!__RtlUserThreadStart+0x70 003ffc88 77539d45 ntdll!_RtlUserThreadStart+0x1b, calling ntdll!__RtlUserThreadStart 0:000> !pe -nested Exception object: 050aae9c Exception type: System.Reflection.TargetInvocationException Message: Exception has been thrown by the target of an invocation. InnerException: System.NullReferenceException, use !PrintException 050aac64 to see more StackTrace (generated): SP IP Function 003FEC2C 6D2700F7 mscorlib_ni!System.RuntimeType.CreateInstanceSlow(Boolean, Boolean)+0x57 003FEC5C 6D270067 mscorlib_ni!System.RuntimeType.CreateInstanceImpl(Boolean, Boolean, Boolean)+0xe7 003FEC94 6D270264 mscorlib_ni!System.Activator.CreateInstance(System.Type, Boolean)+0x44 003FECA4 6AD02DAF Microsoft_VisualStudio_Shell_9_0_ni!Microsoft.VisualStudio.Shell.Package.CreateToolWindow(System.Type, Int32, Microsoft.VisualStudio.Shell.ProvideToolWindowAttribute)+0x67 003FED30 6AD0311B Microsoft_VisualStudio_Shell_9_0_ni!Microsoft.VisualStudio.Shell.Package.CreateToolWindow(System.Type, Int32)+0xb7 003FED58 6AD02D12 Microsoft_VisualStudio_Shell_9_0_ni!Microsoft.VisualStudio.Shell.Package.FindToolWindow(System.Type, Int32, Boolean, Microsoft.VisualStudio.Shell.ProvideToolWindowAttribute)+0x7a 003FED88 6AD02D39 Microsoft_VisualStudio_Shell_9_0_ni!Microsoft.VisualStudio.Shell.Package.FindToolWindow(System.Type, Int32, Boolean)+0x11 003FED94 02585E30 Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage.InitToolWindowVariable[[System.__Canon, mscorlib]](System.__Canon ByRef, System.String, Boolean)+0x58 003FEDD0 02585DBE Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage.InitToolWindowVariable[[System.__Canon, mscorlib]](System.__Canon ByRef, System.String)+0x36 003FEDE4 02585D32 Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage.ShowToolWindow[[System.__Canon, mscorlib]](System.__Canon ByRef, System.String, Boolean)+0x3a 003FEE00 02585AB4 Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage.OpenTestResultsToolWindow()+0x2c 003FEE10 02585A6E Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage.OnMenuViewTestResults(System.Object, System.EventArgs)+0x6 003FEE18 6CD4F993 System_ni!System.ComponentModel.Design.MenuCommand.Invoke()+0x43 003FEE40 6CD4F9D4 System_ni!System.ComponentModel.Design.MenuCommand.Invoke(System.Object)+0x8 003FEE48 6AD000FA Microsoft_VisualStudio_Shell_9_0_ni!Microsoft.VisualStudio.Shell.OleMenuCommandService.Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget.Exec(System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)+0x11a 003FEEA0 6AD03FB8 Microsoft_VisualStudio_Shell_9_0_ni!Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget.Exec(System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)+0x44 StackTraceString: <none> HResult: 80131604 0:000> !PrintException 050aac64 Exception object: 050aac64 Exception type: System.NullReferenceException Message: Object reference not set to an instance of an object. InnerException: <none> StackTrace (generated): SP IP Function 003FE660 078E60BE Microsoft_VisualStudio_TeamSystem_Integration!Microsoft.VisualStudio.TeamSystem.Integration.TcmResultsPublishManager..ctor(Microsoft.VisualStudio.TeamSystem.Integration.ResultsPublishManager)+0xc6 003FE674 078E5C91 Microsoft_VisualStudio_TeamSystem_Integration!Microsoft.VisualStudio.TeamSystem.Integration.ResultsPublishManager..ctor(Microsoft.VisualStudio.TeamSystem.Integration.TeamFoundationHostHelper)+0x59 003FE684 078E2FA0 Microsoft_VisualStudio_TeamSystem_Integration!Microsoft.VisualStudio.TeamSystem.Integration.VsetServerHelper..ctor(System.IServiceProvider)+0x50 003FE6A4 078E2E90 Microsoft_VisualStudio_TeamSystem_Common!Microsoft.VisualStudio.TeamSystem.Integration.Client.VsetHelper.InitializeThrow(System.IServiceProvider)+0x20 003FE6B8 078E2E2A Microsoft_VisualStudio_TeamSystem_Common!Microsoft.VisualStudio.TeamSystem.Integration.Client.VsetHelper.InitializeHelper(System.IServiceProvider)+0x22 003FE6E0 078E2DEC Microsoft_VisualStudio_TeamSystem_Common!Microsoft.VisualStudio.TeamSystem.Integration.Client.VsetHelper.CreateVsetHelper(System.IServiceProvider)+0x1c 003FE6F0 078E2DAC Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage.get_VsetHelper()+0x14 003FE6F8 02586BBE Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.ResultsToolWindow..ctor()+0x9f6 003FE798 02585F8A Microsoft_VisualStudio_QualityTools_TestCaseManagement!Microsoft.VisualStudio.TestTools.TestCaseManagement.ResultToolWindowHost..ctor()+0x1a StackTraceString: <none> HResult: 80004003 In order to be able to continue the analysis, we need to get the parameters to see what is going on. I also tried to run devenv.exe with the /log switch. No error in the log after reproducing the problem. Finally, If Team Explorer is removed from the system, the problem goes away. Any help appreciated. TIA. Olivier.

    Read the article

  • GDI+ crashes when loading PNG from IStream

    - by konforce
    I wrote something to load PNG files from a custom C++ IStream via GDI+. It worked great until I ran it on Vista machines. Crashes every time. When compiled on VS 2008, I found that inserting code into the IStream::AddRef method, such as a cout, made the problem go away. When compiling with VS 2010, it still crashes regardless of that. I stripped the program down to its basics. I copied a FileStream straight from Microsoft's documentation. It can load PNGs when using Bitmap::FromFile. It can load JPEGs, GIFs, and BMPs via FromFile or FromStream. So in short: on Vista, PNG files loaded via Bitmap::FromStream crash. #pragma comment(lib, "gdiplus.lib") #include <iostream> #include <objidl.h> #include <gdiplus.h> class FileStream : public IStream { public: FileStream(HANDLE hFile) { _refcount = 1; _hFile = hFile; } ~FileStream() { if (_hFile != INVALID_HANDLE_VALUE) { ::CloseHandle(_hFile); } } public: HRESULT static OpenFile(LPCWSTR pName, IStream ** ppStream, bool fWrite) { HANDLE hFile = ::CreateFileW(pName, fWrite ? GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, NULL, fWrite ? CREATE_ALWAYS : OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError()); *ppStream = new FileStream(hFile); if(*ppStream == NULL) CloseHandle(hFile); return S_OK; } virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject) { if (iid == __uuidof(IUnknown) || iid == __uuidof(IStream) || iid == __uuidof(ISequentialStream)) { *ppvObject = static_cast<IStream*>(this); AddRef(); return S_OK; } else return E_NOINTERFACE; } virtual ULONG STDMETHODCALLTYPE AddRef(void) { return (ULONG)InterlockedIncrement(&_refcount); } virtual ULONG STDMETHODCALLTYPE Release(void) { ULONG res = (ULONG) InterlockedDecrement(&_refcount); if (res == 0) delete this; return res; } // ISequentialStream Interface public: virtual HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead) { ULONG local_pcbRead; BOOL rc = ReadFile(_hFile, pv, cb, &local_pcbRead, NULL); if (pcbRead) *pcbRead = local_pcbRead; return (rc) ? S_OK : HRESULT_FROM_WIN32(GetLastError()); } virtual HRESULT STDMETHODCALLTYPE Write(void const* pv, ULONG cb, ULONG* pcbWritten) { BOOL rc = WriteFile(_hFile, pv, cb, pcbWritten, NULL); return rc ? S_OK : HRESULT_FROM_WIN32(GetLastError()); } // IStream Interface public: virtual HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE CopyTo(IStream*, ULARGE_INTEGER, ULARGE_INTEGER*, ULARGE_INTEGER*) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE Commit(DWORD) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE Revert(void) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE Clone(IStream **) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove, DWORD dwOrigin, ULARGE_INTEGER* lpNewFilePointer) { DWORD dwMoveMethod; switch(dwOrigin) { case STREAM_SEEK_SET: dwMoveMethod = FILE_BEGIN; break; case STREAM_SEEK_CUR: dwMoveMethod = FILE_CURRENT; break; case STREAM_SEEK_END: dwMoveMethod = FILE_END; break; default: return STG_E_INVALIDFUNCTION; break; } if (SetFilePointerEx(_hFile, liDistanceToMove, (PLARGE_INTEGER) lpNewFilePointer, dwMoveMethod) == 0) return HRESULT_FROM_WIN32(GetLastError()); return S_OK; } virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg, DWORD grfStatFlag) { if (GetFileSizeEx(_hFile, (PLARGE_INTEGER) &pStatstg->cbSize) == 0) return HRESULT_FROM_WIN32(GetLastError()); return S_OK; } private: volatile HANDLE _hFile; volatile LONG _refcount; }; #define USE_STREAM int main() { Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Gdiplus::Bitmap *bmp; #ifndef USE_STREAM bmp = Gdiplus::Bitmap::FromFile(L"test.png", false); if (!bmp) { std::cerr << " Unable to open image file." << std::endl; return 1; } #else IStream *s; if (FileStream::OpenFile(L"test.png", &s, false) != S_OK) { std::cerr << "Unable to open image file." << std::endl; return 1; } bmp = Gdiplus::Bitmap::FromStream(s, false); #endif std::cout << "Image is " << bmp->GetWidth() << " by " << bmp->GetHeight() << std::endl; Gdiplus::GdiplusShutdown(gdiplusToken); #ifdef USE_STREAM s->Release(); #endif return 0; } Tracing and debugging, shows that it does make some calls to the IStream class. It crashes inside of lastResult = DllExports::GdipCreateBitmapFromStream(stream, &bitmap); from GdiPlusBitmap.h, which is a static inline wrapper over the flat API. Other than the reference counting, the only IStream methods it calls is stat (for file size), read, and seek. Call stack looks like: ntdll.dll!_DbgBreakPoint@0() + 0x1 bytes ntdll.dll!_RtlpBreakPointHeap@4() + 0x28 bytes ntdll.dll!_RtlpValidateHeapEntry@12() + 0x70a3c bytes ntdll.dll!_RtlDebugFreeHeap@12() + 0x9a bytes ntdll.dll!@RtlpFreeHeap@16() + 0x13cdd bytes ntdll.dll!_RtlFreeHeap@12() + 0x2e49 bytes kernel32.dll!_HeapFree@12() + 0x14 bytes ole32.dll!CRetailMalloc_Free() + 0x1c bytes ole32.dll!_CoTaskMemFree@4() + 0x13 bytes GdiPlus.dll!GpPngDecoder::GetImageInfo() + 0x68 bytes GdiPlus.dll!GpDecodedImage::InternalGetImageInfo() + 0x3c bytes GdiPlus.dll!GpDecodedImage::GetImageInfo() + 0x18 bytes GdiPlus.dll!CopyOnWriteBitmap::CopyOnWriteBitmap() + 0x49 bytes GdiPlus.dll!CopyOnWriteBitmap::Create() + 0x1d bytes GdiPlus.dll!GpBitmap::GpBitmap() + 0x2c bytes I was unable to find anybody else with the same problem, so I assume there's something wrong with my implementation...

    Read the article

< Previous Page | 1 2 3