从c#wpf program

时间:2016-10-05 08:42:46

标签: c# c++ c wpf dll

这是我的问题..

我创建了一个c语言控制台应用程序来读写NFC卡。在那里,有2个读写函数。

long ReadCard(char * cID)
{
// code here 
}

long WriteCard(char * cID)
{
// code here
}

调用此函数,我使用了这段代码..

读卡..

char * cID = malloc(17 * sizeof(char));
long _ret = ReadCard(cID);

用于写卡..

char CID[17];
printf("Enter Card ID \n");
scanf("%s", CID);
long _ret = WriteCard(CID);

这完全有效......

然后我使用上面的控制台应用程序创建了一个dll,并尝试在c#应用程序中使用它。

在c#代码中首先导入dll和函数声明为这样..

[DllImport("NFC_Driver_DLL.dll", CallingConvention =   CallingConvention.Cdecl)]
public static extern int ReadCard([Out] char[] cID);

[DllImport("NFC_Driver_DLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int WriteCard([In] char[] cID);

之后,为了读卡,我使用了这段代码..

char[] CardID = new char[17];
int a = ReadCard(CardID);
string s = new string(CardID);
MessageBox.Show(s);

这已经过全面测试,100%正常工作..

但我不知道,如何从c#侧调用写卡功能..

我试过这段代码......

char[] CardID = new char[17] ;
int a = WriteCard(CardID);

执行此代码时,会发生一个异常,告诉此消息..

WpfNFCTest.exe中出现未处理的“System.EntryPointNotFoundException”类型异常

其他信息:无法在DLL“NFC_Driver_DLL.dll”中找到名为“WriteCard”的入口点。

请帮我打电话给这个写功能...

0 个答案:

没有答案
相关问题