简单的VC ++ DLL程序无法编译 [英] Simple VC++ DLL Program not Compiling
问题描述
我正在尝试使用VS .Net 2005平台创建示例VC ++ DLL
以下内容是我的ExoDLL.h文件
//调用它的函数.
extern"C" __declspec(dllexport)void BoxProperties(双倍长度,双倍高度,
双倍宽度,双倍&面积,双倍音量);
类测试
{
//此函数用于计算平行四边形矩形的总面积
double BoxArea(double L,double H,double W);
//此函数用于计算平行四边形矩形的体积
双BoxVolume(双L,双H,双W);
}
extern测试testobj;
****************************************************** ********************
而且我的ExoDll.cpp文件具有以下内容
//ExoDLL.cpp:定义DLL应用程序的入口点.
//
#include"stdafx.h"
#include"ExoDLL.h"
#ifdef _MANAGED
#pragmamanaged(push,off)
#endif
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
返回TRUE;
}
double Test :: BoxArea(double L,double H,double W)
{
返回2 *((L * H)+(L * W)+(H * W));
}
双测试:: BoxVolume(双L,双H,双W)
{
返回L * H * W;
}
void BoxProperties(双L,双H,双W,双A,双V)
{
testobj = new Test();
A = testobj.BoxArea(L,H,W);
V = testobj.BoxVolume(L,H,W);
}
#ifdef _MANAGED
#pragmamanaged(pop)
#endif
****************************************************** *******************
当我尝试构建解决方案时,出现以下错误消息
错误C2679:二进制="=":未找到采用测试*"类型的右侧操作数的运算符(或没有可接受的转换)"
****************************************************** ********************
由于我是VC ++的新手,所以我对自己在哪里犯错误感到困惑.
请帮助我解决问题.
谢谢,
帕塔比
****************************************************** ****************
您的建议对我有很大帮助.但是现在我遇到了如下所示的链接器错误.
1.Error 1错误LNK2020:未解析的令牌(0A00000D)类Test * test"(?test @@ 3PAVTest @@ A)ExoDLL.obj
2.Error 2错误LNK2001:无法解析的外部符号类Test * test"(?test @@ 3PAVTest @@ A)ExoDLL.obj
3.错误3致命错误LNK1120:2个未解决的外部文件C:\ Documents and Settings \ WiproCC \ My Documents \ Visual Studio 2005 \ Projects \ ExoDLL \ Debug \ ExoDLL.dll
请提出建议.
当然,我会读一些C ++书.
Hi,
I am trying to create a sample VC++ DLL , using VS .Net 2005 platform
The below content is my ExoDLL.h file
// function that called it.
extern "C" __declspec(dllexport)void BoxProperties(double Length, double Height,
double Width, double& Area, double& Volume);
class Test
{
// This function is used to calculate the total area of a parallelepid rectangle
double BoxArea(double L, double H, double W);
// This function is used to calculate the volume of a parallelepid rectangle
double BoxVolume(double L, double H, double W);
}
extern Test testobj;
**********************************************************************
And my ExoDll.cpp file is having below content
// ExoDLL.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "ExoDLL.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
double Test::BoxArea(double L, double H, double W)
{
return 2 * ((L*H) + (L*W) + (H*W));
}
double Test::BoxVolume(double L, double H, double W)
{
return L * H * W;
}
void BoxProperties(double L, double H, double W, double A, double V)
{
testobj = new Test();
A = testobj.BoxArea(L, H, W);
V = testobj.BoxVolume(L, H, W);
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
*********************************************************************
When I am trying to build the solution getting the below error message
"error C2679: binary ''='' : no operator found which takes a right-hand operand of type ''Test *'' (or there is no acceptable conversion)"
**********************************************************************
Since I am novice to VC++ , I am bit confused on where I am making mistakes.
Please help me to rsolve the issue.
Thanks,
Pattabi
******************************************************************
Hi,
Your suggestion helped me lot.But Now I am getting Linker errors as below.
1.Error 1 error LNK2020: unresolved token (0A00000D) "class Test * test" (?test@@3PAVTest@@A) ExoDLL.obj
2.Error 2 error LNK2001: unresolved external symbol "class Test * test" (?test@@3PAVTest@@A) ExoDLL.obj
3.Error 3 fatal error LNK1120: 2 unresolved externals C:\Documents and Settings\WiproCC\My Documents\Visual Studio 2005\Projects\ExoDLL\Debug\ExoDLL.dll
Please suggest.
Surely I will go through some C++ book
推荐答案
如果您对C ++不太了解,那么编写dll并不是一个很好的起点. DLL在C ++中有点复杂.另外,当您寻求帮助时,如果您可以告诉我们哪一行出现错误,也会有所帮助.
If you know this little about C++, writing a dll is not a great starting point. DLLs are a little complex in C++. Also, when you ask for help, if you could tell us what line has the error, it would help.
外部测试testobj;
extern Test testobj;
这是一个测试对象
This is a Test object
testobj = new Test();
testobj = new Test();
这是对新事物的呼唤. C ++中的New用于创建新对象以分配给指针.您的变量不是指针,因此已经调用了它的构造函数,并且该语句正尝试返回Test *并将其分配给Test,这是不可能的,因此会出现错误.
This is a call to new. New in C++ is used to create a new object to assign to a pointer. Your variable is not a pointer, so it''s constructor has already been called, and the statement is trying to return a Test * and assign it to a Test, which is not possible, hence the error.
感谢您的回复.甚至我也尝试过创建如下所示的Pointer对象.
测试* testobj;
但是我在下面的行中遇到了相同的错误
A = testobj.BoxArea(L,H,W);
您能告诉我如何更改代码吗?
注意:当没有任何类声明时,以上代码将正确编译.
Hi,
Thanks for your reply. Even I have tried to create the Pointer obect like below
Test* testobj;
But I am getting the same error on the below line
A = testobj.BoxArea(L, H, W);
Could you please let me know how do I need to change the code ?
Note: The above code is compiling properly when there isn''t any class statement.
要添加新内容,请修改原始内容,即不要t将其他问题发布为"答案" .
关于:
When you want to add new content, please modify the original post, i.e. don''t post additional questions as ''Answer''.
As about:
A = testobj.BoxArea(L, H, W);
您应该根据指针符号进行更改(因为testobj
现在是指针):
You should change it according to pointer notation (since, now, testobj
is a pointer):
A = testobj->BoxArea(L, H, W);
不过,您确实确实需要一本好书.
You really need a good C++
book, though.
这篇关于简单的VC ++ DLL程序无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!