Ben Voigt [C++ MVP]
6/13/2007 6:00:00 AM
>> But it does seem strange that when importing a tlb into non-CLR C++, it
>> creates a .NET assembly. Are you invoking tlbimp directly, or using
>> #import?
>>
>>>
>>> Alex
>>
>
> I have a C# class there is only one class with only one method and one
> Form:
>
> namespace Cs_CLR_DLLns
> {
> public class Class1
> {
> public int OpenForm1()
> {
> Form1 f1 = new Form1();
> f1.Show();
>
> return 2;
> }
> }
> }
>
> AssemblyInfo.cs is:
>
> [assembly: AssemblyTitle("Cs_CLR_DLL")]
> [assembly: AssemblyDescription("")]
> [assembly: AssemblyConfiguration("")]
> [assembly: AssemblyCompany("UKA")]
> [assembly: AssemblyProduct("Cs_CLR_DLL")]
> [assembly: AssemblyCopyright("Copyright 2007")]
> [assembly: AssemblyTrademark("")]
> [assembly: AssemblyCulture("")]
> [assembly: ComVisible(true)]
> [assembly: Guid("32fa638b-e5fd-4ab0-aa5f-f34d0cfc4913")]
> [assembly: AssemblyVersion("1.0.0.0")]
> [assembly: AssemblyFileVersion("1.0.0.0")]
>
>
>
> After compiling Cs_CLR_DLL I registered it with
> RegAsm.exe Cs_CLR_DLL.dll /t Cs_CLR_DLL.tlb
>
> I can load Cs_CLR_DLL.tlb in VBA and use it as follows:
> Private Sub CommandButton1_Click()
> Dim tt As New Cs_CLR_DLL.Class1
> Call tt.openform1
> End Sub
>
> But I cannot load Cs_CLR_DLL.tlb in C++ Project.
> I tried :
> 1) #import "D:\\Projects\\Cs_CLR_DLL.tlb"
> 2) #import "D:\\Projects\\Cs_CLR_DLL.dll"
> 3) using "References" dialog:
> There is a Cs_CLR_DLL only in COM tab but
> it does not loads from there. There is a following error:
> "TlbImp : error TI0000 : System.Runtime.InteropServices.COMException -
> Type library MyDLL was exported from a CLR assembly and cannot be
> re-imported as a CLR assembly"
>
> The only possibility is to load a dll by browsing to its location (using
> "references" dialog)
>
> in C++ I call and export it as follows:
> extern "C" {
>
> __declspec(dllexport) int CallFromAV1(){
>
> AFX_MANAGE_STATE(AfxGetStaticModuleState());
> int i = 0;
>
> Cs_CLR_DLLns::Class1 cls1;
> i = cls1.OpenForm1();
>
> return i;};
> }
>
> Old Win32 application is calling CallFromAV1 function.
> As soon as I have Cs_CLR_DLLns::Class1 cls1; in this function the client
> application crashes under win2000 and winXP.
>
> How to properly access classes in Cs_CLR_DLL.dll from C++?
>
> is it possible to create a C++ Dll (that uses .net(C#) Dll with Forms)
> without /clr enabled in C++?
>
> Thank you very much in advance.
I think things are pretty well designed around the other way. Yes, a native
application can call a .NET component via COM... if the native application
defined a COM interface for plugins or whatever, then the .NET application
can implement that interface, and the native app can use it. As far as the
native application seeing the .NET interface, I don't know. I've never had
to do that.