Appel API conversion C++ vers C#
Bonjour,
Je souhaite convertir ceci (c++) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class SearchWindow
{
public:
HWND FoundWnd;
TCHAR SearchText[256];
int Type;
};
CStr &window
wcscpy( sw.SearchText, (LPCTSTR)window );
sw.SearchText[255] = '\0';
sw.FoundWnd = NULL;
sw.Type = Type;
BOOL rc = ::EnumWindows( SearchWindowText, (LPARAM)&sw );
BOOL CALLBACK SearchWindowText( HWND hwnd, LPARAM lParam )
{
...
} |
En C#.
J'arrive bien faire l'appel à EnumWindows mais je bloque sur le passage d'une classe via les API, ceci plante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
[StructLayout(LayoutKind.Sequential)]
class SearchWindow
{
public IntPtr handle;
public string searchText;
public int type;
}
[DllImport("coredll.dll")]
static extern int EnumWindows(WNDENUMPROC lpEnumWindow, ref SearchWindow lParam);
static int Callback(IntPtr hwnd, ref SearchWindow lParam)
{
...
}
SearchWindow sw = new SearchWindow();
EnumWindows(Callback, ref sw); |
Merci pour votre aide :)