续:求函数加入动态库及使用范例及说明。快来拿分,大家发发! 求函数加入动态库及使用范例及说明。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // File: RUNTIME.C// A simple program that uses LoadLibrary and // GetProcAddress to access myPuts from MYPUTS.DLL. #include <stdio.h> #include <windows.h> typedef VOID (*MYPROC)(LPTSTR); VOID main(VOID) { HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; // Get a handle to the DLL module. //加载了一个叫myputs的dll hinstLib = LoadLibrary("myputs"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { //获取该dll中的函数地址 ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts"); // If the function address is valid, call the function. if (NULL != ProcAdd) { fRunTimeLinkSuccess = TRUE; //开始调用 (ProcAdd) ("message via DLL function\n"); } // Free the DLL module. //一定free,否则内存泄漏! fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method\n"); } 首先创建一个DLL工程,然后加入函数(求方根)进入DLL中:#include <math.h>extern "C" __declspec(dllexport) double Square(double d){ AFX_MANAGE_STATE(AfxGetStaticModuleState()); TRACE("Entering Ex21cSquareRoot\n"); if (d >= 0.0) { return sqrt(d); } AfxMessageBox("Can't take square root of a negative number."); return 0.0;}导入DLL时,首先申明一下:extern "C" __declspec(dllimport) double Square(double d); 如何等待一个事件发生? 请教如何设置项目为unicode? TREE 树型控件怎么自动指定到某子项 初学者请教——如何实时显示采集的数据曲线 大伙看一下 MSDN 一段内存分配的代码? MCI立刻要用,急!!!!!!!!!!!!!!!!!!!!!11 请问VC做界面是不是很麻烦呢? 100分找学习atl好书,电子版下载也行(最好是实用版的) 使用ADO 的_RecordsetPtr 创建了对象 mySet,如何在使用后关闭它 Rebuilt Solution之后出错 如何加载其他应用程序的对话框 如何给CPropertyPage添加图标?能否通过CPropertySheet?
// A simple program that uses LoadLibrary and
// GetProcAddress to access myPuts from MYPUTS.DLL.
#include <stdio.h>
#include <windows.h>
typedef VOID (*MYPROC)(LPTSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
//加载了一个叫myputs的dll
hinstLib = LoadLibrary("myputs");
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
//获取该dll中的函数地址
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
//开始调用
(ProcAdd) ("message via DLL function\n");
}
// Free the DLL module.
//一定free,否则内存泄漏!
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("message via alternative method\n");
}
#include <math.h>
extern "C" __declspec(dllexport) double Square(double d)
{ AFX_MANAGE_STATE(AfxGetStaticModuleState());
TRACE("Entering Ex21cSquareRoot\n");
if (d >= 0.0) {
return sqrt(d);
}
AfxMessageBox("Can't take square root of a negative number.");
return 0.0;
}
导入DLL时,首先申明一下:extern "C" __declspec(dllimport) double Square(double d);