Previous Existance (Managed C++.NET 2003)

N

Newbie Coder

Can anyone convert this to managed C++.NET 2003?

Private Function PrevInstance() As Boolean
If
UBound(System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Proc
ess.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function

When I try to convert it the 'ProcessName' doesn't work

.... to (System::Diagnostics::process::GetCurrentProcess

That is when I cannot use: GetCurrentProcess::processName)) >0

Any suggestions would be grateful

Thanks in advance,
 
B

Ben Voigt

Newbie Coder said:
Can anyone convert this to managed C++.NET 2003?

Private Function PrevInstance() As Boolean
If
UBound(System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Proc
ess.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function

When I try to convert it the 'ProcessName' doesn't work

... to (System::Diagnostics::process::GetCurrentProcess

GetCurrentProcess sounds like a function, which requires trailing
parentheses.

I also have to remind you that converting code to Managed Extensions for C++
(VC2003) is about the worst possible thing to do. It's unsupported, buggy,
and won't be fixed, ever. Please use C++/CLI instead, you'll save yourself
a lot of pain.
 
N

Newbie Coder

Ben,

Thank you for your reply

After the GetCurrentProcess nothing comes up in the intellisense. So, I am
still in the same position.

My knowledge of C++ now after 5-6 years not using it is basically zero. I'd
prefer to create C++ apps that don't requite the framework whatsoever &
which will use the old C++ runtime files.
 
B

Ben Voigt

Newbie Coder said:
Ben,

Thank you for your reply

After the GetCurrentProcess nothing comes up in the intellisense. So, I am
still in the same position.

Intellisense often gets confused in C++ code.

You should have ended up with something like:

if
:):System::Diagnostics::process::GetProcessesByName:):System::Diagnostics::process::GetCurrentProcess()->ProcessName)->Length
 
B

Ben Voigt

Newbie Coder said:
Ben,

Thank you for your reply

After the GetCurrentProcess nothing comes up in the intellisense. So, I am
still in the same position.

My knowledge of C++ now after 5-6 years not using it is basically zero.
I'd
prefer to create C++ apps that don't requite the framework whatsoever &
which will use the old C++ runtime files.

For a native solution (no framework dependencies), you can do the exact same
thing using EnumProcesses, but the standard way of finding an existing
instance of your application is to create a named pipe. If that fails, it's
because one already exists, so then you can open the named pipe and send a
message to the existing instance.

The problem with the "count processes" method is that it's not atomic. Two
processes could start simultaneously, count processes, see there's another
process, and both exit, even though you would want one to start. The named
pipe method deals with that race condition.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top