| ★ wanayoo — archive 1999 http://www.microsoft.com/Mind/0698/java9110698.htm | Nouvelle recherche | Portail wanayoo |
![]() java911@microsoft.com Download the code (13KB) |
|
Parlez-vous J/Direct?
My February column covered the differences between the various Java native interfaces:
J/Direct, COM, RNI, and JNI. This month I'll delve more deeply into J/Direct to address a few of the questions that weren't answered in February. Keep in mind that most of the
J/Direct declarations demonstrated here are conveniently available by simply importing classes from the package com.ms.win32. In fact, com.ms.win32 serves as a good point of reference if you're having trouble.
|
WINBASEAPI BOOL WINAPI GetDiskFreeSpace(LPCTSTR lpRootPathName,
LPDWORD lpSectorsPerCluster,
LPDWORD lpBytesPerSector,
LPDWORD lpNumberOfFreeClusters,
LPDWORD lpTotalNumberOfClusters) |
|
GetDiskFreeSpace takes the path to the root of a drive and the addresses of several DWORD variables. If the function returns TRUE, the DWORD variables have been modified to contain appropriate values.
How do I provide a character buffer for a DLL function that returns a string by reference (for example, GetEnvironmentVariable)?
|
WINBASEAPI DWORD WINAPI GetEnvironmentVariable(LPCTSTR lpName,
LPTSTR lpBuffer,
DWORD nSize) |
|
The function takes the name of an environment variable like PATH and returns the current value of the variable in the lpBuffer character buffer. The nSize parameter specifies the size of the buffer in characters.
|
|
If you're having trouble getting J/Direct code to work, double-check your @dll tags. Make sure you've linked to the right DLLs and that you're using the auto keyword (if necessary). If you run out of ideas, you may want to surf over to the J/Direct troubleshooting page: http://www.microsoft.com/java/sdk/20/jdirect/Troubleshooting.htm |
|
|
/** @dll.struct() */
class POINT
{
int x;
int y;
}
/** @dll.struct() */
class MSG
{
public int hwnd;
public int message;
public int wParam;
public int lParam;
public int time;
public POINT pt;
}
|
|
|
struct OSVERSIONINFO
{
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[128];
};
|
|
The corresponding J/Direct declaration of this structure is shown in Figure 4. Notice how the @dll.structmap tag specifies that the csdVersion string is a 128-character, fixed-length string where the TCHAR type specifier is defined as a 16-bit Unicode character on Windows NT and as an 8-bit ANSI character on Windows 95.
|
|
|