|
Post by boychan2002 on Jul 21, 2003 15:08:02 GMT -5
I want to call a function defined in c# dll from a vc++ (6.0) client. The c# dll (Class Library) has a Class which is as follows br] using System; using System.Runtime.InteropServices; namespace ClassLibrary3 { public class Class1{ public Class1(){ } public void fn1(){ System.Windows.Forms.MessageBox.Show("abc"); } } } All the function does is show a message box. In the Build properties I set the 'Register for COM interop' as 'True'. And then I created the dll (along with the type library). My VC++ client code looks like this (only the relevant code) br] <stdafx.h> #import "ClassLibrary3.tlb" using namespace ClassLibrary3; <client.cpp> int main(int argc, char* argv[]) { HRESULT hresult; CLSID clsid; CoInitialize(NULL); hresult=CLSIDFromProgID(OLESTR("ClassLibrary3.Class1"),&clsid); _Class1 *t; hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_Class1),(LPVOID *)t); t->fn1(); t->Release (); CoUninitialize(); return 0; } When I compile the VC++ client, it gives the error "error C2039: 'fn1' : is not a member of '_Class1' ". After the compilation, ClassLibrary3.tlh is generated( but ClassLibrary3.tli is not generated). That is the reason the functions in the dll classes are not visible. My question is: Why is the .tli file not being generated? How do I make the Class functions visible to the VC++ client? Eventually I want to open a form in C# dll which has some buttons which perform screen capturing functionality. thanks in advance
|
|
|
Post by Leonardo on Jul 24, 2003 21:25:49 GMT -5
I havent worked with C#, but I guess its the same as using an ActiveX DLL from any other app... like Vb or even a Windows COM compoenent like ADO....
This is what I would try
_Class1 t; t.CreateInstance(__uuidof(Class1)); t->fn1();
|
|