Typecasting string to char * in C#
-
Hi, Sorry if this is too basic, Can you please let me know how to typecast string to char* in C#? I need this as Im calling a managed DLL function. Thanks Vikas
-
Hi, Sorry if this is too basic, Can you please let me know how to typecast string to char* in C#? I need this as Im calling a managed DLL function. Thanks Vikas
Vikas K. wrote:
Im calling a managed DLL function
I don't think that you will be using pointers much in managed environment.
Vikas K. wrote:
string to char*
If you want to call some native C++ functions you can use Marshal.StringToHGlobalAnsi[^] method.
*jaans
-
Actually from C# I'm calling an unmanaged MFC DLL. MFC DLL has an API for example:
int fnSetMonitorNo(char* m_MonitorNo) int fnGetMonitorNo(char* m_MonitorNo)
If I pass char* to the DLL, it will see the MonitorNo. I tried to do in C# as follows[DllImport("OfficeCTE.dll")] public static extern unsafe int fnSetMonitorNo([MarshalAs(UnmanagedType.LPStr)]string arg1); [DllImport("OfficeCTE.dll")] public static extern unsafe int fnGetMonitorNo([MarshalAs(UnmanagedType.LPStr)]string arg1);
But it didn't work. How can this be done?