Ewa
Ewa

Reputation: 31

C# Dllimport problems in Visual Studio 2010 .NET framework 4

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 :

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.

Upvotes: 1

Views: 5613

Answers (3)

fatih
fatih

Reputation: 1

you can use WIA for capture or scan image

Upvotes: 0

Ewa
Ewa

Reputation: 31

Ok. Thanks to you comments I managed to solve my problem. I used website

and I changed in c# code

[DllImport("FindCaptureDevice.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern void GetDeviceName(StringBuilder response, int index);

and I call it with

StringBuilder tempDevice = new StringBuilder(255);
                GetDeviceName(tempDevice, DevCount);

and in c++ code I wrote

void GetDeviceName(char * outChr, int index)
{
    GetDeviceNameAux(index, outChr);
}

and I copy the data to outChr with strcpy_s method.

Upvotes: 2

Aliostad
Aliostad

Reputation: 81700

Change the return type to StringBuilder:

[DllImport("FindCaptureDevice.dll")]
public static extern StringBuilder GetDeviceName(int index);

Upvotes: 1

Related Questions