VB callback function 
Author Message
 VB callback function

Hi,

we are developing a VB applications that calls a DLL (written in C) that
does
some calculations. The DLL should print its output using a VB Routine.
Thus,
we would like to call the DLL with the address of a VB Routine as a
paramter.
The DLL then uses this routine to print values (for example to a message
box).
We succeded to give the pointer to the VB function to the DLL and to
call
this VB function from the dll. However, we did not manage to print out
the
C-style string. The C-Prototyp of the VB-function is:

void WINAPI myprint(char *s);

But how can we code this in VB? VB only knows its own strings, but no
pointers.
Anyone knows a solution?

Thanks in advance,

 Juergen



Tue, 08 Jan 2002 03:00:00 GMT  
 VB callback function
When a C function calls a VB function and passes a string pointer, VB does
not know to convert this to a BSTR. The simplest solution would be to have
the VB function expect a pointer to the first element in a byte array. You
could then convert this byte array to a VB string.



Quote:
> Hi,

> we are developing a VB applications that calls a DLL (written in C) that
> does
> some calculations. The DLL should print its output using a VB Routine.
> Thus,
> we would like to call the DLL with the address of a VB Routine as a
> paramter.
> The DLL then uses this routine to print values (for example to a message
> box).
> We succeded to give the pointer to the VB function to the DLL and to
> call
> this VB function from the dll. However, we did not manage to print out
> the
> C-style string. The C-Prototyp of the VB-function is:

> void WINAPI myprint(char *s);

> But how can we code this in VB? VB only knows its own strings, but no
> pointers.
> Anyone knows a solution?

> Thanks in advance,

>  Juergen



Tue, 08 Jan 2002 03:00:00 GMT  
 VB callback function
For that prototype I think the following VB sub would work:

Sub myprint(ByVal  s)

This should work because VB strings are really pointers to the string, so
by passing the pointer ByVal, VB gets a copy of the pointer to a string,
which is exactly what it expects.

Hope this helps,
Jason Bouzane


Quote:
> Hi,

> we are developing a VB applications that calls a DLL (written in C) that
> does
> some calculations. The DLL should print its output using a VB Routine.
> Thus,
> we would like to call the DLL with the address of a VB Routine as a
> paramter.
> The DLL then uses this routine to print values (for example to a message
> box).
> We succeded to give the pointer to the VB function to the DLL and to
> call
> this VB function from the dll. However, we did not manage to print out
> the
> C-style string. The C-Prototyp of the VB-function is:

> void WINAPI myprint(char *s);

> But how can we code this in VB? VB only knows its own strings, but no
> pointers.
> Anyone knows a solution?

> Thanks in advance,

>  Juergen



Wed, 09 Jan 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HOWTO Call a VB Callback function from VB ActiveX control

2. problems with C/C++ DLL passing arguments to VB Callback Function

3. Return values from VB CallBack Function to VC Dll

4. HOWTO Call VB Callback function from ActiveX control

5. HOWTO: Call a VB callback function from a VC++ DLL

6. HOWTO Call VB Callback function from ActiveX control

7. creating a callback function in c++ dll to callback a VB function in an exe

8. async callback function in VB.Net

9. VB and UNRAR.dll callback function URGENT please

10. passing callback function to VB active x control

11. Any Tricks Available to Use C Function for Callbacks in VB

12. Callback functions in VB?

 

 
Powered by phpBB® Forum Software