我如何从我的C#代码中引用我的C代码混淆。我已经阅读并意识到DLL是有用的,但我不知道如何连接我的DLL。从我的理解,我从我的C代码的DLL?请帮助传递到C代码从C#代码在Visual Studio
C#(Visual Studio代码)
public partial class Form1: Form{
[DllImport("simple.dll", CallingConvention = CallingConvention.Cdec1)]
public static extern void pinfo(string str);
private void button1_Click(object sender, EventArgs e){
pinfo("yay");
}
}
C代码 - simple.c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
__declspec(dllexport) void pinfo(char* str){
printf("You are in the method %s\n, str);
}
int main(void){
}
我的问题是如何将C代码连接到C#代码因此,“你在方法耶”行打印出来?我不明白如何将dll文件链接到Visual Studio或如何创建dll文件。感谢
检查https://stackoverflow.com/questions/11425202/is-it-possible-to-call-ac-function-from -c-net和https://stackoverflow.com/questions/2874603/is-it-possible-to-embed-c-code-in-ac-sharp-project –
你的代码对我来说看起来很好。当你尝试运行它会发生什么? (请注意,您需要首先导出'pinfo'函数)。使用'__declspec(dllexport)' – Dai
@dai我添加了这一行,我不确定如何运行它,因为我有一个visual studio项目,然后是一个与我的visual studio项目无关的simple.c文件,我不确定如何链接它们 – Aak