Custom and P/Invoke pb

  • Thread starter Thread starter Steve B.
  • Start date Start date
S

Steve B.

Hi,

My custom control use some p/Invoke that are in coredll.dll.

One of this call is done each time the control render. It works fine when
running, but Visual Studio crash when I add the control to a form using the
designer, telling me that the coredll.dll is not find.

How can I prevent that ?
I've added DesktopCompatible = true is the xmta file but it does not work.

Thanks,
Steve
 
You have a few choices here...

(1) If you need to be able to make the appropriate p/invoke call within the
designer then you can do something like this.

[DllImport("User32", EntryPoint="GetCapture")]
private static extern IntPtr GetCaptureWin();
[DllImport("Coredll", EntryPoint="GetCapture")]
private static extern IntPtr GetCaptureWinCE();

....

IntPtr hWnd;

if (Environment.OSVersion.Platform == PlatformID.WinCE)
{
hWnd = GetCaptureWinCE();
}
else
{
hWnd = GetCaptureWin();
}

(2) If you don't need to be able to make the appropriate p/invoke call
within the designer then you can either check the Platform and only execute
the code if your running on WinCE, as above but ignoring the "else", or you
can wrap the p/invoke in a try...catch.

try
{
// Device specific code.
}
catch
{
}
 
Thanks,

I just add the test before the call to the api, in order to disable it on
desktop.
It works fine.

Thanks,
Steve

Tim Wilson said:
You have a few choices here...

(1) If you need to be able to make the appropriate p/invoke call within
the
designer then you can do something like this.

[DllImport("User32", EntryPoint="GetCapture")]
private static extern IntPtr GetCaptureWin();
[DllImport("Coredll", EntryPoint="GetCapture")]
private static extern IntPtr GetCaptureWinCE();

...

IntPtr hWnd;

if (Environment.OSVersion.Platform == PlatformID.WinCE)
{
hWnd = GetCaptureWinCE();
}
else
{
hWnd = GetCaptureWin();
}

(2) If you don't need to be able to make the appropriate p/invoke call
within the designer then you can either check the Platform and only
execute
the code if your running on WinCE, as above but ignoring the "else", or
you
can wrap the p/invoke in a try...catch.

try
{
// Device specific code.
}
catch
{
}

--
Tim Wilson
.NET Compact Framework MVP

Steve B. said:
Hi,

My custom control use some p/Invoke that are in coredll.dll.

One of this call is done each time the control render. It works fine when
running, but Visual Studio crash when I add the control to a form using the
designer, telling me that the coredll.dll is not find.

How can I prevent that ?
I've added DesktopCompatible = true is the xmta file but it does not
work.

Thanks,
Steve
 
Back
Top