03-19-2007 11:05 AM
03-20-2007 03:39 PM
How about a string?
@kaycea114 wrote:I have a C++ header file that contains around 2000 preprocessor directives:#define MEM_1 0xC#define MEM_2 0xD#define MEM_3 0x18"""I want to be able to "access" these memory offsets by identifier name (MEM_1) in my LabVIEW program like I would in a C++ program. I do not want the overhead of parsing through the header file and storing all the offsets into an array or similar structure.I've written a simple Win32 console program to return the memory offset given the identifier (see code below), and created a DLL to use with my LabVIEW program. In the console program, you notice that I can call a function and pass in the identifer name, and get the offset back correctly:getOffset(MEM_1);In LabVIEW, I was hoping to be able to pass in the identifier (MEM_1) but was unsure what datatype to use. In my C++ code, I defined the parameter as an int. But in LabVIEW, I can't enter in MEM_1 as an int. Can someone advise on how to do this? Or if there is an alternate way to use #define's from external code inside LabVIEW?---------------------#include "stdafx.h"
#include "scrmem.h"
#include "stdio.h"void getOffset (int var);int _tmain(int argc, _TCHAR* argv[])
{
getOffset(MEM_1);
canf("%d");
return 0;
}void getOffset (int var)
{
printf("The address of MEM_1 is %x", var);
}
03-20-2007 05:47 PM
03-20-2007 06:10 PM
Well, what you want to do is indeed entering a string and getting back the assigned integer. That is what the C preprocessor is doing too although there it is done only once at the preprocessor stage of course and not at runtime anymore. But LabVIEW is not a C preprocessor.
@kaycea114 wrote:Hi,Where do you think I should use the string?The way that getOffset is currently defined in the DLL, I have to connect an integer input into the LabVIEW function. This prevents me from entering in: MEM_1 as the input to the LabVIEW function.Are you suggesting that I change getOffset to receive a String parameter ("MEM_1")? Does that mean I need to do a string compare (line by line) through the header file to get the offset? It seems like doing this search through the header file would degrade performance, but if that's the only work around, then I'll do it.Please advise.
03-20-2007 06:13 PM
03-20-2007 06:34 PM
03-20-2007 11:33 PM
03-21-2007 01:26 AM
And using a Ring Control you can have sparse "enums" meaning the actual values need not to be continous. So you can define "enums" that directly contain the string that identifies a constant and the according value that is the constant you want to be returned. Then you have the whole lookup process in the "Ring Control" itself (actually it is not even a lookup anymore, just an index array, so faster than that is not possible, unless you really go to C compile everything in C and have the preprocessor do it all).
@tbob wrote:
"In LabVIEW, I was hoping to be able to pass in the identifier (MEM_1) but was unsure what datatype to use. In my C++ code, I defined the parameter as an int. But in LabVIEW, I can't enter in MEM_1 as an int. Can someone advise on how to do this? Or if there is an alternate way to use #define's from external code inside LabVIEW?"Can you use an enum structure in Labview? Then typcast the enum into an int (I16) to pass into the C DLL. Or maybe the typecast is not needed since the enum output is actually a numeric.
01-28-2010 03:46 PM - edited 01-28-2010 03:48 PM
This is an old thread. Has there been anything new added to more recent versions of labVIEW do deal with this problem?
Since I'm doing a wrapper DLL, I can create a function to accept a string constant matching the constant symbol and return the value, but if there is a more elegant way to do this I would like to use it.
01-29-2010
04:32 PM
- last edited on
05-01-2025
03:30 PM
by
Content Cleaner
Hey garya505,
Are you looking to send an integer to your main DLL but pass in a string from LabVIEW? So you have created a wrapper DLL to take the string from LabVIEW and convert it to the appropriate integer? If this is the case, could you not use an enumerated control to implement this in your LabVIEW code? Or, use similar logic that you have in your wrapper DLL to pass integers to your DLL.
It might be benificial to start your own thread and reference this one; as the last post on this thread was a few years ago.