Click to See Complete Forum and Search --> : DLLs and Status Bar
September 13th, 1999, 03:33 PM
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.
Lothar Haensler
September 14th, 1999, 01:25 AM
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.
September 14th, 1999, 02:43 PM
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...
September 14th, 1999, 10:50 PM
Can you recommend any books or online documentation about creating DLLs, Active X DLLs, etc?
Lothar Haensler
September 15th, 1999, 01:37 AM
the only documentation that I really recommend is: MSDN!
Lothar Haensler
September 15th, 1999, 01:45 AM
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.
bcyde
October 1st, 1999, 03:40 PM
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 quad_seven@hotmail.com
MarkRM
November 12th, 1999, 04:42 AM
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
bcyde
November 13th, 1999, 04:54 PM
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.
MarkRM
November 15th, 1999, 05:39 AM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.