LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to load DLL library on Labview?

Hi

 

I have an application that is working well in Visual C++ 2012. I would like to load the dll library on labview and to execute the code on labview. I have only the DLL file, the working application and the help file. Is it possible to realise this task on labview using Call Library Function Node.

 

I have par example the following code in .cpp file:

 

void CMTBClientUsingCOMDlg::OnBnClickedConnect()

{

// TODO: Add your control notification handler code here

try

{

// login to MTB, using english language

 

m_MTBConnection->Login(("en"), &m_ID);

// get MTB root (forcing an internal QueryInterface() on IMTBRoot!)

m_Root = (IUnknown*)(m_MTBConnection->GetRoot((BSTR)m_ID));

 

// ask root to return the number of devices

int count = m_Root->GetDeviceCount();

 

// list all devices

for (int i=0; i < count; i++)

{

_bstr_t name = ((IMTBIdentPtr)m_Root->GetDevice(i))->GetName();

m_ComboDevices.AddString(name);

}

if( m_ComboDevices.GetCount() > 0)

m_ComboDevices.SetCurSel(0);

OnCbnSelchangeDevices();

m_BtnConnect.EnableWindow(false);

m_BtnDisconnect.EnableWindow(true);

}

catch(_com_error e)

{

// connection close

OnBnClickedDisconnect();

DisplayError(&e);

}

}

 

 

How to execute this code on labview?

 

Best regards

 

0 Kudos
Message 1 of 16
(5,788 Views)

http://digital.ni.com/public.nsf/allkb/DCB90714981A1F148625731E00797C33

 

http://zone.ni.com/reference/en-XX/help/371361J-01/lvexcodeconcepts/configuring_the_clf_node/

 

I've never had an easy time doing this, but then again most the times I have this task I don't have the original source so maybe you'll have better luck.

0 Kudos
Message 2 of 16
(5,779 Views)

It really depends what your DLL is (and your example code shows absolute nothing about how the objects are initialized/instantiated). How do you get the m_MTBConnection variable initialized, for instance?

 

If it is an ActiveX interface you will use the Active X functions in LabVIEW. If it is however a C++ DLL you will have to write a C wrapper for every method you want to call as well as a C function to instantiate and dispose of the object.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 16
(5,761 Views)

Is there any way you can write this with .NET ? Should be simple to port it to C# or something that can adapt this code quickly. The benefit is you can use .NET constructor which is way way wayyyy simpler than using Call Library Node.


Kudos are the best way to say thanks 🙂
0 Kudos
Message 4 of 16
(5,743 Views)

Hi

I have attached the help file describing the dll library (MTBApi.dll). My working program made on Visual C++ Dot Net is very big and therefore I can’t attach it.

In my header file I import at the beginning the dll library on this way:

 #import "MTBApi.tlb" named_guids

using namespace MTBApi;

 

Than I have a class:

 

class CMTBClientUsingCOMDlg : public CDialogEx

{

public:

CMTBClientUsingCOMDlg(CWnd* pParent = NULL); // standard constructor

~CMTBClientUsingCOMDlg(); // standard destructor

enum { IDD = IDD_MTBCLIENTUSINGCOM_DIALOG };

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

 

protected:

HICON m_hIcon;

IMTBConnectionPtr m_MTBConnection;

IMTBRootPtr m_Root; 

CComBSTR m_ID; 

IMTBChangerPtr m_Changer; 

IMTBDevicePtr m_Device;

...

DECLARE_MESSAGE_MAP()

public:

afx_msg void OnBnClickedConnect();

CButton m_BtnConnect;

};

 

In my .cpp file I have:

 

CMTBClientUsingCOMDlg::CMTBClientUsingCOMDlg(CWnd* pParent /*=NULL*/)

: CDialogEx(CMTBClientUsingCOMDlg::IDD, pParent)

{

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

CoInitialize(NULL);

try

{

// create an instance of the connection class which can connect to the server

m_MTBConnection = IMTBConnectionPtr(CLSID_MTBConnection);

}

catch(_com_error e)

{

...

}

...

}

CMTBClientUsingCOMDlg::~CMTBClientUsingCOMDlg()

{

...

}

void CMTBClientUsingCOMDlg::DisplayError(_com_error* e)

{

...

}

void CMTBClientUsingCOMDlg::DoDataExchange(CDataExchange* pDX)

{

CDialogEx::DoDataExchange(pDX);

DDX_Control(pDX, IDC_CONNECT, m_BtnConnect);

 

}

BEGIN_MESSAGE_MAP(CMTBClientUsingCOMDlg, CDialogEx)

ON_BN_CLICKED(IDC_CONNECT, &CMTBClientUsingCOMDlg::OnBnClickedConnect)

...

END_MESSAGE_MAP()

 

BOOL CMTBClientUsingCOMDlg::OnInitDialog()

{

CDialogEx::OnInitDialog();

{

...

}

 

void CMTBClientUsingCOMDlg::OnPaint()

{

...

}

 

void CMTBClientUsingCOMDlg::OnBnClickedConnect()

{

try

{

// login to MTB, using english language

 

m_MTBConnection->Login(("en"), &m_ID);

// get MTB root (forcing an internal QueryInterface() on IMTBRoot!)

m_Root = (IUnknown*)(m_MTBConnection->GetRoot((BSTR)m_ID));

 

// ask root to return the number of devices

int count = m_Root->GetDeviceCount();

 

// list all devices

for (int i=0; i < count; i++)

{

_bstr_t name = ((IMTBIdentPtr)m_Root->GetDevice(i))->GetName();

}

catch(_com_error e)

{

// connection close

}

}

 

My question is how to start this code in labview. How to write the function in labview, par example this function:

m_MTBConnection->Login(("en"), &m_ID);

Best regards

0 Kudos
Message 5 of 16
(5,715 Views)

This looks very much like a an ActiveX library, but the type library is not included but distributed as a seperate file. As such you should look into the ActiveX functions in LabVIEW to import it into LabVIEW.

 

Something like following should get you started. The typecast from the refnum from the GetDevice() method I'm not sure about but the rest is basically exactly what you source code example you posted is doing.

You will need both the .tlb and .dll file in the same folder (preferably in the folder where you also save your VIs for accessing this library, and have to point the MTBApi.IMTBConnection refnum to the .tlb file.

 

IMTBConnection.png

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 6 of 16
(5,700 Views)

Hi

 

Thank you for your answer. I tried the code. When launching the code there is only one error after the execution of IMTBIdent property.

0 Kudos
Message 7 of 16
(5,688 Views)

Well I checked in another project and ActiveX refnum typecasting needs to use the Variant to Data function. Does this work better?IMTBConnection.png

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 8 of 16
(5,685 Views)

Hi

 

Unfortunately the situation is the same.

0 Kudos
Message 9 of 16
(5,677 Views)

Does the Variant to Data node throw an error or does the IMTBIdent->Name property give you an error? And what error code do you get?

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 10 of 16
(5,622 Views)