[DllImport(DLLName, EntryPoint="CommOpen")]
public static extern int CommOpen(int comNumber);
[DllImport(DLLName,EntryPoint="CommClose")]
public static extern int CommClose();
[DllImport(DLLName,EntryPoint="CommTmOut")]
public static extern int CommTmOut(int count);
[DllImport(DLLName,EntryPoint="CommSend")]
public static extern int CommSend(String function,String data);
[DllImport(DLLName,EntryPoint="CommRece")]
public static extern int CommRece(String function,String data);
private void button1_Click(object sender, EventArgs e)
{
string id = "";
string data = "";
if (CommOpen(6) == 1)
{
CommTmOut(500);
CommSend("A1", "");
if (CommRece(id, data) == 1)
txtId.Text = id + " " + data;
else
{
MessageBox.Show("读取ID失败,请检查设备");
}
CommClose();
}
else
{
MessageBox.Show("PDA端口无法打开");
}
////////////////////////////////////////////////////////////////////////////////////////
//
// SunCf.h used for SunCf.dll
//
//
////////////////////////////////////////////////////////////////////////////////////////
extern "C" __declspec(dllexport) int __stdcall CommOpen(int com_number);
extern "C" __declspec(dllexport) int __stdcall CommClose();
extern "C" __declspec(dllexport) int __stdcall CommTmOut(int count);
extern "C" __declspec(dllexport) int __stdcall CommSend(char *function, char *data);
extern "C" __declspec(dllexport) int __stdcall CommRece(char *function, char *data);
/*-------------------------------------------------------
SunCfEVC.h
this header file is used for writing evc program
--------------------------------------------------------*/
#ifndef _SunCfEVC_H
#define _SunCfEVC_H
typedef int (_stdcall pfnCommOpen) (int);
typedef int (_stdcall pfnCommClose) ();
typedef int (_stdcall pfnCommTmOut) (int);
typedef int (_stdcall pfnCommSend) (char *,char *);
typedef int (_stdcall pfnCommRece) (char *,char *);
#endif
//////////////////////////////////
看样子最后问题还是,
从
extern "C" __declspec(dllexport) int __stdcall CommSend(char *function, char *data);
到
CommSend("A1", "");
函数在C#里是这么定义的: [DllImport(SunCf.dll,EntryPoint="CommSend")]
public static extern int CommSend(String function,String data);