Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how to receive message from dll (by postmessage) ??

duahanzhiduahanzhi Member Posts: 6
hi,
i used borland c++ 5.0 and created a win32 application.
i need to call a function from a dll and it return some value
to my program.
the problem is, my program doesn't have a window.(it run invisible and it does not created any windows/gui)

how do i receive the message from the dll ?

my DLL used postmessage() to post the message.

Any one pls help or give me a sample about how to get a message from dll.


thanks

Comments

  • pingpongpingpong Member Posts: 937
    You can write a message loop inside your EXE even thought it doesnt not have a window, as long as you have a thread (everything does), you can pull its messages:
    [code]
    void CheckMessageLoop()
    {
    MSG msg;
    if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0)
    {
    if(msg != WM_QUIT)
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);

    switch(msg)
    {
    case WM_SOMETHING: break;
    case WM_OTHERTHING: break;
    }
    }
    }
    }
    [/code]
    Depending on the message you are sending, you probably dont need the check for WM_QUIT and the Translate/DispatchMessage pair, but putting them there does not hurt anyway.

    So now, your EXE needs to call CheckMessageLoop repeatedly, your switch/case takes care of the action. But how to send the message from the DLL to this loop?

    First off, you need to pass your EXE thread ID to the dll in some way, easiest is to have the EXE call GetCurrentThreadId and passing on the return value to the DLL, the DLL should store this value somewhere.

    When its time for the DLL to send a message to the EXE, simply do:
    PostThreadMessage(myExeThreadId, WM_SOMETHING, wParam, lParam);

    HTH

    : hi,
    : i used borland c++ 5.0 and created a win32 application.
    : i need to call a function from a dll and it return some value
    : to my program.
    : the problem is, my program doesn't have a window.(it run invisible and it does not created any windows/gui)
    :
    : how do i receive the message from the dll ?
    :
    : my DLL used postmessage() to post the message.
    :
    : Any one pls help or give me a sample about how to get a message from dll.
    :
    :
    : thanks
    :
    :

  • Shawn CarterShawn Carter Member Posts: 0

    __ [ http://forcoder.org ] free ebooks and video tutorials about || Swift Perl C C++ Visual Basic C# PL/SQL MATLAB JavaScript Java Python Scratch Go Delphi Ruby Visual Basic .NET R Objective-C PHP Assembly FoxPro D Alice Hack LabVIEW ABAP SAS F# Crystal Rust Fortran Transact-SQL Ada Scheme Julia ML Clojure Logo Dart Awk VBScript Kotlin Lua Scala Prolog COBOL Erlang Apex Bash Lisp || __________

Sign In or Register to comment.