Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:09:05+00:00 2026-06-08T21:09:05+00:00

I am using kernel32.dll to import a 3rd party DLL’s functions via the method

  • 0

I am using kernel32.dll to import a 3rd party DLL’s functions via the method below.

private delegate bool MyDelegate(float[] floatArray, UInt16[] intArray);

private static MyDelegate MyDelegateCaller = null;

public static bool MyMethod(ref float[] floatArray, out UInt16[] intArray)
{
    if(MyDelegateCaller == null)
    {
        IntPtr address = GetProcAddress(_dllHandle, "ExternalMethod");

        MyDelegateCaller = 
            (MyDelegate)Marshal.GetDelegateForFunctionPointer(
                address, 
                typeof(MyDelegate)
            );
    }

    return MyDelegateCaller(floatArray, intArray); //*
}

If I debug and step over MyDelegateCaller (at //*) then the arrays get populated as expected. However, if I just run the code, the arrays do not get populated.

Any ideas as to what is going on?

Some more info:
I am using this method rather than PInvoke for calling the DLL as I need to be able to unload and reload DLLs at run-time.
I have tried adding delays, running in different threads as test to try to simulate the effect of stepping over.
There isn’t any cross thread calling of these methods, unless the DLL is creating its own thread(s), however, I do not have access to the DLL’s code to verify.


Update

So I’ve tried the following (inspired from here)

            ...
            );
    }

    IAsyncResult result = MyDelegateCaller.BeginInvoke(floatArray, intArray, null, null);

    while (!result.IsCompleted)
        result.AsyncWaitHandle.WaitOne(1000, false); //**

    result.AsyncWaitHandle.Close();

    return MyDelegateCaller.EndInvoke(result);    
}

However, when I get to //** the program throws a System.ExecutionEngineException.


Hack

Got my code working.

I removed the working from the previous update and put MyMethod in a BackgroundWorker‘s DoWork event. Looped over BackgroundWorker.IsBusy.

Not elegant, but will do for the moment.

Any better solutions are more than welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:09:08+00:00Added an answer on June 8, 2026 at 9:09 pm

    I have tried adding delays, running in different threads.

    Adding arbitrary delays is not the right way to synchronize between threads. You need to wait for the other task to complete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im using the following method [DllImport(kernel32.dll, SetLastError=true)] static extern int GetProcessId(IntPtr hWnd); to try
I am trying to call OpenEvent of kernel32.dll using JNA and it fails with
I am using a third party dll built with VS2008 that relies on msvcr90.dll
I am using JNA to call methods of user32.dll and kernel32.dll. It is working
Is there a managed API for kernel32.searchpath? i.e not using a pinvoke. http://www.pinvoke.net/default.aspx/kernel32.searchpath
Using import datetime in python, is it possible to take a formatted time/date string
I'm trying to hook a 3rd party app so that I can draw to
I start to learn asm using fasm, unfortunately after compile code below I get
hello i'm using vb 2008 here is part of my code: Private Declare Function
Using only VBScript (launched from Windows Scripting Host) can I pull the DLL metadata

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.