在Microsoft Visual C ++ 2010中导入DLL [英] Import DLL in Microsoft Visual C++ 2010

查看:96
本文介绍了在Microsoft Visual C ++ 2010中导入DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有一个名为key generator.DLL的DLL,我需要使用此DLL来调用以下函数.我将此DLL复制到我的项目文件夹中,并自动生成了key generator.h和key generator.cpp.

uint securityKey = 0;
securityKey = Key_Generator.KeyCalculator.EOLP_CalculateKeyFromSeed(securitySeed);

其中Key_Generator是命名空间,
KeyCalculator是DLL和
中的静态方法 securitySeed是您传递到DLL中的种子(uint类型)

注意:我的项目模板文件夹具有example.h和example.cpp,可在Microsoft Visual C ++ 2010中生成DLL,而DLL可以正常运行.

问题:
1.我需要在哪个文件中声明此导入功能?怎么样?
2.我需要包括哪些文件以及在哪里?
3.我需要任何图书馆吗?
2.任何项目设置?

谢谢,
Han

I have a only DLL named key generator.DLL, i need to use this DLL to call below function. I copied this DLL into my project folder and it has automatically generated key generator.h and key generator.cpp.

uint securityKey = 0;
securityKey = Key_Generator.KeyCalculator.EOLP_CalculateKeyFromSeed(securitySeed);

Where Key_Generator is a namespace,
KeyCalculator is a static method inside the DLL and
securitySeed is a seed(uint type) you pass into the DLL

Note:My project template folder has example.h and example.cpp to generate a DLL in microsoft visual C++ 2010, which works without any error.

Question:
1. In which file i need to declare this import function? How?
2. Which files i need to include and where?
3. Do i need any library?
2. Any project setting?

Thanks,
Han

推荐答案

http://www.functionx. com/visualc/libraries/explicitdll.htm [ ^ ]在MSVS上运行良好,至少应该以示例为例..
http://www.functionx.com/visualc/libraries/explicitdll.htm[^] works fine with MSVS , should help ya at least as an example ..


如果您是静态链接到该DLL,则需要包含.lib文件在您的链接器设置中.生成DLL时,它将自动生成一个.lib文件.

另外,您也可以使用LoadLibrary(),尽管这通常不是示例处理的方式.
If you''re statically linking against this DLL, then you need to include the .lib file in your linker settings. When you build you DLL, it will automatically produce a .lib file.

Alternatively, you can use LoadLibrary(), though that''s not the way your example is usually handled.


假设您只有abc.dll,并且在dll中有一个命名空间TESTDLL还有一个名为MyClass的类,其构造函数为MyClass().
现在,在VC 2010中执行:
-在您的项目名称上单击属性->配置属性->一般->设置公共语言运行时支持" =公共语言运行时支持(/clr)"(调用:默认为否"). OK
-在您的项目名称上点击引用->选择通用属性->添加新参考->选择浏览器标签->选择您的abc.dll
-现在,您已经在使用此dll.
-接下来,在您的代码中,使用dll中的类:
-使用命名空间TESTDLL
-从abc.dll声明类
MyClass ^测试;
测试= gcnew MyClass();
//对类进行某些操作

我测试了由C#创建的dll.

有福!
Assume you have abc.dll only, and in your dll has a namespace TESTDLL and a Class named MyClass which has constructor as MyClass().
Now, in VC 2010 do:
- Click Properties on your project name -> Configuration Properties -> General -> set Common Language Runtime Support = Common Language Runtime Support(/clr) (recall: default is No) -> OK
- Click References on your project name -> Select Common Properties -> Add New References -> select Browser Tab -> select your abc.dll
- Now, you already use this dll.
- Next, in your code, to use class in the dll:
- using namespace TESTDLL
- declare the class from abc.dll
MyClass^ test;
test = gcnew MyClass();
// do something with the class

I test the dll which is created by C#.

Have fune!


这篇关于在Microsoft Visual C ++ 2010中导入DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆