首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"DLLNotFoundException"?

"DLLNotFoundException"?
EN

Stack Overflow用户
提问于 2013-03-05 11:44:18
回答 1查看 356关注 0票数 0

我正在尝试将C++制作的本地动态链接库导入到C#中。我有点小问题。

下面是我的C#代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace test
{
    class Program
    {
        [DllImport("hello2dll.dll")] //I didn't know what to name it :'(
        private static extern void SayHi();

        static void Main(string[] args)
        {
            while (true)
            {
                Console.ReadKey();
                SayHi();
            }
        }
    }
}

下面是来自DLL的main.h:

代码语言:javascript
复制
#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
    #endif

     void DLL_EXPORT SayHi();

    #ifdef __cplusplus
}
#endif

#endif // __MAIN_H__

然后是来自DLL的main.cpp:

代码语言:javascript
复制
#include "main.h"

#include<windows.h>

void SayHi()
{
    MessageBox(HWND_DESKTOP, "Hello!", "Hello!", 0);
}

因此,我尝试通过将其放入system32中来访问该动态链接库,然后尝试通过将其复制并粘贴到visual c#中来将其添加到项目中,但到目前为止我还没有成功。我有点失望,它没有工作,但谁知道呢。

EN

回答 1

Stack Overflow用户

发布于 2013-03-05 11:48:09

我不知道它为什么会失败,我宁愿创建一个与CLR兼容的程序集

您可以使用tblimp创建与CLR兼容的程序集,然后可以添加对该程序集的引用,而不是导入它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15215448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档