Displaying dynamic text on VB form that originates in C DLL

I am migrating a C program to a DLL.  The C code uploads hardware and was originally a DOS application.  The original program used printf statements for user input and progress of the hardware upload.  I want to use VB as my front end to call the DLL.  Is there anyway to display what was in the printf statements on the VB form.  I read that VB does not allow for call back functions from a C DLL.  The text would have to be dynamic just as it is when one would installs a new software package.  I would break the program up and call all the functions from VB but would lose my device and file handles in the C DLL so this does not seem like an option.
johnslaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ventondCommented:
You could write a timer loop so that every so often your VB program could query the DLL as to what the value is. I do believe that with VB6 native complie you can do a callback now.
0
johnslaAuthor Commented:
I do not believe the timer idea will work for this particular application.  I will look into the call back.
0
rondeaujCommented:
can't call back functions be used with the Addressof Statement?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

johnslaAuthor Commented:
Yes they can as I am reading up on them now
0
AnswerTheManCommented:
you can do another 2 things :
1. make the DLL SendMessage in a way
   that will raise an event on the VB
   FORM. you can use any of the FORM
   existing EVENTS which is not in use
   in this APP, and use the PARAMS sent
   in this event.
2. if your app is not in a hurry -
   Update a certain Registry Key with
   the data from the DLL.
   the VB app will be reading that
   KEY from time to time.
   (timer again).
0
m26Commented:
How about putting a textbox on your vb form and passing its window handle to your DLL? Then the DLL can DrawText using that Hwnd (instead of the printf's) and thus write directly onto your VB control from the DLL.
0
johnslaAuthor Commented:
M26,
Sounds great, got an example?
0
johnslaAuthor Commented:
m26,
How would you tell the DLL exactly where to draw?  How does the window handle imply the textbox?  How would you tell the DrawText what the RECT structure is and where would you get the textbox's logical coordinates?
0
m26Commented:
Q. How does the window handle imply the textbox?
A. A textbox is a window of class "EDIT". Each instance of a window has a unique handle (the HWND) and this identifies the particular window to the DLL.

I've changed my mind regarding DrawText etc. Much simpler for the DLL to send your textbox a message to write the text in.

Eg:

SendMessage( hwndYourEditCtrl, WM_SETTEXT, 0, (LPARAM)"Here is the text to display")
0
johnslaAuthor Commented:
m26,
I still am not clear on the textbox handle.  For the sake of argument lets say the DLL is called on a Click menu item event so my call to the DLL on this event would look something like this:

Private Declare Function NdsInfo Lib "nds.dll" (ByVal hwnd As Long) As Long

Private Sub mnuNds_Click()
    Dim NdsRtn As Long
   
    NdsRtn = NdsInfo(hwnd)
    Print NdsRtn
End Sub

This at least to me is unclear as to how any control is referenced other than a handle to the VB form window.  Sorry Im not getting it.
0
m26Commented:
Your call would be:

NdsRtn = NdsInfo( YourTextBox.Hwnd )

Look at the properties of a VB textbox and you'll see it has a Hwnd property which is a read-only Long. THis is the value you pass to the DLL, and inside the DLL it can write text to teh textbox using the WM_SETTEXT message as I described previously
0
johnslaAuthor Commented:
M26
Thanks for your help.  This works but only once.  The first call to SendMessage is displayed but further calls to SendMessage are not displayed.  I will investigate further.  I don't seem to have the option of accepting your answer but you get the points.
0
johnslaAuthor Commented:
M26
I've been playing in the VC++ debugger and all my SendMessage calls are being executed yet do not update the textbox on the VB.  The first call to SendMessage as I said works but further calls do nothing.  On interesting tidbit is that the one time it will work it is from the VB developement environment.  When the app. is compiled to .EXE no text is ever shown.  Any ideas?
0
m26Commented:
Maybe if I click "Answer" you will have the option of giving me the points?

Regards your last comment, without seeing the code I couldn't really give you an answer, but it's worth making sure that the hWnd you use in your SendMessage is a valid hWnd and that there is nothing in the VB code which is updating your textbox after your DLL has written to it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
johnslaAuthor Commented:
m26,
After playing with this a bit I still cannot get this approach to behave like a printf statement.  If you try a simple example where you create a C DLL that accepts the textbox's hWnd and uses the SendMessage method you suggested to post script you will only see the last SendMessage text in you code.  eg.

int _stdcall SendMsgExmpl(HWND hWnd)
{

  SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)"Hello");
  Sleep(2000);
  SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)"there");
  Sleep(2000);
  SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)"m26");
  Sleep(2000);
return(0)
}

when you call this from your VB event the textbox you defined and passed it's handle to the DLL will only show "m26".  If you step through the code using the VC++ debugger all the SendMessage's are executed yet only the will show to the textbox.  So I suppose this method works but only for one textbox update which does not satisfy the my requirement.  I assume SendMessage is not a buffered I/O like printf and documentation claims the command is exected upon call (vs. PostMessage) a concept like flush() is not applicable.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.