I am trying to import a dll written in C++, in my C# application.
The application is supposed to get names of disponible webcams.
It works well in .NET framework 3.5 (gets all names properly) but I have problems with getting names in framework 4. I get something like “„îş” instead.
Here are fragments of my code :
-
c++ dll :
TCHAR GetDeviceName(int index) { char name[255]; GetDeviceNameAux(index, name); TCHAR retVal = (TCHAR)name; return retVal; } -
c# application (that works for framework 3.5)
[DllImport("FindCaptureDevice.dll")] public static extern string GetDeviceName(int index);
I have tried also :
[DllImport("FindCaptureDevice.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern string GetDeviceName(int index);
with different parameters for CallingConvention ans CharSet.
Thanks in advance for any help.
Ok. Thanks to you comments I managed to solve my problem.
I used website
and I changed in c# code
and I call it with
and in c++ code I wrote
and I copy the data to outChr with strcpy_s method.