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

  • Home
  • SEARCH
  • 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 4321168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:42:50+00:00 2026-05-21T08:42:50+00:00

I give up, I have to write and ask; I’m using an unmanaged DLL

  • 0

I give up, I have to write and ask; I’m using an unmanaged DLL written in Delphi, which asynchronously invokes a (parameterless) callback passed to it whenever an event occurs in the hardware it is developed to monitor.

What I do in C# is I keep a static reference to a created delegate, which is then passed as parameter to the start method on the Delphi side. This tells the DLL to notify me using the callback, whenever there is new data to fetch, using a GetData method.

All works fine, real fine, until I try to do the exact same thing in a console app, or in a windows service. Or if I create and call the DLL related methods on a separate thread without letting that thread spin doing Application.DoEvents(). Usually people with similar problems seem to have had problems with the GC or calling conventions, but having (attempted to) secured against GC issues by keeping the delegate ref I stand without further clues on how to solve this.

I’m assuming I’m missing something paramount in how the CLR invokes my callbacks after the DLL calls the thunk provided to connect to my callback handler.

The declarations of my DLL imports look like this:

    [DllImport("TheDelphiApi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
    private static extern UInt32 Start(MulticastDelegate callback);

    [DllImport("TheDelphiApi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
    private static extern void GetData(byte[] recdata);

    public delegate void EngineCallbackHandler();                     

    private static EngineCallbackHandler engineCallback;

And the call setting up the callback:

        UInt32 result = Start(engineCallback);

Got clues? What’s with the need for DoEvents? Any feedback is really appreciated, been trying research this for a few days now, without any indications on progress.
/J

  • 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-05-21T08:42:50+00:00Added an answer on May 21, 2026 at 8:42 am

    It’s hard to tell without seeing the native code, but I would assume that the code on the native side depends on a message loop being processed on the thread that calls Start? e.g. because it’s using a TTimer or similar?

    Once the call to Start has returned, there is only 2 ways how any code can get executed inside that DLL. Either a new thread was started, or a timer or some other mechanism has been registered which depends on window messages.

    EDIT:

    Another possibility:

    If the native DLL is using cross-process COM in an STA (single threaded apartment) then COM depends on a working message loop.

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

Sidebar

Related Questions

I have to write a Java program that tells what coins to give out
Give that I have written a JPanel with many different components on it, is
I have a listbox in which i have to give minimum 2 files for
I have web-service which give list of property at a particular area My problem
I have an IP camera which can give me media-data by RTSP. I develop
I have a code in search.java which uses getParameter and xmltransform. I am using
I have to give one option in my website to upload multiple files and
What would a developer used to working in Visual Studio have to give up
I have a service that give me a date time string in the following
I have two spreadsheets that each give information about a bunch of applications running

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.