'Get' : cannot convert parameter 1 from 'char *' to 'struct tagSAFEARRAY *'
Code:#include "stdafx.h" #include "tchar.h" #include <comutil.h> #include <string> // Import the type library. //#import "..\ManagedDLL\bin\Debug\ManagedDLL.tlb" raw_interfaces_only #import "C:\Mydot-net-projects\sManagedDLL\sManagedDLL\bin\Debug\sManagedDLL.tlb" using namespace sManagedDLL; int _tmain(int argc, _TCHAR* argv[]) { // Initialize COM. HRESULT hr = CoInitialize(NULL); // Create the interface pointer. ICalculatorPtr pICalc(__uuidof(ManagedClass)); long lResult = 0; std::string str; // Call the Add method. // pICalc->Add(5, 10, &lResult); wprintf(L"The result1 is [%d]\n", pICalc->Add(5, 10)); char p[10]; char *szTemp = new char [1000]; strcpy(szTemp,"Test"); wprintf(L"The result2 is p=[%s]\n",pICalc->Get(szTemp) ); // Uninitialize COM. CoUninitialize(); return 0; }
and in C#
Code:using System; using System.Collections.Generic; using System.Text; namespace sManagedDLL { // Interface declaration. public interface ICalculator { int Add(int Number1, int Number2); string Get(char [] s); }; // Interface implementation. public class ManagedClass : ICalculator { public int Add(int Number1, int Number2) { return Number1 + Number2+3; } public string Get(char[] s) { StringBuilder sBuffer = new StringBuilder(100); return sBuffer.ToString(); } } }




Reply With Quote