I've written a function that will be called from a JNI method... It's been crashing, but I think it's working now. Note the word 'think'..
Does this seem right? If I don't use the copyTCHAR function it crashes...
I'm not sure why it crashes either ... New to C and a little lost....
Code:
char* getDNSFullyQualifiedName()
{
TCHAR buffer[256] = TEXT("");
DWORD dwSize = sizeof(buffer);
char* temp;
if (GetComputerNameEx((COMPUTER_NAME_FORMAT)3, buffer, &dwSize))
{
temp = copyTCHAR(buffer);
dwSize = sizeof(buffer);
ZeroMemory(buffer, dwSize);
return temp;
}
return NULL;
}
Code:
char* copyTCHAR(TCHAR* source)
{
int size;
char* destination;
if (!source)
{
return NULL;
}
size = strlen(source) + 1;
if (size <= 0)
{
return NULL;
}
destination = (char *)malloc(size);
strcpy(destination, source);
return destination;
}