我希望在C应用程序中使用C ++ dll.我希望C应用程序将直接从指定路径调用C ++ dll并使用其功能 [英] Using C++ dll in a C application.I want that the C Application will directly call the C++ dll from the specified path and use its functions

查看:40
本文介绍了我希望在C应用程序中使用C ++ dll.我希望C应用程序将直接从指定路径调用C ++ dll并使用其功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有问题.
有一个 C ++ dll 其中包含一些功能(假设-加上2个数字.).
我需要从 C 应用程序调用此加法函数.

注意:我不想添加/链接/引用C ++ dll的源代码.
我希望C应用程序将直接从指定路径调用C ++ dll,并使用"Addition()".

我全部使用Visual C ++ 2008.
无论解决方案如何通过互联网访问,到处都有他们告诉我们添加dll项目的参考(dll源代码)

我的要求是-
我们只会将C ++ dll提供给客户端(拥有C应用程序),并告诉他如何将输入提供给C ++ dll,以及如何将其提供给他.

请有人建议我我需要做什么...
我需要在C ++ dll中进行哪些更改以及我们应该如何编写C应用程序以使其能够成功调用&使用C ++ dll.
我是C/C ++的新手,请帮助我.

提前感谢.
Dinesh kumar dora

Hi All,
I have a problem.
There is a C++ dll which has some functions in it (suppose - Addition of 2 nos.).
and i need to call this addition function from a C application.

Note: I dont want to add/link/refer the source code of C++ dll.
I want that the C Application will directly call the C++ dll from the specified path and use the "Addition()".

Iam using Visual C++ 2008 for all this.
Whatever soluton iam getting over internet, everywhere they tell us to add the reference of the dll project(dll source code)

My requirement is that-
We will only give our C++ dll to the client(who has his C application) and will tell him how he should provide the inputs to the C++ dll and how we are going to give him his output.

Please someone suggest me what i need to do...
What changes i need to do in C++ dll and How we should write the C application such that it can successfully call & use the C++ dll.
Iam a newbie in C/C++ so please help me.

Thanx in advance.
Dinesh kumar dora

推荐答案

请阅读: [ ^ ](特别是您需要在DLL中使用extern "C"构造).
如果您不想隐式链接比您必须使用的DLL,请在C应用程序的LoadLibrary函数中,请参阅 [
Please read: "How to mix C and C++"[^] (expecially you need to use the extern "C" construct in your DLL).
If you don''t want implicitely link the DLL than you have to use, in the C application, the LoadLibrary function, see "Using Run-Time Dynamic Linking"[^] at MSDN.


使用DLL文件的示例.
An example to use DLL files.
HANDLE hLib = LoadLibrary("math.dll");
PFARPROC x = GetProcAddress(hLib,"Addnumbers");
x(23,34);
FreeLibrary(hLib);


这篇关于我希望在C应用程序中使用C ++ dll.我希望C应用程序将直接从指定路径调用C ++ dll并使用其功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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