Re: Calling .NET COM object from MFC application



So your situation is:

MFC exe calls C# managed DLL which in turn calls other ATL/MFC COM DLLs,
correct?

All the COM and .Net DLLs must be registered on the "clean" machine or they
won't be able to talk to each other (unless you go "Registry Free
COM"--search the MSDN site for "Reg-Free COM").

The managed .Net assembly must be registered with the equivalent of
regasm.exe and the MFC/ATL COM DLLs must be registered with the equivalent
of RegSvr32.exe

Do you have an installer? A VStudio setup project allows you to set a
property on the DLL (Register=vsdrfCOM) to have them registered on install.
This works for MFC/ATL COM servers, and it *might* work for .Net assemblies,
but what it definitely doesn't do for .Net assemblies is trigger the calls
to the "ComRegisterFunctionAttribute" functions. That is, in my .Net
assembly, I do some extra work during the calls to the functions with the
above attribute. On my development machine, if I call Regasm on my .Net
assembly (which is properly configured to "Register for COM interop"), those
functions are called. But they are *not* called on user machines if I set
the (Register=vsdrfCOM) on the installer. To get those functions called
during installation, I had to create CustomActions (Install, Commit,
Rollback, and Uninstall) which would manually execute the following code:

RegistrationServices aRS = new RegistrationServices();
Assembly thisAssembly = Assembly.GetExecutingAssembly();
aRS.RegisterAssembly(thisAssembly, AssemblyRegistrationFlags.None);

Anyway, back to your situation: once you have the various COM/.Net DLLs
properly registered, it should work. If it doesn't, then again, I'll ask,
how are you calling the .Net assembly from your MFC app?

Bob





"Alex" <alsim123@xxxxxxxxxxx> wrote in message
news:1178824423.666793.250660@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks, Bob, for your concern.

I'll describe my project in more detail. I've created in C# COM dll
which calls some "third party" COM server. And by now I've figured,
that my COM I register properly, i.e. my MFC application can call some
test functions from it without problem. The program crashes when I'm
trying to initialize this "third party" COM. At this moment program
crashes. As I understand, I have to register this "third party" COM
on client machine this same way, as registered mine. This sounds
ridiculous, but I cannot find some "third party" .exe file which they
provided us a while ago. What this file did after running it, it
added corresponding reference for this "third party" COM in Add
Reference -> COM tab of my project. And if I'm running my MFC
application on the same machine, where C# COM project has been built,
everything works fine, including call for this "third party" COM.
Somehow as I mentioned before I cannot register this "third party" COM
on a "clean" machine.
Sorry if my explanation was not clear enough. Thanks for you help
again

Alex.


On May 9, 9:54 pm, "Bob Eaton" <pete_dembrow...@xxxxxxxxxxx> wrote:
Did you set the switch in your COM project to "Build", "Register for COM
interop"?

Is the COM interface marked to be ComVisible?

What does your #import statement look like?

Bob

"Alex" <alsim...@xxxxxxxxxxx> wrote in message

news:1178737038.400164.156140@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



Hi, everybody

I wrote MFC application under VS6 and COM server under VS8. My goal
is to call COM functions from this MFC application by importing
corresponding .tlb file.

Everything works fine if I running my MFC application from the same
machine where my .NET COM project was built ( probably because during
the project build corresponding COM is registering on this machine
automatically).

Then I register my COM object on a different machine:
regasm mycom.dll
( by the way, regasm mycom.dll /tlb doesn't work )

and if I'm trying to run the same exe from different machine I'm
getting error message:

Runtime Error!
Program: C:\...\myappl.exe
This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information.

Any idea? Thanks in advance

Alex- Hide quoted text -

- Show quoted text -






.