⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loaddll.cpp

📁 自动化过程中用到的运动控制器
💻 CPP
字号:
// LoadDll.cpp: implementation of the CLoadDll class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "Demo2.h"
#include "LoadDll.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLoadDll::CLoadDll()
{
	LoadDllFun();			//加载DLL文件
}

CLoadDll::~CLoadDll()
{
	if (hDLL != NULL)
	{
		FreeLibrary(hDLL);	//释放DLL
	}
}

int CLoadDll::LoadDllFun()
{
	hDLL = LoadLibrary("dmc");	//加载dmc.dll
	if (hDLL != NULL)
	{
		//////////////////////////////////////
		//以下取得各个DLL函数指针
		auto_set = (LPFNDLL_auto_set)GetProcAddress(hDLL,
                                           "auto_set");
		set_board_irq = (LPFNDLL_set_board_irq)GetProcAddress(hDLL,
                                           "set_board_irq");
		init_board = (LPFNDLL_init_board)GetProcAddress(hDLL,
                                           "init_board");
		decel_stop = (LPFNDLL_decel_stop)GetProcAddress(hDLL,
                                           "decel_stop");
		sudden_stop = (LPFNDLL_sudden_stop)GetProcAddress(hDLL,
                                           "sudden_stop");
		get_abs_pos = (LPFNDLL_get_abs_pos)GetProcAddress(hDLL,
                                           "get_abs_pos");
		reset_pos = (LPFNDLL_reset_pos)GetProcAddress(hDLL,
                                           "reset_pos");

		set_conspeed = (LPFNDLL_set_conspeed)GetProcAddress(hDLL,
                                           "set_conspeed");
		set_profile = (LPFNDLL_set_profile)GetProcAddress(hDLL,
                                           "set_profile");
		set_vector_conspeed = (LPFNDLL_set_vector_conspeed)GetProcAddress(hDLL,
                                           "set_vector_conspeed");
		set_vector_profile = (LPFNDLL_set_vector_profile)GetProcAddress(hDLL,
                                           "set_vector_profile");
		con_pmove = (LPFNDLL_con_pmove)GetProcAddress(hDLL,
                                           "con_pmove");
		con_pmove2 = (LPFNDLL_con_pmove2)GetProcAddress(hDLL,
                                           "con_pmove2");
		fast_pmove = (LPFNDLL_fast_pmove)GetProcAddress(hDLL,
                                           "fast_pmove");
		fast_pmove2 = (LPFNDLL_fast_pmove2)GetProcAddress(hDLL,
                                           "fast_pmove2");

		con_vmove = (LPFNDLL_con_vmove)GetProcAddress(hDLL,
                                           "con_vmove");
		con_vmove2 = (LPFNDLL_con_vmove2)GetProcAddress(hDLL,
                                           "con_vmove2");
		fast_vmove = (LPFNDLL_fast_vmove)GetProcAddress(hDLL,
                                           "fast_vmove");
		fast_vmove2 = (LPFNDLL_fast_vmove2)GetProcAddress(hDLL,
                                           "fast_vmove2");

		con_line2 = (LPFNDLL_con_line2)GetProcAddress(hDLL,
                                           "con_line2");
		fast_line2 = (LPFNDLL_fast_line2)GetProcAddress(hDLL,
                                           "fast_line2");
		arc_center = (LPFNDLL_arc_center)GetProcAddress(hDLL,
                                           "arc_center");
		fast_arc_center = (LPFNDLL_fast_arc_center)GetProcAddress(hDLL,
                                           "fast_arc_center");

		DmcSetBatchProcessFlag = (LPFNDLL_DmcSetBatchProcessFlag)GetProcAddress(hDLL,
                                           "DmcSetBatchProcessFlag");
		DmcGetError = (LPFNDLL_DmcGetError)GetProcAddress(hDLL,
                                           "DmcGetError");

	   ////////////////////////////////
		//若无法取得函数指针
		if (!auto_set||!get_abs_pos)
		{
			// handle the error
			FreeLibrary(hDLL);
			return -1;
		}
	   else
	   {
		   return 0;
	   }
	}
	else
	{
		return -1;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -