CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2007
    Posts
    2

    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);
    .
    .
    .

    }
    }
    }

  2. #2
    Join Date
    Mar 2003
    Location
    The Netherlands
    Posts
    586

    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

  3. #3
    Join Date
    Mar 2007
    Posts
    2

    Unhappy Re: dynamic loading of dll

    Hey thanks for a prompt reply

    I double checked it, its all same but still the error persists!!

  4. #4
    Join Date
    Mar 2003
    Location
    The Netherlands
    Posts
    586

    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

  5. #5
    Join Date
    Mar 2003
    Location
    The Netherlands
    Posts
    586

    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

  6. #6
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    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.

  7. #7
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    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
  •  





Click Here to Expand Forum to Full Width

Featured