Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Help needed regarding callback function


Message #1 by "azian mohamad" <amohamad_my@h...> on Tue, 29 Jan 2002 07:23:04
The problem is in your VB declaration. fnc is a void*, that in C++ is a 
long integer, not a Variant. Change the declaration to "byval fnc as Long"

Good luck,
m.


> Hi,
> I have problem when VB app tried to call an API function build in MFC
> Below are some of the codes:
> 
> in BAS file =>
> Declare Function A Lib "Sekure" Alias "_A @8" _
>     (ByVal comport As Integer, fnc As Variant) As Integer
> 
> in C files =>
> the prototype is => int A (int comport, void *fnc)
> //global declaration
> typedef void (*STATUS) (short);
> STATUS Sts = NULL;
> // in one of the .CPP files
> SEKURE_API int __stdcall int A (int comport, void *fnc)
> {
> 	Sts = (STATUS)fnc;
> 	int nRet = GetInfo(comport);
> 		
> 	if (nRet)	{
> 		if(Sts)	
> 			Sts (nRet);
> 		}
> 	return OK;
> ......
> ....
> }
> 
> 
> In my VB application I have these =>
> 
> Public Sub Verify()
>    Msgbox "Hi"
> ...
> End sub
> 
> Private Sub form_load
>     res = A (1, AddressOf Verify)
> end sub
> 
> 
> And the error I get =>
> memory can't be written....
> 
> I tried to trap the error in the DLL, the error starts when try to do 
this 
> stmt:-
> Sts (nRet);
> 
> Is it something to do with datatype (void) and how to overcome this..

  Return to Index