|
-
March 7th, 2007, 05:57 AM
#1
dynamic loading of dll
Hi,
I am having problems calling a function within a DLL. The code is as below, actually there is no problem in loading the DLL but when the call is made to the "JNI_GetDefaultJavaVMInitArgs" function message box appears saying:
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
Any help in this regard is highly appreciatred.
Thanks.
_declspec(dllexport) int CALLCONV JINVOKER(jbyte *input, unsigned short inputLen,
jbyte *output, unsigned short maxOutputLen,
unsigned short *outputLen) {
........................
HINSTANCE handle;
jint res=0;
typedef jint (JNICALL *pfunc1)(void*);
typedef jint (JNICALL *pfunc2)(JavaVM **, void**, void*);
pfunc1 Func1;
pfunc2 Func2;
JavaVMOption options[1];
options[0].optionString =
"-Djava.class.path=" USER_CLASSPATH;
vm_args.version = 0x00010004;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
handle = LoadLibrary("C:\\Program Files\\IBM\\WebSphere Studio\\Application Developer\\v5.1\\runtimes\\base_v5\\java\\jre\\bin\\classic\\jvm.dll");
if(handle!=NULL)
{
Func1=(pfunc1)GetProcAddress(handle,"JNI_GetDefaultJavaVMInitArgs");
Func2=(pfunc2)GetProcAddress(handle,"JNI_CreateJavaVM");
if((Func1!=NULL)&&(Func2!=NULL))
{
.
.
.
.
if (!env) {
vm_args.version = 0x00010004;
//JNI_GetDefaultJavaVMInitArgs(&vm_args);
res=(*Func1)(&vm_args); // ERROR SHOWING IN THIS LINE
.
.
.
res=(*Func2)(&jvm,(void *)&env,&vm_args);
.
.
.
}
}
}
-
March 7th, 2007, 07:04 AM
#2
Re: dynamic loading of dll
Your function pointer pfunct1 takes a void as the parameter. Is the function in the dll (JNI_GetDefaultJavaVMInitArgs) of the same type? This means the number of parameters have to be correct and the parameters should be of the same type. Als the return type of the dll function and the function pointer should be the same.
Time is fun when you're having flies 
-
March 7th, 2007, 07:24 AM
#3
Re: dynamic loading of dll
Hey thanks for a prompt reply
I double checked it, its all same but still the error persists!!
-
March 7th, 2007, 08:09 AM
#4
Re: dynamic loading of dll
You are passing some argument to the function pointer while you declare it as being void (having no parameters).
res=(*Func1)(&vm_args); // ERROR SHOWING IN THIS LINE
Time is fun when you're having flies 
-
March 7th, 2007, 08:11 AM
#5
Re: dynamic loading of dll
No discard my previous post, i see you declare it as void*. Try casting the argument to void* ?
Time is fun when you're having flies 
-
March 7th, 2007, 10:31 AM
#6
Re: dynamic loading of dll
Off the top of my head you should just call
Func1(&vm_args);
Last edited by fransn; March 7th, 2007 at 11:04 AM.
-
March 8th, 2007, 03:22 AM
#7
Re: dynamic loading of dll
since there are no more replies I take it that solved it. Usual.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|