DllImport and Control Library project

J

John Dinning

(Using VS2005 C# and compact Framework. Target device is running CE5).

I am creating a simple visual control (New Control Library project for smart
device Windows CE 5), derived from Label, with a couple of extra properties.

I need to call an external dll from this control, on a timer.

When I insert the declaration for the external dll function and build the
control project, strange things happen to any project that uses this
control.

One of my new properties disappears from the properties window.
The form designer displays the error:
"The type 'Microsoft.CompactFramework.Design.UnsafeControl' has no property
named 'TType'"
(TType is my new property - an enum).

The dllImport declaration looks like this:

[System.Runtime.InteropServices.DllImport("Test.dll")]
private static extern bool GetAlphaMode();

It makes no difference if the Test.dll exists or not so the problem is not
with the dll, only with the declaration.
I am not actually calling the function - just declaring it.
If I remove these two lines, all is well again, and all properties are
visible in the designer.
With or without these two lines, the project compiles with no errors.

My first question is:
Is it ok to call a Dll from a visual component library?
If not does anyone have any idea what is going on here?

More info:
If I remove all my new properties, so the control only inherts the standard
label, the control compiles, but the default text on the label is not
'MyNewLabel1' but 'MyNewLabelLib.MyNewLabel', i.e. the library name and
class name of the component. Weird.

Any help extremely welcome.

John.
 
J

John Dinning

The solution was supplied by Rick D in the dotnet.framework.compactframework
newsgroup. Thank you Rick.

dbgrick said:
John,
Marking your control with the DesktopCompatible(true) attribute will
eliminate the Unsafe control message. You should be able to then use the
debugger to determine any additional issues.

Rick D.
Contractor


John Dinning said:
(Using VS2005 C# and compact Framework. Target device is running CE5).

I am creating a simple visual control (New Control Library project for
smart device Windows CE 5), derived from Label, with a couple of extra
properties.

I need to call an external dll from this control, on a timer.

When I insert the declaration for the external dll function and build the
control project, strange things happen to any project that uses this
control.

One of my new properties disappears from the properties window.
The form designer displays the error:
"The type 'Microsoft.CompactFramework.Design.UnsafeControl' has no
property named 'TType'"
(TType is my new property - an enum).

The dllImport declaration looks like this:

[System.Runtime.InteropServices.DllImport("Test.dll")]
private static extern bool GetAlphaMode();

It makes no difference if the Test.dll exists or not so the problem is not
with the dll, only with the declaration.
I am not actually calling the function - just declaring it.
If I remove these two lines, all is well again, and all properties are
visible in the designer.
With or without these two lines, the project compiles with no errors.

My first question is:
Is it ok to call a Dll from a visual component library?
If not does anyone have any idea what is going on here?

More info:
If I remove all my new properties, so the control only inherts the
standard label, the control compiles, but the default text on the label is
not 'MyNewLabel1' but 'MyNewLabelLib.MyNewLabel', i.e. the library name
and class name of the component. Weird.

Any help extremely welcome.

John.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top