Google Answers Logo
View Question
 
Q: All kinds of C++ ERROR_ACCESS_DENIED in JNI when doing simple Win32 calls ( No Answer,   0 Comments )
Question  
Subject: All kinds of C++ ERROR_ACCESS_DENIED in JNI when doing simple Win32 calls
Category: Computers > Programming
Asked by: dre2xl-ga
List Price: $20.00
Posted: 19 Aug 2003 10:28 PDT
Expires: 18 Sep 2003 10:28 PDT
Question ID: 246497
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).
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy