से पास स्ट्रिंग पास मैं सी # से सी डीएलएल तक एक स्ट्रिंग पास करने की कोशिश कर रहा हूं। मैंने जो पढ़ा है, उससे .NET को मेरे लिए स्ट्रिंग से char * में रूपांतरण करना चाहिए, हालांकि मुझे "त्रुटि CS1503: तर्क '1' मिलता है: 'स्ट्रिंग' से 'char *' में परिवर्तित नहीं किया जा सकता है" क्या कोई मुझे सलाह दे सकता है कि मैं कहां हूं गलत हो गया है? धन्यवाद।सी # से सी डीएलएल
सी # कोड
[DllImport("Source.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static unsafe extern bool StreamReceiveInitialise(char* filepath);
const string test = "test";
// This method that will be called when the thread is started
public void Stream()
{
if (StreamReceiveInitialise(test))
{
}
}
सी DLL
extern "C"
{
__declspec(dllexport) bool __cdecl StreamReceiveInitialise(char* filepath);
}
क्यों असुरक्षित के रूप में StreamReceiveInitialise घोषित? अब आपको स्ट्रिंग के बजाए एक char * पास करने की आवश्यकता है। – diggingforfire
मैंने अब असुरक्षित हटा दिया है और उत्तर 1 में दिखाए गए अनुसार उपयोग कर रहा हूं। – integra753