tags:

views:

275

answers:

3
A: 

Most likely there's something wrong with the reference counting.

When the function exists, the reference count to all interfaces is decremented. The Delphi compiler automatically creates the necessary code to call ICOMEditArticleManager::Release.

Either its implementation is flawed or you are not returning a valid IUnknown interface.

You can try the following:

  • In VC++ set a breakpoint at the implementation of ICOMEditArticleManager::Release
  • In Delphi switch to the CPU mode and single-step through the disassembled code.

That way you should find the cause or at least narrow it down.

DR
I've edited my original post, see last part there.
rufusz
+2  A: 

Should be

function  CreateManager(bstrName: wideString; OUT pEditArticleManager: ICOMEditArticleManager): HResult; stdcall; external 'SCBLEditArticle.dll';

Notice the "OUT", you somehow dropped a indirection. (an interface is only one *, not two)

Marco van de Voort
In the .idl if I declare it with one * HRESULT CreateManager([in]...,[out]ICOMEditArticleManager* pEdit..)I get a compiler error that out pointers should use double indirection :error MIDL2284 : [out] interface pointers must use double indirection
rufusz
Rufus, you have to get it right in both languages. You already had it right in C++. Your Delphi code was wrong. The C++ needs two stars because interfaces are just ordinary classes there. You need a pointer to the object, and then a pointer to the pointer. Delphi interfaces are already references, so you just need one additional reference, which you get with `out`. The IDL `[out]` doesn't actually *do* anything; it's just documentation.
Rob Kennedy
+1  A: 

It's odd you try to declare STDMETHODIMP CreateManager within your class in C++, this may be causing trouble.

Also COM provides a standard way of having an object-factory (class-object), which responds to CoCreateInstance calls, you may want to have a look at that.

Stijn Sanders
Can you elaborate on this? CoCreateInstance should be called from Delphi to create a COM object? Or how?
rufusz
Declaring the function in the class is definitely causing problems; Rufus mentions that making it a standalone function makes the crash go away. He has *two* problems, and both need fixing before things will work. He needs to make the C++ function a non-member (or static member), and he needs to use `out` on the Delphi declaration.
Rob Kennedy
To elaborate: you mention you have a DLL written in C++? Does it contain a TypeLibrary, does it export DllGetClassObject http://msdn.microsoft.com/en-us/library/ms680760(VS.85).aspx (preferably using a framework like ATL)? Is it properly registered in the registry (HKEY_CLASSES_ROOT\CLSID and other)? Then CoCreateInstance will do the work for you of loading and linking the DLL and creating an object.
Stijn Sanders