Problem accessing C# dll in VC 6.0
-
Hi, i have a small problem i have a csharp dll built in VS2005.I have to access the functions from this dll in my VC++ project done in VC 6.0.My VC project is not able to identify my C# namespace and class.I dont get what the problem is. Please do have a look at my c# code and VC Project code and do let me know if im making some mistake.I have also pasted the errors that i am getting. please do help me...i'm not able to understand the problem. :( C# code: using System; using System.Collections.Generic; using System.Text; namespace TestDllCsharp { public class Class1 { public void PrintMessage () { System.Windows.Forms.MessageBox.Show("Test"); } } } VC Project : #import "TestDllCsharp.tlb" using namespace TestDllCsharp; #include void main() { HRESULT hresult; CLSID clsid; CoInitialize(NULL); hresult=CLSIDFromProgID(OLESTR("TestDllCsharp.Class1"),&clsid); if (hresult == 0) { _Class1 *t; hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_Class1),(LPVOID *) &t); t->PrintMessage (); CoUninitialize(); } } I get errors like : error C2065: '_Class1' : undeclared identifier error C2065: 't' : undeclared identifier Thnx in advance.
-
Hi, i have a small problem i have a csharp dll built in VS2005.I have to access the functions from this dll in my VC++ project done in VC 6.0.My VC project is not able to identify my C# namespace and class.I dont get what the problem is. Please do have a look at my c# code and VC Project code and do let me know if im making some mistake.I have also pasted the errors that i am getting. please do help me...i'm not able to understand the problem. :( C# code: using System; using System.Collections.Generic; using System.Text; namespace TestDllCsharp { public class Class1 { public void PrintMessage () { System.Windows.Forms.MessageBox.Show("Test"); } } } VC Project : #import "TestDllCsharp.tlb" using namespace TestDllCsharp; #include void main() { HRESULT hresult; CLSID clsid; CoInitialize(NULL); hresult=CLSIDFromProgID(OLESTR("TestDllCsharp.Class1"),&clsid); if (hresult == 0) { _Class1 *t; hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_Class1),(LPVOID *) &t); t->PrintMessage (); CoUninitialize(); } } I get errors like : error C2065: '_Class1' : undeclared identifier error C2065: 't' : undeclared identifier Thnx in advance.
You cannot directly access a C# class in VC. You will need to create a COM Callable Wrapper (CCW) from the C# class. Look at the documentation on how to create CCWs. Then you can access it from VC like you access a COM component.
«_Superman_»
-
Hi, i have a small problem i have a csharp dll built in VS2005.I have to access the functions from this dll in my VC++ project done in VC 6.0.My VC project is not able to identify my C# namespace and class.I dont get what the problem is. Please do have a look at my c# code and VC Project code and do let me know if im making some mistake.I have also pasted the errors that i am getting. please do help me...i'm not able to understand the problem. :( C# code: using System; using System.Collections.Generic; using System.Text; namespace TestDllCsharp { public class Class1 { public void PrintMessage () { System.Windows.Forms.MessageBox.Show("Test"); } } } VC Project : #import "TestDllCsharp.tlb" using namespace TestDllCsharp; #include void main() { HRESULT hresult; CLSID clsid; CoInitialize(NULL); hresult=CLSIDFromProgID(OLESTR("TestDllCsharp.Class1"),&clsid); if (hresult == 0) { _Class1 *t; hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_Class1),(LPVOID *) &t); t->PrintMessage (); CoUninitialize(); } } I get errors like : error C2065: '_Class1' : undeclared identifier error C2065: 't' : undeclared identifier Thnx in advance.