VC++ 2019 (64Bit) Loading DLL built from Labview 2017 64Bit.

  • Thread starter Thread starter Kaneem
  • Start date Start date
K

Kaneem

Guest
Hi,

I am struggling to figure out how to use a DLL that I have created in Labview 2017 (64 bit). I have created a minimal DLL and VC++ code base to share here to hopefully find a solution to the error with the DLL not loading (the error is described below). The DLL (and others I have made) work fine when I use them with MatLab 2015b. But VC++ is just not working for me!

I am using Visual Studio 2019 C++ and took the following steps to create the simple project:

  • I started with an Empty c++ project.
  • Changed the Linker>System>SubSystem from blank to: Windows (/SUBSYSTEM:WINDOWS)
  • Changed the Linker>Advanced>Entry Point from blank to: main
  • Right-Clicked on the project to choose Add>New Item.
  • Then chose "Visual C++">UI>Windows Form (Creating MyForm).
  • Added the main(..) function to the MyForm.cpp
  • A text field is added to the form (InputField)
  • A second text field is added to the form (OutputField)
  • A Button is added to the form (Button1)
  • Double click on the new Button to automatically create the event: Button1_click(...)" at the bottom of MyForm.h
  • The code for the Button1_click() is show below.
  • I have tried adding the path of the DLL/LIB/h files to the Properties>VC++ directories (Include and Library Directories) but it made no difference. All those files are located next to the project and other source files anyhow.

The Error I receive when I Build is LNK2028, LNK2019, and LNK1120 (see the image below)

Error LNK2028 unresolved token (0A000008) "extern "C" double __cdecl MyIncrement(double)" (?MyIncrement@@$$J0YANN@Z) referenced in function "private: void __clrcall MyTestApp::MyForm::Button1_Click(class System::Object ^,class System::EventArgs ^)" (?Button1_Click@MyForm@MyTestApp@@$$FAE$AAMXPE$AAVObject@System@@PE$AAVEventArgs@4@@Z) MyTestApp C:\Users\kane\source\repos\MyTestApp\MyForm.obj 1
Error LNK2019 unresolved external symbol "extern "C" double __cdecl MyIncrement(double)" (?MyIncrement@@$$J0YANN@Z) referenced in function "private: void __clrcall MyTestApp::MyForm::Button1_Click(class System::Object ^,class System::EventArgs ^)" (?Button1_Click@MyForm@MyTestApp@@$$FAE$AAMXPE$AAVObject@System@@PE$AAVEventArgs@4@@Z) MyTestApp C:\Users\kane\source\repos\MyTestApp\MyForm.obj 1
Error LNK1120 2 unresolved externals MyTestApp C:\Users\kane\source\repos\MyTestApp\x64\Debug\MyTestApp.exe 1


The MyForm.h header consists of:

#pragma once
#include "MySimpleTest.h"" //DLL Header

namespace MyTestApp {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/*...
and so on and so on... standard form items etc. Below,
Button1_Click(...) is the peice of code that calls the
DLL function "double MyIncrement(double)" when the
Button1 is pressed. The function Reads value from the
InputField, Increments the value, and writes it to the
OutputField. That is all! To activate the DLL call,
set the #define UseDLLCall to true (but will cause an error).
...*/

private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
double a,b;
/*CHANGING THE LINE BELOW TO true CAUSES COMPILE ERRORS*/
#define UseDLLCall false
a = System::Convert::ToInt32((InputField->Text));
#if UseDLLCall
// Use the DLL to do the Increment: NOTE, this results in
// the error I can not resolve!!!!!!
b = MyIncrement(a); //This is the DLL Call
#else
// Do the increment maths without the DLL.
b = a + 1;
#endif
OutputField->Text = System::Convert::ToString(b);
}
};
}

The MyForm.cpp is:

#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;

[STAThreadAttribute]
int main(array<String^>^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
MyTestApp::MyForm form;
Application::Run(% form);
return 0;
}

The DLL files ...
MySimpleTest.dll
MySimpleTest.lib
MySimpleTest.h
... are all together inside the VC++ project folder, along with the files ...
MyForm.h
MyForm.cpp
MyTestApp.h
MyTestApp.sln
MyTestApp.vcxproj

The DLL Header MySimpleTest.h is:

#ifdef __cplusplus
extern "C" {
#endif

// The DLL call "MyIncrement() simply returns "Input + 1".
double __stdcall MyIncrement(double Input);
long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
void __cdecl SetExcursionFreeExecutionSetting(long value);

#ifdef __cplusplus
} // extern "C"
#endif

Does anyone know what the problem is? Many thanks in advance!

The project and source can be downloaded from here:

(It won't let me post a link)

Kind regards,

Kane.

Continue reading...
 
Back
Top