ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CreateProcess by LabVIEW

I am trying to use WinAPI CreateProcessA (kernel32.dll) for future use. I am getting return value 0. What am I doing wrong?
LabVIEW 7.1, XP SP2.
0 Kudos
Message 1 of 14
(6,117 Views)
A few comments to answer
 
1. You can always call GetLastError() in the Win32 API for any function that returns a boolean to indicate pass or fail. It will give you the actual error code, which you can then look up.
 
2. LV Clusters and C structures are not the same thing. You are trying to pass a pointer to a LV cluster (via the void*) directly to the Win32 API that is expecting a C structure - it is probably getting garbage. Similar issue for the data coming out. In fact, you might end up with corrupted memory...I don't recommend doing this.
 
3. A much easier approach is to use the .NET System.Diagnostics.Process class, which lets you do the same thing but has full data support in LabVIEW 7.x.
0 Kudos
Message 2 of 14
(6,093 Views)
Additionally, I think that your startupinfo cluster is missing two elements.  If memory serves they are dwXSize and dwYSize located between dwY and dwXCountChars.

Paul
0 Kudos
Message 3 of 14
(6,090 Views)

Thanks a lot.

I will check it one more time and definitelly will check Process Class from .NET.

Zeck

P.S. 1)  I was trying to use GetLastError() with no luck, it shows NoErorr.

        2)  I created header file to see how LV converts structure and i found that LV is smart enouph to 

              produces very similar structure to the code provided by MSDN.

0 Kudos
Message 4 of 14
(6,083 Views)
1. Strange! I have no response to that one...
 
2. Yes, it often is close but remember that "often" isn't "always". At a minimum, for example, LV data structures are 1-byte aligned where Win32 structures are 4-byte aligned. So a structure such as
 
struct Oops {
   int abc;
   byte def;
   int ouch;
};
 
Have different memory layouts, even if the structure definitions are the same.
 
Let me know if you have any questions with the .NET API's...
0 Kudos
Message 5 of 14
(6,080 Views)

Thanks you.

I was thinking about It, but wanted to check with much more advanced people.

So, as I understood, I really have concentrate on .Net. I have never worked with it so, let me read about it and see some examples first.

Thanks again, I will return as I have something or stock with something.

Zeck

0 Kudos
Message 6 of 14
(6,057 Views)

.Net is working for me.

Thank you for help.

Zeck

0 Kudos
Message 7 of 14
(6,035 Views)

Here is vi with CreateProcessA and GetLastError working.

In order to properly handle stdIn and stdErr in .NET Microsoft recommends to use second (or another) thread but I

could not get enough Information how to do that. Any idea?

Thank you.

 

Zeck

0 Kudos
Message 8 of 14
(6,023 Views)
You actually will do it very differently in LV than you would in C#, simply because of the way LV handles threads.

Exactly how best to handle this is going to depend on what you want to do. For example, if you simply want a thread to sit and read from stderr, the easiest thing to do is create a subVI that takes in the .NET refnum for the process and reads stderr. So I would recommend something like

a. Create an instance of the process class and start the process via .NET.
b. Create a subVI that does the stdin, stdout work - the main stuff you are planning on. Set the VI execution thread to "other 1"
c. Create a subVI that does the stderr work. Set the VI execution thread to "other 2"
d. Execute the two subVI's in parallel - make sure you don't have anything that would serialize the execution of the two subVIs.

Does that make sense?
0 Kudos
Message 9 of 14
(6,004 Views)
I decided to try the .net approach. I have never used .net before. I placed a constructor node down but coud not link it to the System.Diagnostics.Process class. I found the class in the list but there are no constructors listed. Could someone help me get a constructor that would let me get to the process class. Thanks.
0 Kudos
Message 10 of 14
(5,879 Views)