[C++> C#]Comment régler problème de type TCHAR*/string ?
Je veux appeler une fonction d'une dll écrite en C++ (compilé avec VS .
net). Mais ca ne fonctionne pas ?
Je suis débutant en C# et je pense qu'il y a un pb de type entre "TCHAR*" et "string"
Code:
1 2 3 4 5 6 7 8 9 10
|
//déclaration C++ :
int PrinterSendFileTo(TCHAR* printerName, TCHAR* filePath)
//déclaration C# :
[DllImport("DMIPrintMonitor")]
static extern int PrinterSendFileTo(string printerName, string filePath);
//appel C#
PrinterSendFileTo("EPSONC82",openFileDialog1.FileName); |
Je fais la même chose en delphi, et ca fonctionne :
/
Code:
1 2 3 4 5
| /déclaration delphi :
function PrinterSendFileTo(printerName: pWideChar;filePath:pWideChar):integer; cdecl; external 'DMIPrintMonitor.dll' name 'PrinterSendFileTo';
//appel delphi
PrinterSendFileTo(pWideChar(fPrinterName),pWideChar(FFileName)); |
Re: [C++> C#]Comment régler problème de type TCHAR*/strin
essai avec ça :
Code:
1 2 3 4 5 6 7 8 9
|
//déclaration C# :
[DllImport("DMIPrintMonitor",CallingConvention=CallingConvention.Cdecl)]
static extern int PrinterSendFileTo(
[MarshalAs(UnmanagedType.ByValTStr)]
string printerName,
[MarshalAs(UnmanagedType.ByValTStr)]
string filePath); |