CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Guest

    DLLs and Status Bar

    I have a DLL created in C that I am using with a VB app, however I want to implement a status bar. I was wondering if there was a
    way to return percentage values from the DLL to my visual basic progress bar while the DLL is performing its task or if I can
    manipulate the visual basic status bar directly from the DLL. Any help would be greatly appreciated.


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: DLLs and Status Bar

    since you DLL seems to be an "old-style" :-) C-DLL, not an ActiveX DLL you won't be able to raise an event to VB.
    You could have the VB program pass the window handle of the statusbar to your C DLL and manipulate the status bar directly.
    I don't think, that's a good approach, though.
    I'd rather write a COM DLL and raise events at regular intervals.
    You could even have the vb program pass the address of a callback function (via Addressof) and call that function from your C DLL.


  3. #3
    Guest

    Re: DLLs and Status Bar

    Sorry if this is a repeat post, but I replied a little while ago and I haven't seen it come up yet.
    Once again, thanx for your help (now and in the past). If I decide to go the callback route and have the VB function
    for the status bar declaration such as:
    status_bar(picture_box as control, percent as integer, visible as boolean)
    and pass the pointer to this function to the c dll how do I access it? Specifically how do I change the percent value? Do I need
    to do some type definitions in the DLL or something like that? Sorry if I sound like a newbie, I sort of am...


  4. #4
    Guest

    Sorry, it's me again one last thing....

    Can you recommend any books or online documentation about creating DLLs, Active X DLLs, etc?


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: Sorry, it's me again one last thing....

    the only documentation that I really recommend is: MSDN!


  6. #6
    Join Date
    May 1999
    Posts
    3,332

    Re: DLLs and Status Bar

    This is not how I'd do it.
    I'd write a very simple callback. I'd never pass anything "As Control" to a C DLL and I wouldn't let the DLL manipulate the status bar directly.

    I'd try this:
    Public sub callMe( byval lPercent as long )

    Whenever that routine gets called, I'd update the statusbar within the VB program.
    How would you declare that in C?
    typedef void (*LPCALLBACK)(LONG lPercent);
    void MyCFunction( LPCALLBACK lp )
    {// call the callback
    lp( 5 );
    }
    and so on.
    I haven't implemented such a thing yet. So, this is more or less guesswork. That's just what I'd try.


  7. #7
    Join Date
    Sep 1999
    Location
    CA
    Posts
    83

    Re: DLLs and Status Bar

    I was not able to implement your suggestion, I tried a simple callback procedure where I was just trying to pass a number back and forth between the dll and the vb executable but the variable would not pass correctly. I tried looking for your email address in your user profile, but it is not specified, is there any way if you have free time that I can send you a zip of the simple vb form and simple c dll so that you can tell me what I am doing wrong of if it's just not possible. Thanks, you can reach me directly via e-mail at [email protected]


  8. #8
    Join Date
    Oct 1999
    Location
    UK
    Posts
    44

    Re: DLLs and Status Bar

    I am also struggling with access violations while trying to do this sort of thing and would be interested to see a working solution. Going to private email conversations prevents others benefitting from the help being given. Please keep it public! :-)

    Mark
    Regards

    Mark Rivers-Moore

  9. #9
    Join Date
    Sep 1999
    Location
    CA
    Posts
    83

    Re: DLLs and Status Bar

    I was finally able to get this working, please let me know what type of errors you are getting and if I am able to shed some light on the situation then I will.


  10. #10
    Join Date
    Oct 1999
    Location
    UK
    Posts
    44

    Re: DLLs and Status Bar

    Likewise, I solved the problem myself. I was suffering Unhandled Exceptions.

    I had forgotten to make the protoype for the callback use CALLBACK (i.e. __stdcall). I worked it out by studying the stack in Visual C++ 5.0 before and after the call to VB.

    Here are extracts of my working code for reference by other people.


    /* My DLL.h */
    enum Callbacks
    {
    CALLBACK_NEWALARMS,
    CALLBACK_NEWSTATUS,
    MAX_CALLBACKS /* Do not use, for internal use only! */
    };

    extern void (CALLBACK *CallbackPointers[ MAX_CALLBACKS ])( void );

    /* My DLL.c code */
    #include <windows.h>
    #include <DLL.h>

    /* In this code example, the callback functions are just setting a flag to
    notify VB of an event in my DLL code. VB then calls a DLL function to
    acquire the data. This method is used as the DLL is running a time
    critical thread and time consuming VB code is unwelcome.
    */

    void (CALLBACK *CallbackPointers[ MAX_CALLBACKS ])( void );

    void
    WINAPI /* Defines __stdcall calling convention */
    SetCallback(
    const int Index, /* Index to which function to set */
    const void* pFunc /* Address of VB function */
    )
    {
    CallbackPointers[ Index ] = pFunc;
    }


    /* Within my DLL code, this is the callback to VB */
    if ( CallbackPointers[ Index ] != NULL )
    {
    (*CallbackPointers[ Index ])();
    }




    'VB CODE

    'Call DLL to set callback address, done prior to first callback
    VC_SetCallback(CALLBACK_NEWALARMS, AddressOf VB_NewAlarms)

    'This is one of the VB callback functions
    public Sub VB_NewAlarms()
    bAlarmsChanged = true ' Trigger to update the alarm list
    End Sub





    Mark
    Regards

    Mark Rivers-Moore

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured