Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CNiTimer external event handler; CoInitializeEx is not a member of global namespace.

I am attempting to use the CNiTimer class in VC++. I want to have the handler function change the state of an LED control on my dialog window.
I defined the handler function and tried
m_LED2.SetValue(led2state);
but got an error that "m_LED2" is an undelcared identifier.

Research led me to a question here "Timers for Visual C++" where in David Rohacek indicated the need to include a call to ::CoInitializeEx. (Seems to me that I also ran across this suggestion somewhere in the Measurement Studio help files...)

Anyway, now I get an error that CoInitializeEx is not a member of global namespace. I assume that this has something to do with the fact that there is no class n
ame in front of the "::", but beyond that I am lost.
In case it isn't already obvious, I usually program in CVI, but in this case I need to capture the return value from an .exe application that I want to run. The response to another question in Developer Zone leads me to believe that C++ is my only hope to achieve this.
0 Kudos
Message 1 of 3
(4,447 Views)
To answer your main question, the problem probably is that _WIN32_DCOM is not defined for your project. Go to the Project>>Settings>>C/C++ tab. Make sure General is selected in the Category dropdown list control. At the end of the Preprocessor Definitions list add _WIN32_DCOM (make sure you use a comma to separate it from the other definitions). Do this for every configuration (Release and Debug).


For your original issue, I'm not sure if you mean 1) that you need to write a program that returns a value that you use; or 2) that you need to launch an .exe from within your program and capture its return value. For case 1, you can write a CVI program that returns the value from main. If you need the result from within a batch file, you use %errorlevel% to get
it. For case 2, you can either work around the issue by writing a series of CVI programs and passing their results to each other in a batch file or go with a C++ program that calls _spawn.

David Rohacek
National Instruments
Message 2 of 3
(4,447 Views)
Thanks David. You were right on target with _WIN32_DCOM and project settings. That fixed the compile error with CoInitializeEx().
However, the compiler still gives me an error stating that the 'm_LED2' member variable is and "undeclared identifier". I had thought that the CoInitialize statement would cure this. . . . of course, just because it compiles doesn't mean that it is returning successfully. Guess I'll have to check the return value.
0 Kudos
Message 3 of 3
(4,447 Views)