我正在制作一个程序来控制激光,但要做到这一点,我需要将一个 dll 导入 c# 并用它调用函数。原始程序是用 C++ 编写的,我只是不知道该怎么做。所以我的问题是:
- 如何在c#中导入dll
- 如何在 C# 中从 C++ 调用函数
为了让您更清楚一点,我添加了 C++ 程序中的代码。
#include "MarkEzdDll.h"
class CDemoEzdDlg : public CDialog
{
// Construction
public:
CDemoEzdDlg(CWnd* pParent = NULL); // standard constructor
HINSTANCE m_hEzdDLL;//DLLµ÷Óþä±ú
LMC1_INITIAL lmc1_Initial;
LMC1_CLOSE lmc1_Close;
LMC1_LOADEZDFILE lmc1_LoadEzdFile;
LMC1_MARK lmc1_Mark;
LMC1_MARKENTITY lmc1_MarkEntity;
LMC1_GETPREVBITMAP lmc1_GetPrevBitmap;
LMC1_READPORT lmc1_ReadPort;
LMC1_WRITEPORT lmc1_WritePort;
LMC1_SETDEVCFG lmc1_SetDevCfg;
LMC1_SETHATCHPARAM lmc1_SetHatchParam;
LMC1_SETFONTPARAM lmc1_SetFontParam;
LMC1_GETPENPARAM lmc1_GetPenParam;
LMC1_SETPENPARAM lmc1_SetPenParam;
LMC1_CLEARENTLIB lmc1_ClearEntLib;
LMC1_ADDTEXTTOLIB lmc1_AddTextToLib;
LMC1_ADDFILETOLIB lmc1_AddFileToLib;
LMC1_ADDBARCODETOLIB lmc1_AddBarCodeToLib;
LMC1_CHANGETEXTBYNAME lmc1_ChangeTextByName;
LMC1_AXISMOVETO lmc1_AxisMoveTo;
LMC1_AXISCORRECTORIGIN lmc1_AxisCorrectOrigin;
LMC1_GETAXISCOOR lmc1_GetAxisCoor;
LMC1_SAVEENTLIBTOFILE lmc1_SaveEntLibToFile;
在对话框中,有一个附有此代码的按钮:
void CDemoEzdDlg::OnButtonRun()
{
// TODO: Add your control notification handler code here
UpdateData();
if(lmc1_Mark==NULL)
{
return;
}
lmc1_Mark(FALSE);
UpdatePrevBmp();
AfxMessageBox(_T("Mark file finish!"));
}
这是激光应该启动的时候。
如何在 c# 中得到这个?