PInvoke from a class library


G

Guest

Are there any restrictions in using MarshalAs when p/invoke-ing from a class
library as opposed to a windows application in .NET CF 2.0?

The following code will not compile in a CF class library with the error
MarshalAs not found. The same code runs happily in both a Windows
Applicationa and a standard class library.

Is there a simple fix (other than pinvoking only from a .EXE file)?

using System.Runtime.InteropServices;
....
[DllImport("my.dll", CharSet = CharSet.Unicode)]
public static extern bool Test1([In, Out, MarshalAs UnmanagedType.U4)]
ref uint testValue)

Thanks,

Peter
 
Ad

Advertisements

M

Michael C

Peter said:
Are there any restrictions in using MarshalAs when p/invoke-ing from a
class
library as opposed to a windows application in .NET CF 2.0?

The following code will not compile in a CF class library with the error
MarshalAs not found.
You need to add a reference?
 
G

Guest

You need to add a reference?

To what? The references are identical across the different projects,
including a reference to mscorlib.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Peter said:
Are there any restrictions in using MarshalAs when p/invoke-ing from a
class
library as opposed to a windows application in .NET CF 2.0?
Not AFAIK, ni any case all you need to add is the correct namespace.

Now in the case of the CF you can have other problems , namely that the
class (or method) in question are not present.

Does the code compile in a CF win app?

Additionally you could post this problem in the CF newsgroup.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

The following code will not compile in a CF class library with the error
MarshalAs not found. The same code runs happily in both a Windows
Applicationa and a standard class library.

Is there a simple fix (other than pinvoking only from a .EXE file)?

using System.Runtime.InteropServices;
...
[DllImport("my.dll", CharSet = CharSet.Unicode)]
public static extern bool Test1([In, Out, MarshalAs UnmanagedType.U4)]
ref uint testValue)

Thanks,

Peter
 
Ad

Advertisements

G

Guest

Not AFAIK, ni any case all you need to add is the correct namespace.

Now in the case of the CF you can have other problems , namely that the
class (or method) in question are not present.

Does the code compile in a CF win app?
Yes, and runs quite happily. I have simply moved the relevant files to a
folder in the winapp project. Not as nice as a separate library, but it works.
Additionally you could post this problem in the CF newsgroup.
I'll try it, thanks for the suggestion.

Peter
 

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

Similar Threads

OCX from a class library? 4
Class libraries 2
Class Library 3
Class library 4
Problems reloading library. Dynamic pinvoke 0
Debugging Class Libraries 2
Problem: Class Library 1
static class libraries? 2

Top