By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,542 Members | 1,740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,542 IT Pros & Developers. It's quick & easy.

Interop DllImport in Class Library

P: n/a
Hello -

I am getting a compile error "Expected class, delegate, enum".

I am trying to create a Class Library in C# which wraps around an unmanaged
DLL that manages a MIDI interface.

In my Class Library code, I have tried to put a DllImport to the Win32
function MessageBox. Just to test out the DllImport functionality before I
add my custom functions that I want to wrap.

So in my Class Library code, I have

using System.Runtime.InteropServices;

namespace TestMod
{
[DllImport("user32.dll")]
public static extern int MessageBox( System.IntPtr h, string m, string
c, uint t);

........
}
I get an error on the work "int" with error "Expected class, delegate,
enum, interface or struct".

This works if my project target is a Windows exe.
In my case I would like to create a class library, so that many apps could
use this and not have to have a define section in the 'main' code.

Is the DllImport attribute allowed for a class library?

Much thx,
bruce


Mar 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
just insert the dllimport into your class:
namespace ClassLibrary1
{

public class Class1
{
[DllImport("user32.dll")]
public static extern int MessageBox(System.IntPtr h, string m, string c,
uint t);

...
}
}

After that, you have to add a refernece to System.Windows.Forms
Marcel
Mar 16 '07 #2

P: n/a
Thanks - that worked!

"Marcel Beutner" <in**@obd2-software.dewrote in message
news:op.tpaly2vyjbzbwo@mb...
just insert the dllimport into your class:
namespace ClassLibrary1
{

public class Class1
{
[DllImport("user32.dll")]
public static extern int MessageBox(System.IntPtr h, string m, string c,
uint t);

...
}
}

After that, you have to add a refernece to System.Windows.Forms
Marcel

Mar 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.