我想用KERNEL32.DLL,需要创建自己的dll为了这个,我已经创造DllImp.cs代码,并想用这些在另一个文件的方法,如pipe.cs但如调用DLL的方法,但它说:“是一个领域,但使用像一种”
CreateNamedPipe is a method but is used like a type.
PipeName is a field but is used like a type
PIPE_ACCESS_DUPLEX is a field but is used like a type
PIPE_TYPE_MESSAGE is a field but is used like a type
我的代码是我收到的错误:
//DllImp.cs code
using System;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;
namespace MessageManagerServer {
[SuppressUnmanagedCodeSecurity]
public sealed class DllImports {
[DllImport("kernel32.dll")]
public static extern IntPtr CreateNamedPipe(
String lpName, // pipe name
uint dwOpenMode, // pipe open mode
uint dwPipeMode, // pipe-specific modes
uint nMaxInstances, // maximum number of instances
uint nOutBufferSize, // output buffer size
uint nInBufferSize, // input buffer size
uint nDefaultTimeOut, // time-out interval
IntPtr pipeSecurityDescriptor); // SD
public const uint PIPE_ACCESS_DUPLEX = 0x00000003;
//public const uint PIPE_TYPE_BYTE = 0x00000000;
public const uint PIPE_TYPE_MESSAGE = 0x00000004;
//public const uint PIPE_READMODE_BYTE = 0x00000000;
public const uint PIPE_READMODE_MESSAGE = 0x00000002;
public const uint PIPE_WAIT = 0x00000000;
public const uint NMPWAIT_WAIT_FOREVER = 0xffffffff;
public const uint NMPWAIT_USE_DEFAULT_WAIT = 0x00000000;
public const int INVALID_HANDLE_VALUE = -1;
public const uint ERROR_IO_PENDING = 997;
public const uint PIPE_UNLIMITED_INSTANCES = 255;
public DllImp() {
}
}
这里是pipe.cs代码
using System;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Collections;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Xml;
using System.Windows.Forms;
using System.Diagnostics;
namespace ClassLibrary1
{
public class Pipe
{
private string PipeName = "\\\\.\\pipe\\Honeywell";
public IntPtr Handle;
Handle = DllImp.CreateNamedPipe(PipeName,DllImp.PIPE_ACCESS_DUPLEX,
DllImp.PIPE_TYPE_MESSAGE |
DllImp.PIPE_READMODE_MESSAGE |
DllImp.PIPE_WAIT,
1,
0,
0,
1000,
IntPtr.Zero);
}
}
什么是'DllImp'的实现? –
如果是这样'DllImports.PIPE_ACCESS_DUPLEX'等? –
该代码为DllImp.cs编译? – rene