LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Program run unexpectedly

Let me explain the problems now we're facing.
I have implement a source code and use it for 3 days. There is a code that we used in a sub function which is GetComputerName(TCHAR pcname, DWORD &pcnamelen). But for the 4th day, suddenly program can not been used. We cannot get the pc name which is very important for this source code. So, we modify the program by changing the sequence for using the GetComputerName() function. The function definition remain same, just the sequence calling GetComputerName() function had change and the program can use again. In fact, it call this function from Subfunction but program can not execute the function. But when we change it and call from main function, the program is working. The changes are some sort like bel
ow:-

Original:-

void GetLocalPC(void)
{
TCHAR pcname[20];
DWORD pcnamelen;
.
.
.
.
GetComputerName(pcname, &pcnamelen);
printf("%s\n",pcname);
.
.
}

int main (void)
{
.
.
.
.
GetLocalPC();
.
.
.
}

New:-

TCHAR pcname[20];

void GetLocalPC(void)
{
.
.
.
.
printf("%s\n",pcname);
.
.
}

int main (void)
{
TCHAR temppcname[20];
DWORD temppcnamelen;
.
.
.
.
GetComputerName(temppcname, &temppcnamelen);
strcpy(pcname,temppcname);
GetLocalPC();
.
.
.
}

As you can see, the program although got change but the flow is basically just same as the old one. We would like to ask why this problem can happen and, why the old program can used for 3 days before the problem happen. Beside virus, is there any other reason for this thing to happen? Because believe that is not virus related issue. The pc that installed this program has anti virus software with latest defination. Moreover the quantity of pc using this program is nearly 500 pc and
all come out the error together nearly the same time.
0 Kudos
Message 1 of 3
(3,173 Views)
Hello

Since this is part of the Windows SDK, and not a CVI function, you might be able to find out more about this if you refer to the MSDN. The MSDN documentation for this function lists how to find out more error information about this function. Use GetLastError to see what the error code is and look up the error code.

I can't say why this function would stop working after 2 days. There might have been changes in the network configuration or something.

Hope this helps

Bila
l Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 3
(3,173 Views)
I'm sorry I don't understand your problem, but I have a couple of suggestions.
1. Click here to review the details of GetComputerName on MSDN.
2. Increase the size of pcname to MAX_COMPUTERNAME_LENGTH + 1 characters.
3. Before calling GetComputerName, set pcnamelen to sizeof(pcname). MSDN says on input, pcnamelen should be the size of the buffer (pcname).
4. Check the return value of GetComputerName and call GetLastError if GetComputerName returns a non-zero value. Click here for an example of retrieving the last error.
5. If none of
that works, try using GetCompName from the CVI Programmer's Toolbox.
0 Kudos
Message 3 of 3
(3,173 Views)