C#调用dll文件,产生找不到程序入口点的问题
先用VC创建了一个dll的工程,代码如下:
//头文件
/*dlltry_04.h*/
#ifndef DLLTRY_04_
#define DLLTRY_04_
#ifdef EXPORT_SAMPLE
extern __declspec(dllexport) __stdcall int SampleMethod(int i);
#else
extern __declspec(dllimport) __stdcall int SampleMethod(int i);
#endif
//.cpp文件
//dlltry_04.cpp
#include
#include
#include
int __declspec(dllexport) __stdcall SampleMethod(int i)
{
return i*10;
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
我用VC建立的测试工程测试了上述代码,没有问题。
在C#中,在调用上述的dlltry_04.dll文件发生了找不到程序入口点的错误
c#代码如下:
//C#工程
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//[DllImport("dllTry.dll")]
//private static extern void HelloWorld ();
[DllImport("DllTry_04.dll", EntryPoint = "?SampleMethod@@YAHH@Z")]
public static extern int SampleMethod(int x);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int i = 5;
Console.WriteLine("SampleMethod() returns {0}.", SampleMethod(i));
}
}
}
程序入口点我是用vc工具dumpbin找到的,直接写在C#中。.cpp中的函数代码是MSDN提供的,因此也不可能出错。
求教啊!!!!
方法声明的地方改在这样就可以了啊
[DllImport("DllTry_04.dll", EntryPoint = "SampleMethod")]
答:打开c的file用load打开详情>>
答:详情>>
答:这个问题是见人见智的,我觉得不够,作为一个优秀的.net程序员,你还需要掌握计算机网络,计算机组成,数据库,html,等你都是需要掌握的。详情>>
答:不知是不是你要的版本,但是这里面不仅有源代码,还有视频讲解。下了看看吧。下载地址:详情>>