Addressof cannot be converted to integer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've read several articles regarding the above error, but still can't get it
to work. I upgraded an app that was running in VB6 that has a lot of errors
when upgrading to VB.NET. Here's what I have associated with the error.

'UPGRADE_WARNING: Add a delegate for AddressOf EnumAcctListEntriesCB Click
for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1048"'

iRC = EntEnumN(ghSelect, HYP_ID_ACCTLISTENTRY, sigAcctList, AddressOf
EnumAcctListEntriesCB, lParam, 0)

Public Function EnumAcctListEntriesCB(ByVal hSelect As Integer, ByVal
sigRecd As Integer, ByVal sigKey As Integer, ByVal lParam As Integer, ByRef
apis As APISTRUCT) As Integer ' This worked fine in VB6

I added the line below in addition to what's above. Should there be
something else that need changing or added? There's no "Declare" associated
with this section.


Delegate Function EnumAcctListEntriesCBDelegate(ByVal hSelect As Integer,
ByVal sigRecd As Integer, ByVal sigKey As Integer, ByVal lParam As Integer,
ByRef apis As APISTRUCT) As Integer
 
This is correct, the parameter that you supplied before was a function
pointer - using address-of to pass in the pointer (although it's declared as
an integer). You can achieve the same thing using a delegate.

Change your declaration to something like the below and pass in a
new EnumAcctListEntriesCBDelegate( YourFunctionName ) as the parameter.

Public Function EnumAcctListEntriesCB(ByVal hSelect As Integer,
sigRecd As EnumAcctListEntriesCBDelegate, ByVal sigKey As Integer, ByVal
lParam As Integer, ByRef
apis As APISTRUCT) As Integer ' This worked fine in VB6
 
Joe, I pasted your suggestion and received same error cannot be converted to
integer because integer is not a delegate type. I even got an additional
error on the "sigrecd". Same as above.
 
Correction, it does get rid of the error above when I add the code and take
out the "Delegate Function EnumAcctListEntriesCBDelegate" below.

However, this leaves another error of "Type EnumAcctListEntriesCBDelegate"
is not define.
 
You need to include the definiton of this type:

Delegate Function EnumAcctListEntriesCBDelegate(ByVal hSelect As Integer,
ByVal sigRecd As Integer, ByVal sigKey As Integer, ByVal lParam As Integer,
ByRef apis As APISTRUCT) As Integer
 
When insert the definition below I get 5 add'l errors, which is the origianal
cannot convert Addressof into integer. I have several callbacks (addressof)
that are producing errors. I figure if I can get through this one the others
will be the same. Right the changes below are in conflict. Either definition
or cannot convert to Integer. This is what I have currently:

Delegate Function EnumAcctListEntriesCBDelegate(ByVal hSelect As Integer,
ByVal sigRecd As Integer, ByVal sigKey As Integer, ByVal lParam As Integer,
ByRef apis As APISTRUCT) As Integer

Public Function EnumAcctListEntriesCB(ByVal hSelect As Integer, ByVal
sigRecd As EnumAcctListEntriesCBDelegate, ByVal sigKey As Integer, ByVal
lParam As Integer, ByRef apis As APISTRUCT) As Integer

iRC = EntEnumN(ghSelect, HYP_ID_ACCTLISTENTRY, sigAcctList, AddressOf
EnumAcctListEntriesCB, lParam, 0) 'this invokes the callback function above
 
I think you may have forgetten to replace your definition of the function
with one that uses the delegate:

Public Function EnumAcctListEntriesCB(ByVal hSelect As Integer,
sigRecd As EnumAcctListEntriesCBDelegate, ByVal sigKey As Integer, ByVal
lParam As Integer, ByRef
apis As APISTRUCT) As Integer

Joe
 
Sorry for the delay. Joe, you gave me the answer earlier but I couldn't put
it together. The "EntEnum" has a declaration that needs to be modified with
the "Delegate" such as:

Declare Function EntEnumN Lib "hacces32.dll" Alias "_EntEnum@24" (ByVal
hSelect As Integer, ByVal wTabId As Integer, ByVal sigKey As Integer, ByVal
lpCallback As EnumAcctListEntriesCBDelegate, ByVal lParam As Integer, ByRef
lpApiStruct As Integer) As Integer

This works. The only issue in the end is that I multiple callbacks that are
using the same "EntEnum" declare. I get the error message "Overload
resoluton....not most specific" if I try creating the "EntEnum" for the
different callbacks.
 
Back
Top