我正在製作一個程序來控制激光,但要做到這一點,我需要將一個DLL導入到C#中並使用它調用函數。原來的程序是用C++編寫的,我只是不知道該怎麼做。 所以我的問題是:從C調用C++ DLL#
- 如何導入一個dll在C#
- 如何調用從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#中獲得此?
爲了澄清,你想從C#代碼中調用C++函數,還是想從C++代碼調用C#方法? – Justin