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.