爱问知识人 爱问教育 医院库

C#调用dll文件,产生找不到程序入口点的问题

首页

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提供的,因此也不可能出错。

求教啊!!!!

提交回答

全部答案

    2018-04-25 03:59:37
  • 方法声明的地方改在这样就可以了啊
    [DllImport("DllTry_04.dll", EntryPoint = "SampleMethod")]

    b***

    2018-04-25 03:59:37

类似问题

换一换
  • C#/.NET 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):