Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing some code to read the free disk space as follows:

//declare the params to pass into the method to check disk usage
		ULARGE_INTEGER uliFreeBytesAvailable;
		ULARGE_INTEGER uliTotalNumberOfBytes;
		ULARGE_INTEGER uliTotalNumberOfFreeBytes;

		//init the params to pass into the method to check disk usage
		uliFreeBytesAvailable.QuadPart = 0L;
		uliTotalNumberOfBytes.QuadPart = 0L;
		uliTotalNumberOfFreeBytes.QuadPart = 0L;

		if(GetDiskFreeSpaceEx(lpDirectoryName,
			&uliFreeBytesAvailable,
			&uliTotalNumberOfBytes,
			&uliTotalNumberOfFreeBytes))


I then get the uliTotalNumberOfFreeBytes.QuadPart which is a DWORD64 and I need to send it to another application via a windows socket using the socket::send method requires the data to be sent as a char*. Please could somebody help me to convert the DWORD64 to a char*, or tell me if there is an alternative option for doing this.

I can conver the DWORD64 to a double so if someone could tell me how to convert a double to a char* that would be very helpful too :)
Posted
Updated 3-Feb-12 4:48am
v2

Hi,

If you know what you're doing you could use a static cast
(char *)TotalNumFree etc.

Make sure you got the size right when sending though (sizeof(xyz))

Cheers,

AT
 
Share this answer
 
Comments
Jackie Lloyd 3-Feb-12 11:07am    
Hi, thanks for your suggestion, I tried this:
double dblFreeBytes
char* pCh:
pCh = static_cast<char*>(dblFreeBytes);

but the compiler message is: cannot convert from 'const char [2]' to 'int'. Have I done something wrong?
Addy Tas 3-Feb-12 11:27am    
hi,

Yes You should cast the address of the double to a different size.
so pCh = (char*)&dblFreeBytes; should work
Jackie Lloyd 4-Feb-12 6:09am    
many thanks - that's the same suggestion as above, which is absolutely correct and worked great :)
The char* parameter of socket::send is a pointer to the data memory that should be send. You can pass the address of any kind of data when using a cast:

C++
ULARGE_INTEGER val = 123;;
send(s, (char *)&val, sizeof(ULARGE_INTEGER), 0);
 
Share this answer
 
Comments
Jackie Lloyd 3-Feb-12 11:29am    
Thankyou! THat worked. However, I had to convert the char* back to a double on the other side, so I used strtod() and I just get null.

char * pEnd;
double dbl;
char* val;
dbl = strtod (val,&pEnd);

Could you possibly tell me if you know what I should do to sort his out, please.
Jochen Arndt 3-Feb-12 11:34am    
On the other end do it just the same way:
ULARGE_INTEGER val;
recv(s, (char *)&val, sizeof(ULARGE_INTEGER), 0);

Just treat the char* parameter as a buffer pointer. It's in your hands to what kind of data it is pointing. There is no conversion performed.
Jackie Lloyd 4-Feb-12 6:08am    
Thanks everso much - it looks so easy and obvious now :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900