Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2006

Tip: Looking for answers? Try searching our database.

Com Interop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick Thompson - 14 Nov 2006 17:42 GMT
I have created an invisible OCX control using MFC8.0 (to be loaded by WW
intouch)

I would like to call a .NET2 remoting method from this OCX and realise that
I MUST
not do it directly, VS displays CLR stability warning when I tried running
the control having compiled it with /CLR set

Is it safe to create a .net class, export it as a com object and load it
with cocreate
instance, ps do you know of sample code that does this.

best wishes
"Peter Huang" [MSFT] - 15 Nov 2006 08:11 GMT
Hi Nick,

Currently I understand that you would like to create a .NET class and
expose it to COM and call it from C++.
If I misunderstand, please let me know.

Here I write some code snippet for your reference.
1. .NET Server
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace dotNETServer
{
   [InterfaceType(ComInterfaceType.InterfaceIsDual),ComVisible(true)]
   public interface ITest
   {
       string HelloWorld();
   }
   [ClassInterface(ClassInterfaceType.None),ComVisible(true)]
   public class TestClass :ITest
   {
       #region ITest Members

       public string HelloWorld()
       {
           return "Hello World!";
       }

       #endregion
   }
}

2. C++ client
// TestConsole.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#import "..\\dotNETServer\\bin\\Debug\\dotNETServer.tlb"
#include <comdef.h>
int _tmain(int argc, _TCHAR* argv[])
{
    CoInitialize(NULL);
    dotNETServer::ITestPtr pdotNETServer;
    HRESULT hr    =
pdotNETServer.CreateInstance(__uuidof(dotNETServer::TestClass));
    try
    {
        if FAILED(hr)
        {
            _com_issue_error(hr);
        }
        else
        {
            _bstr_t resultStr = pdotNETServer->HelloWorld();
            printf("%S\n",(LPCWSTR)resultStr);
        }
    }
    catch(_com_error &e)
    {
        printf("%S\n", e.ErrorMessage());
    }
    CoUninitialize();
    return 0;
}

You may have a try and let me know the result.

BTW: here is a link for your reference.
.NET - COM Interoperability
http://www.codeproject.com/dotnet/COM_DOTNET_INTEROP.asp?print=true

Best regards,

Perter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

"Peter Huang" [MSFT] - 20 Nov 2006 03:08 GMT
Hi,

Just want to say Hi, and I was wondering how everything is going.
If anything is unclear, please let me know.
It is my pleasure to be of assistance.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.