views:

81

answers:

1

I have a DLL with a TClientSocket component, it is used to talk to a Telephone System Machine. The DLL only have PChar parameters in the exports methods, and is not using packages.

When I load the DLL with Delphi app, all the events works fine, no problem so far.

My customer is calling this DLL from a console Win32 Cobol program, and the TClientSocket do not trigger the events when its happen, it uses a main loop to call a check method in DLL to known if is there any returning from the Telephone system, if it returns OK then it call the Get Method, and here is where the problem happen:

In TClientSocket.OnRead event, I call TClientSocket.Socket.ReceiveText, and there are several returns from server app, what make me think that the event is only triggered when I call a method from DLL, and the TClientSocket is holding several returns in the buffer.

The problem is that I cant find any Delimiter to split this Return.

How can I fix this? Is there anything I can add to my DLL to make sure that the OnRead event will be triggered every time when it is not called from a Delphi Program?

+1  A: 

you probably need a message loop in your dll .. (Console applications lack a message pump ..). SO implement something like this in your dll constructor:

var Msg : TMsg;
     res : Integer;

.
. .

While true Do Begin
        res := Integer( GetMessage(Msg, 0, 0, 0 ));
        If res = -1 Then
          Exit  // error
        else if res = 0 then
          exit  // WM_QUIT received
        else begin
          TranslateMessage( Msg );
          DispatchMessage( Msg );
        end;
End; { While }

Take a look at a similar thread http://www.mofeel.net/1102-comp-lang-pascal-delphi-misc/2763.aspx

GX
I did that in the DLL main procedure and the first interaction the DLL stop in GetMessage, and dont move forward.
Cesar Romero
Now I know GetMessage wait until it get a message, so I change to PeekMessage, but it returns -1, so it goes out. if I remove the test then it never load the application.
Cesar Romero
Cesar, maybe the culprit is the COBOL app see another similar thread (it is .net but seems to be dealing with the same issue)http://www.devnewsgroups.net/windowsforms/t10952-messageloop-thread.aspx
GX
GX, I think the solution will be move the TClientSocket to a thread inside DLL and then add the loop to the execute method.Now Im working in a parser to make the current version works, and Ill start a new version using threads. Ill post the result here when it is done. Thank you for your help so far.
Cesar Romero