我是一个创建dll文件的初学者。我已经到处搜寻,但找到的帮助很少,可能是因为这是基础知识吗?我想知道是否在创建dll文件时总是需要编写头文件?根据网上的一些帮助,我已经编写了.cpp文件。我已经构建了它,一切正常,但目录中没有.lib文件,所以我想知道是否是因为我没有为dll创建头文件?如果是的话,你能帮我为我的代码编写一个吗?这是我的.cpp代码。它是一个简单的球体表面积和体积计算代码。
// myfirstdll.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "math.h" //library that defines the pow function
#define M_PI 3.14159 //declare our M_PI constant
/*BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
return TRUE;
}*/
//Function declarations
extern "C" __declspec(dllexport) int __cdecl GetSphereSAandVol(double radius, double* sa, double* vol);
double GetSA(double radius);
double GetVol(double radius);
__declspec(dllexport) int __cdecl GetSphereSAandVol(double radius, double* sa, double* vol)
//Calculate the surface area and volume of a sphere with given radius
{
if(radius < 0)
return false; //return false (0) if radius is negative
*sa = GetSA(radius);
*vol = GetVol(radius);
return true;
}
double GetSA(double radius)
{
return 4 * M_PI * radius * radius;
}
double GetVol(double radius)
{
return 4.0/3.0 * M_PI * pow(radius, 3.0);
}