/**
* volser.cpp : Version 1.2 jni methods in nativevolser.dll
* For instructions on using javah and the C/C++ compiles see:
* http://mindprod.com/jgloss/jni.html#COMPILING
*
* Copyright: (c) 2007-2017 Roedy Green, Canadian Mind Products
*/
#define UNICODE
#define _UNICODE
#include <Windows.h>
#include <WinBase.h>
#include <String.h>
#include "volser.h"
JNIEXPORT jint JNICALL Java_com_mindprod_volser_Volser_getVolser
(JNIEnv * env, jclass volserClass, jstring rootPathName)
{
const wchar_t * lpRootPathName16 = ( wchar_t *) env->GetStringChars( rootPathName, NULL );
if ( lpRootPathName16 == NULL )
{
return 0;
}
jsize rootLen = env->GetStringLength( rootPathName );
wchar_t * lpRootPathName16_0 = new wchar_t[ rootLen+1 ];
errno_t err = wcsncpy_s(
lpRootPathName16_0 ,
rootLen+1 ,
lpRootPathName16 ,
rootLen
);
env->ReleaseStringChars( rootPathName, (const jchar *) lpRootPathName16 );
if ( err )
{
delete[] lpRootPathName16_0;
return 0;
}
LPTSTR lpVolumeNameBuffer = new TCHAR[ MAX_PATH+1 ];
DWORD volumeSerialNumber;
BOOL ok = GetVolumeInformation(
(LPCTSTR)lpRootPathName16_0,
lpVolumeNameBuffer,
MAX_PATH+1 ,
&volumeSerialNumber,
NULL ,
NULL ,
NULL ,
0
);
delete[] lpRootPathName16_0;
delete[] lpVolumeNameBuffer;
return ok ? volumeSerialNumber : 0 ;
}