LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library Node with Console

Hello,

 

I am currently getting to grips with using the Call Library Node to acess exported functions that from DLLs that I have created myself using C++.  I have created a simple DLL that recieves an integer and prints it to the screen:

 

extern "C" __declspec(dllexport) void PrintINT(int);

 

__declspec(dllexport) void PrintINT(int MyInt)
{
std::cout << "This is my integer: " << MyInt << std::endl;
}

 

Labview doesn't display a the console when I call this function though.  I have read some threads where AllocConsole() is used but I cannot find any simple code describing how to implement this when I create my DLL.

 

The reason I would like to be able to do this is two fold: Firstly, to help with debugging my DLLs.  Secondly, I have a working C++ program that uses the console already to perform conplicated mesh vs mesh collision detection.  My aim is to be able to control this program through labview by wrapping it into a DLL.

 

Any information on how to include the AllocConsole() function into my DLL script so that the console runs with my DLL would be great.

0 Kudos
Message 1 of 3
(3,937 Views)

LabVIEW is a Windows GIU application and is compiled and linked as such. This makes the compiler add specific flags to the executable image that tell Windows to not allocate a console on startup that gets anyhow never used. In order to have a console availabe in a Windows GUI application, you have to explicitedly tell the application linker to set that flag differently. Since you do not compile LabVIEW yourself you don't have that option (you could find out the offset into the executable image where this flag is set in the PE header and change it, but that is an unmaintainable solution, if you ever want to distribute such a DLL to another system.

 

The only correct way is to explicitedly allocate a console in your code using the Windwos API, and use that instead. See here for some specific information what Windwos APIs would be involved. There are quite a few other posts here and on lava.org, that go deeper into this.

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

Rolf is fully correct.

 

Another possibility for getting "console" functionality is using CVI Standard Input/Output window:

 

10-06-2012 19-21-28-console.png

 

If you will use standard CVI Compiler, then printf/scanf functions are automatically redirected to this window instead of standard console. From MSVC you will need to call FmtOut and ScanIn.

Also with functions  SetStdioWindowOptions(), SetStdioWindowSize(), SetStdioWindowPosition(), SetStdioWindowVisibility () you will be able to control this window a little bit.

 

Andrey.


 

0 Kudos
Message 3 of 3
(3,923 Views)