Re: Serious bug in .NET framework 2.0 - IShellLink interface crashes



I didn't see any reply that had a solution.

I was unable to reproduce your problem. I wrote a managed C++ console app
to test it, and created a shortcut to notepad.exe. The code compiled and
ran with 0 errors:

// linktest.cpp : main project file.
#include "stdafx.h"
#include <shlobj.h>
#include <atlbase.h>

using namespace System;
using namespace System::Runtime::InteropServices;

int main(array<System::String ^> ^args)
{
CComPtr<IShellLink> pLink;
CComQIPtr<IPersistFile> pPersist;
HRESULT hr;

hr = pLink.CoCreateInstance(CLSID_ShellLink);
if (FAILED(hr)) return 1;

pPersist = pLink;
if (!pPersist) return 2;

hr = pPersist->Load(OLESTR("c:\\Notepad.lnk"), 0);
if (FAILED(hr)) return 3;

WIN32_FIND_DATA wfd;
WCHAR szPath[MAX_PATH];

hr = pLink->GetPath(szPath, MAX_PATH, &wfd, 0);
if (FAILED(hr)) return 4;

Console::WriteLine(Marshal::PtrToStringUni((IntPtr)szPath));

return 0;
}




"Elmue" <abuse@xxxxxx> wrote in message
news:OyPPmGdUGHA.5900@xxxxxxxxxxxxxxxxxxxxxxx
Hello

Why are you calling CoInitialize(0)? Please tell me you aren't calling
it
from the DLL ...

What should be the problem with CoInitialize ?
As I wrote I call it in the constructor of the managed C++ DLL.

But this is not the cause of the problem.
Because I also tried a completely different code which I found in the
internet which does not use
any C++ code. It used COM import and directly loaded IShellLink from C#
code.

And this code had the same problem although it worked WITHOUT
CoInitialize.

But I already found a solution.
See my other posting !

Elmü


.



Relevant Pages

  • Re: operator new[] fails in DLL when being called from within VB6 process
    ... its initialization graph, it may work one day, and the next day you'll start ... DllMain being called before ole32's DllMain. ... > But btw - calling CoInitialize() in DllMainis actually very forbidden ... >> I can't remember the details, and our DLL is a complex multi-threaded RPC ...
    (microsoft.public.win32.programmer.kernel)
  • Re: operator new[] fails in DLL when being called from within VB6 process
    ... and our DLL is a complex multi-threaded RPC ... importing our standard client/server WINAPI based dlls. ... You would call CoInitialize() in DLL_PROCESS_ATTACH and you would call ... > loaded into a VB6 process? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Calling a Activex control from a DLL
    ... Note that CoInitialize does explicitly state that it cannot be called from the DllMain ... CoInitialize/Unitializein the DLL anyway? ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: CoUninitialize() and CComPtr<> object lifetimes
    ... > seems that the destructor for my CComPtr<> is not being called until ... It does not help that CoInitialize() is being called ... called when the DLL is loaded, and its destructor - when the DLL is ... loaded until CoUninitialize. ...
    (microsoft.public.vc.atl)