LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

strstr() works in debug but fails in executable

A routine I used to see if the executable is running on the C drive of the PC on on a network drive as follows:
 
GetProjectDir (currentFolder);
 if (strstr (currectFolder, "c:\\")
 {
    
 
0 Kudos
Message 1 of 8
(4,329 Views)

Sorry, not sure what key I hit...

Anyhow, a routine to check if the executable is running on the C drive or on a network drive:

GetProjectDir (currentFolder);
 if (strstr (currentFolder, "c:\\"))
 {
  // run local stuff
 }
 else
 {
  // run network stuff
 }

This works fine when running under debug mode, but always executes the "else" code after compiled.

Any ideas?

0 Kudos
Message 2 of 8
(4,329 Views)

Hi, cpoore, have you considered using SplitPath function? It can return the drive only so that you can specifically test its value instead of searching for the occurrence of a string.

In case of physical local drive the function returns the drive name and the colon without the backslash, the same in case of a network drive mapped to a virtual drive in the computer. In case of a real network drive (e.g. \\RemoteComputer\\myprogram.exe) the function returns an empty string as the drive name.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 8
(4,314 Views)

Are you sure the drive letter is always lower case?

if (strstr(currentFolder, "c:\\") || strstr(currentFolder, "C:\\"))

might be better, or you could use the CVI FindPattern() function, which can do case-insensitive searching.

--
Martin
Certified CVI Developer
0 Kudos
Message 4 of 8
(4,304 Views)


@cpoore wrote:

Sorry, not sure what key I hit...


probably TAB followed by Space.  Happens all the time 😉
Message 5 of 8
(4,295 Views)
ooooooooo... The SplitPath function looks cool.  There's lots of places I could use that.  I can't believe I missed that one - I need to get out more. Thank you!
0 Kudos
Message 6 of 8
(4,289 Views)

Would it be simpler to use the Utility Library function GetDrive()?

Perhaps something like this:

GetProjectDir (currentFolder);
SetDir (currentFolder); // to be sure
GetDrive (&driveNumber, &numberOfDrives);

Message Edited by cdk52 on 04-06-2006 10:27 AM

0 Kudos
Message 7 of 8
(4,274 Views)

Yes!  I did find that...

GetDrive (&driveNum, &numDrives);
 if (driveNum == 2)
 {
  // using local C drive
  }
 else
 {
  // using networked drive
  }

But the SplitPath function is still cool.

0 Kudos
Message 8 of 8
(4,262 Views)