Re: Custom Controls with DLLImports in VS 2005

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You can alter your code so that the P/Invokes are only called on the device.
e.g. using

if(System.Environment.OSVersion.Platform==PlatformID.WindowsCE)
{
//do device specific stuff
}

to exclude the calls from the desktop, or you could use an alternative e.g.
desktop p/invoke. You can simplify this slightly by using a static boolean
which is set once on initialisation e.g.
private static bool isDevice =
(System.Environment.OSVersion.Platform==PlatformID.WindowsCE);

If the P/Invokes occur during property setter/getters you can disable these
from appearing in the designer, if they are called within OnPaint,
OnParentChanged etc you'll need to wrap them as shown above.

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net

"DanielF" <DanielF@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:72B96282-4911-4AA1-B9C5-03991BD3A151@xxxxxxxxxxxxxxxx
>I am trying to port some existing CF custom controls to VS 2005. I have
>read
> the article "Creating Custom Controls for MS .NET CF in VS 2005" which was
> helpful, but it does not deal with DLLImports. I have created the .xmta
> file
> to deal with the design attributes that are required and have installed
> the
> control into the toolbox, but still have errors when I drag-n-drop the
> control onto a form. It complains about the DLLImports and then crashes
> VS. I
> have searched this Newsgroup but no joy. Does anyone know how to deal with
> this issue? Is there an attribute that needs to be added to handle this or
> do
> you have to code around each and every reference to the DLLImport
> functions?
> Any help will be appreciated.


.