473,480 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C++ interop help

I have an ATL DLL that hosts a COM object. Without managed extensions the
object compiles and works fine. Now with some assistance from Will DePalo
(on a different thread in this group) I figured out how to add CLR support
to my object and how to call into managed code. The code and the calls work
, however when the host application drops the reference to my COM object (
specifically to a class that has clr support ) the ATL framework throws an
errorr and returns RPC_S_WRONG_KIND_OF_BINDING while the reference is being
dropped.

If I comment out the clr code and remove the clr flag, the code executes
fine, If I add clr support to the module but make no clr calls I get the
error. So it appears that simply adding clr support to an ALT object is
causing the problem. The ATL class is defined as a single threaded IDispath
implementation using the ATL libraries (sample below):

class ATL_NO_VTABLE CCSharpMEVT :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CCSharpMEVT, &CLSID_CSharpMEVT>,
public ICSharpMEVT,
public IDispatchImpl<_iMEVT, &__uuidof(_iMEVT), &LIBID_MEVT, /* wMajor
= */ 56, /* wMinor = */ 3>

Has anyone seen this before ? The COM string error equates to "The string
binding is invalid."

Thanks in advance for any help or advice

Robert


Dec 20 '05 #1
4 1273
"Robert Ginsburg" <ro*************@ver3.com> wrote
I have an ATL DLL that hosts a COM object. Without managed extensions the
object compiles and works fine. Now with some assistance from Will DePalo
(on a different thread in this group) I figured out how to add CLR support
to my object and how to call into managed code. The code and the calls work
, however when the host application drops the reference to my COM object
( specifically to a class that has clr support ) the ATL framework throws
an errorr and returns RPC_S_WRONG_KIND_OF_BINDING while the reference is
being dropped.


I think, I've seen something like this. You're probably calling into managed
code under the loader lock. Do you have the call stack for the exception?
IIRC the .NET DLLs ship with private symbols (anyway just grab it
from the symbol server)

From my very limited understanding you must not call into managed
code under the loader lock. However, AFAICT this is exactly what
happens when you mix native and managed code. Usually, you'd
get a hint in the debugger from the MDA. But in some cases
(which one I don't know), it just fails with an OS exception
with the code you mention.

Some of the ATL code is precompiled without /clr. There are
some globals which need initialization/destruction. For native code
that's implemented in the CRT init/cleanup code called from
the entrypoint. The constructors/destructors must not call into
managed code.

I guess, that is what happens (e.g. on ClassFactory Release).
But the MS folks would probably need a full repro case.

-hg
Dec 22 '05 #2
> From my very limited understanding you must not call into managed
code under the loader lock. However, AFAICT this is exactly what
happens when you mix native and managed code. Usually, you'd
get a hint in the debugger from the MDA. But in some cases
(which one I don't know), it just fails with an OS exception
with the code you mention.

In fact, it seems digged something up when I ran into the issue myself
(I guess I'm getting old).
Anyway, if my notes are correct, the managed CRT cleans up
state (e.g. atexit, dtors of globals & local statics etc.) in hooks
provided by the EE (DomainUnload and ProcessExit) event
of the AppDomain.
However, I believe, this requires some cooperation of the main
app which should call CorExitProcess if the CLR EE is
active (the VC++ CRT does that for a while).

If the host does not play nice, the runtime will eventually call
the cleanup code from the DllMain event under the loader lock.
Executing managed code might hang the process. However,
if the offending managed method has been JITted already, you get
the error above (that sounds like very odd behavior and is
probably a CLR bug)

In case anyone's interested I have a small repro case.

-hg
Dec 22 '05 #3
"Holger Grund" <ho**********@remove.ix-n.net> wrote

FWIW, I've bugged it here:

http://lab.msdn.microsoft.com/Produc...3-78508988cc72

-hg
Dec 22 '05 #4
Thanks for responding so completely, yours is the only response from several
postings I made. I have come up with a work around that seems to function
well, and is pretty simple. Simply dont do it, by that I mean dont add clr
support to anything that inherits from the ATL framework. Create a "proxy"
as a different class (make sure to put it in a separate modeule and dont mix
the header or source files), add CLR support to that class, static or
instance methods seem to work fine. Call from the ATL object through the
proxy functions and it all behaves nicely.

-Robert

"Holger Grund" <ho**********@remove.ix-n.net> wrote in message
news:OH**************@TK2MSFTNGP14.phx.gbl...
"Holger Grund" <ho**********@remove.ix-n.net> wrote

FWIW, I've bugged it here:

http://lab.msdn.microsoft.com/Produc...3-78508988cc72

-hg

Dec 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2228
by: Jack Menendez | last post by:
I have a forms based plugin architecture using C# that includes help files using MSHelpServices. However, my strongly named assemblies cannot be created because Interop.MSHelpServices is not strongly...
1
1440
by: Anand G | last post by:
We are trying to find help on the Interop classes for interfacing with Word/Excel to create Word document with tables/charts etc. We are not able find any help on the MSDN and on google for...
20
3157
by: Razzie | last post by:
Hey all, I'm really going through a small hell right now - I've completely lost it :) I made a project, using two interop libraries from exchange (created them as in this msdn article:...
6
5882
by: Sudha | last post by:
Hi All, I am trying to use COM DLL in my C#. I have added this DLL in referance and all interface are working fine. I have one issue in calling function decleared like: void...
1
2265
by: Shiro | last post by:
Hi I have read the various postings relating to Interop strong name signing and cannot find an example similar to mine. I have stringly named my AxInterops/Interops and they all work just...
7
10936
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
0
1581
by: R Reyes | last post by:
ISSUE (reposted) =========================== Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? For many people, they say they add the...
0
1343
by: Tobester | last post by:
Hi I am having problems accessing a vb6 dll from ASP.Net. The vb6 dll is registered. I have then created an interop file using tlbimp. The interop has been added to the GAC. I can run the...
0
2029
by: Tina | last post by:
I've gotten this before where it says there is a problem with Interop.MSDASC but I can't remember what causes this. This is a 1.1 app I'm trying to debug in vs2005. It was running yesterday just...
2
10688
by: RodneyAnonymous | last post by:
I've got some code for composing an e-mail from the contents of an RTF box. The first time I execute it, everything works fine. If I close my app and then re-run it, however, I always receive the...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.