Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a c++ project [vs 2010 compiler]that uses GetVolumePathNamesForVolumeName function of kernel32.dll. As the function is not supported in windows 2000 server OS, i am not able to run my program in Windows 2000 Server OS. Any Suggestions on how to change the project settings or any code change that solves my purpose. I dont mind if the functionality of "GetVolumePathNamesForVolumeName" does not reflect in my 2000 Server. I tried the following :

C++
typedef BOOL (WINAPI *P_GVPNFVN)(LPCWSTR, LPWSTR, DWORD, PDWORD);

P_GVPNFVN pGetVolumePathNamesForVolumeName = NULL;

pGetVolumePathNamesForVolumeName = (P_GVPNFVN)GetProcAddress (GetModuleHandle ("kernel32.dll"), "GetVolumePathNamesForVolumeName");

BOOL res ;

if(pGetVolumePathNamesForVolumeName != NULL)
{
   res = pGetVolumePathNamesForVolumeName((LPCWSTR)szVolumeName,(LPWSTR)szNames,MAX_PATH,&nChars);
}

The Problem with the above is, after implementing this, the functionality in other OSes is also getting failed. Any Suggestions are welcome.. Thanks in advance.
Posted
Updated 24-Jul-12 19:26pm
v2

You can check the current OS version using GetVersionEx and take the decision accordingly. For more details on OS version GetNativeSystemInfo, GetProductInfo and GetSystemInfo are also helpful.
 
Share this answer
 
v2
Comments
gssajith87 25-Jul-12 9:19am    
I didn't try this out because this had another limitation with my application. But of-course this is also an acceptable solution in general case.
Your code fails because there are two versions of the function: An ANSI version and an Unicode version. According to the Unicode setting, you must pass 'GetVolumePathNamesForVolumeNameA' or 'GetVolumePathNamesForVolumeNameW' to GetProcAddress().
 
Share this answer
 
Comments
nv3 25-Jul-12 3:52am    
Well observed Jochen!

And gssajth87, don't forget to write two versions of the typedef at the top of your code, one for the ANSI and one for the Unicode configuration.
Malli_S 25-Jul-12 3:54am    
Yup ! I missed that. :P
Jochen Arndt 25-Jul-12 4:14am    
Thank you.

Just another example of the necessity to check return values and the error code upon failure. That would have directed to the solution.

But Malli wasn't the questioner. However, you are right to suggest implementation of two versions.

EDIT: Oh, you just saw your mistake and corrected it.
Malli_S 25-Jul-12 3:55am    
Jochen, my +5.
gssajith87 25-Jul-12 9:16am    
Hi Thanks all. [Jochecn Arndt] your following statement solved my issue " According to the Unicode setting, you must pass 'GetVolumePathNamesForVolumeNameA' or 'GetVolumePathNamesForVolumeNameW' to GetProcAddress()" Thanks.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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