473,545 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interop DllImport in Class Library

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("user 32.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
2 10339
just insert the dllimport into your class:
namespace ClassLibrary1
{

public class Class1
{
[DllImport("user 32.dll")]
public static extern int MessageBox(Syst em.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
Thanks - that worked!

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

public class Class1
{
[DllImport("user 32.dll")]
public static extern int MessageBox(Syst em.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6170
by: Patrick | last post by:
Following earlier discussions about invoking a .NET class library via ..NET-COM Interop (using regasm /tlb) at http://groups.google.com/groups?hl=en&lr=&threadm=%23Van7eSrEHA.4004%40TK2MSFTNGP10.phx.gbl&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26selm%3D%2523Van7eSrEHA.4004%2540TK2MSFTNGP10.phx.gbl I have concluded that my .NET class library...
2
6449
by: pieter.breed | last post by:
Hi All, The company I work for has traditionally used COM/ActiveX for the solutions that it provides. We are in the process of moving to .NET and a few applications have been written in VB.NET up to this point. Some of the applications are class libraries which need to be callable via the COM interface from some of the older applications....
2
7897
by: Jessard | last post by:
Help! Hi, I'm having a bit (well a lot - it's getting annoying) of trouble using a C# class library within a VBScript on a computer other than the development machine. All the class is needed for at the moment is to create an ADODB.Connection object based on a passed in parameter. The passed in parameter is looked up in an XML document...
3
2105
by: Jay Douglas | last post by:
Hello all, I've wrote a .dll in c#. The .dll needs to be used by a VB 6 application. At first, I couldn't set a reference from the VB app, but then I found the register for COM Interop in the build configuration in the VS.net IDE. The VB 6 IDE now lists my class library as a reference. But there are still a few issues. I can set a...
7
4690
by: Josef | last post by:
Hello, I want to create a C# class library which I can use in an Excel VBA macro. I created a C# class library and set the "Register for COM Interop" option in Visual Studio to TRUE. Now in Excel I can use this library but the intellisense does not show any properties or functions of the class. Do I have to add any keywords or GUID to each...
7
1466
by: jason | last post by:
i have a C# class library full of objects. the immediate need was to instantiate these objects in classic ASP, so i inherit ServicedComponent and build the project with COM Interop set to true. and the objects work in classic ASP just fine. however, we are slowly introducing ASP.NET code, and i would like to make use of the same objects....
0
1146
by: ajerijian | last post by:
Hi all, My apologies for posting this message into the wrong newsgroup. I'm reposting it here since it's more appropriate. I am attempting to export an unmanaged (__nogc) C++ class from a class library into an C++ application compiled using the CLR. Within the class library, I have declared the class as follows: __nogc class...
4
1716
by: Peter | last post by:
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...
4
2339
by: Greg | last post by:
I have a very simple Visual Basic .NET 2003 class library project ClassLibrary1 configured to run an external program (in this case C:\WINDOWS\system32\wscript.exe), in the Debugging Configuration Properties Dialog Box with command line arguments C:\test.vbs. When I run the project, I get an "unable to start debugging" error "unable to start...
0
7479
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7411
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7439
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4962
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3468
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.