Creating a dll in C# and calling it from VC6 ============================================ 1) Using VS2005 create a C# dll. 2) 3) Add the follwing code to the dll's namespace: // Since the .NET Framework interface and coclass have to behave as // COM objects, we have to give them guids. And, we have to expose // them via an attribute. [ComVisible(true)] [Guid("DBE0E8C4-1C61-41f3-B6A4-4E2F353D3D05")] public interface ISharpServicesInterface { int ShowMessage(string sData); } [ComVisible(true)] [Guid("C6659361-1625-4746-931C-36014B146679")] public class ISharpServicesInterfaceImplementation : ISharpServicesInterface { public int ShowMessage(string s) { string ss = string.Format("Hello {0} ", s); System.Windows.Forms.MessageBox.Show(ss); return 100; } } 4) Build the solution the execute the following on the command line: Regasm /codebase /tlb c:\tmp\sharp\bin\debug\sharp.dll You'll have to adjust the path and name to suit. This fills in the appropriate registry GUID entrys. 5) Using Visual Studio V6 create dialog based project. 6) Add a button, label it 'Call C#DLL', and in its handler add the following code: ISharpServicesInterface *cpi = NULL; int retval = 1; // Initialize COM and create an instance of the InterfaceImplementation class: CoInitialize(NULL); HRESULT hr = CoCreateInstance(CLSID_ISharpServicesInterfaceImplementation, NULL, CLSCTX_INPROC_SERVER, IID_ISharpServicesInterface, reinterpret_cast(&cpi)); if (FAILED(hr)) { printf("Couldn't create the instance!... 0x%x\n", hr); } else { printf("Calling function.\n"); fflush(stdout); if( cpi->ShowMessage("Darren") == 100 ) retval = 0; printf("Returned from function.\n"); } cpi->Release(); cpi = NULL; // Be a good citizen and clean up COM: CoUninitialize(); 7) In the header somwhere you'll need to add the following: #include /* Adjust path to suit. This will create temp files with the required CLSID and IIDs needed to query COM. */ #import "c:\tmp\sharp\bin\debug\sharp.tlb" no_namespace named_guids