I get ERROR_ACCESS_DENIED when doing all sorts of simple Win32 calls.
Please look at http://www.javaworld.com/javaworld/javatips/jw-javatip86.html
for the source code I am trying to modify.
The source code itself works, but when I add simple functions to the
C++/native function Java_MyWindow_paint such as:
LoadLibrary( "user32.lib" );
GetWindowLong( hWnd, ...etc...
SetWindowLong( hWnd, ...etc...
SetBkColor ( hdc, ...etc...
SetLayeredWindowsAttributes( hWnd, ...etc...
The errors are run-time, and all of these will cause a C++ error #5
ERROR_ACCESS_DENIED. The .java file itself is unmodified from the
original tutorial. The Win32 code works fine in a Win32 application. |
Request for Question Clarification by
mathtalk-ga
on
19 Aug 2003 10:46 PDT
Hi, dre2xl-ga:
I suggest verifying the return value from LoadLibrary, to see if a
failure there could be root of the problem.
regards, mathtalk-ga
|
Clarification of Question by
dre2xl-ga
on
21 Aug 2003 11:08 PDT
LoadLibrary is not at the root of this problem. I have used both
static linking and dynamic linking with same results.
Ultimately I simply want to use SetLayeredWindowAttributes in
conjunction with JNI.
Here is some debug printfs code (without LoadLibrary):
printf( "%d\n", GetLastError() );
SetBkColor( hdc, RGB(0x88, 0x88, 0x88) );
printf( "%d\n", GetLastError() );
The output:
16753822 (which is NULL)
5
LoadLibrary, and just about any other kind of code, will produce a 5.
Take my word on this...
|
Clarification of Question by
dre2xl-ga
on
21 Aug 2003 11:13 PDT
To clarify the output, the code does not involve LoadLibrary at all; I
had static-linked to user32.lib.
<br><br>
If you can just get something as simple as SetBkColor working using
that example code in that tutorial, the rest will probably fall in
place.
|
Request for Question Clarification by
mathtalk-ga
on
22 Aug 2003 07:41 PDT
Hi, dre2xl-ga:
Are you trying to add this JNI functionality to an existing applet?
Or to put it in broader terms, how are you trying to run the Java code
and its invocation of native methods?
regards, mathtalk-ga
|
Clarification of Question by
dre2xl-ga
on
25 Aug 2003 10:49 PDT
No applet/servlet/etc. here, just a normal Swing mini-application. My
java.policy file is already set at the most lenient security levels I
believe. I am implementing the code exactly as it is presented in the
tutorial at http://www.javaworld.com/javaworld/javatips/jw-javatip86.html
. It does sound like a permission problem in JNI, I agree, but
precious little information is to be had...
<br><br>
The code itself as presented in the tutorial works fine. However
adding certain other Win32 methods to the C++ native code does
not--the easiest way to make this happen: take the tutorial code, and
just add SetBkColor in the Java_MyWindow_paint method in the C++ code.
<br><br>
Ultimately, I'd just like an answer on how to fix those
ERROR_ACCESS_DENIED problems (or an explanation why it cannot be
fixed).
|