🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2796

Re: form inside a dll loaded by a console application

#2796
From: Remy Lebeau (TeamB)
Date: Wed, 27 Dec 2006 00:49
63 lines
2948 bytes
"Stefano Bonifazi" <stefboombastic@email.it> wrote in message
news:45919f15@newsgroups.borland.com...

> You mean that I have to create an hidden window with its WndProc
> callback function inside the console application calling the dll?

No.  A TForm already has a suitable window for processing messages.  You do
not need a separate hidden window at all.

The real problem is that console applications do no have any message queue
for receiving and dispatching the messages in the first place, so there is
nothing for the TForm to process.  That is what you have to implement
manually in your console code.  The simpliest message queue is one that
calls Peek/GetMessage(), TranslateMessage(), and DispatchMessage()
repeatedly for the lifetime of the process, or at least while the TForm is
active.  For example:

    #include <windows.h>

    BOOL CALLBACK HandlerRoutine(DWORD dwCtrlType)
    {
        PostQuitMessage(0);
        return TRUE;
    }

    int main(int argc, char** argv)
    {
        SetConsoleCtrlHandler(&HandlerRoutine, TRUE);

        // load DLL...
        // show TForm...

        MSG msg;
        while( GetMessage(&msg, NULL, 0, 0) > 0 )
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            switch( msg.message )
            {
                case WM_SYSCOMMAND:
                    if( (msg.wParam & 0xFFF0) != SC_CLOSE )
                        break;
                    // fall though to the next block...

                case WM_CLOSE:
                    if( PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT,
PM_NOREMOVE) == 0 )
                        PostQuitMessage(0);
                    break;
            }
        }

        // close TForm...
        // unload DLL...

        SetConsoleCtrlHandler(&HandlerRoutine, FALSE);
        return 0;
    }


Gambit
Technical Details
Message-ID: <4591c308$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!news.glorb.com!tudelft.nl!txtfeed1.tudelft.nl!feeder.news-service.com!newsfeed.freenet.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail
References: <458e4f48@newsgroups.borland.com> <45903d10$1@newsgroups.borland.com> <45919f15@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,3fa2091e9808a898
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <458e4f48@newsgroups.borland.com> <45903d10$1@newsgroups.borland.com> <45919f15@newsgroups.borland.com>
Subject: Re: form inside a dll loaded by a console application
Date: Tue, 26 Dec 2006 16:49:16 -0800
Lines: 65
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.34.171
Message-ID: <4591c308$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1167180552 75.83.34.171 (26 Dec 2006 16:49:12 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!news.glorb.com!tudelft.nl!txtfeed1.tudelft.nl!feeder.news-service.com!newsfeed.freenet.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail